Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

set empty default values for the field, without overwriting existing field values #24

Open
ahebrank opened this issue Oct 16, 2016 · 4 comments

Comments

@ahebrank
Copy link
Owner

The problem and a potential solution is suggested by PR #19 but in practice this seems to overwrite any existing value for the field. Need a way to set null values for a field, but only if the field is actually empty.

@JonatanJJ
Copy link

Maybe doing an array_merge would work better?
$field['value'] = array_merge($this->defaults['value'], $field['value']);

This will make sure that only values missing from $field['value'] will be overwritten.

@ahebrank
Copy link
Owner Author

@Jontis00, can you describe steps to replicate the original issue? I've never actually seen the PHP warnings.

@JonatanJJ
Copy link

Depending on your PHP warning setting the error may or may not show.
On one of my sites I can replicate the issue by editing a page with an empty Link picker field.

The reason for the issue is that $field['value'] defaults to null. But in the render_field function we keep referencing $field['value']['url'] for example which means we are trying the access an index of a null value. Which may cause a warning on some configurations.

@defaria
Copy link

defaria commented Aug 25, 2017

So.. how do you go about setting the field's default_value? I tried passing an array, but it didn't work.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants