function _conditional_fields_element_add_property in Conditional Fields 7.3
Helper function to add a property/value pair to a render array safely without overriding any pre-existing value.
Parameters
$position: 'append' if $value should be inserted at the end of the $element[$property] array, any other value to insert it at the beginning.
2 calls to _conditional_fields_element_add_property()
- conditional_fields_attach_dependency in ./
conditional_fields.module - Attaches a single dependency to a form.
- conditional_fields_form_after_build in ./
conditional_fields.module - after_build callback for forms with dependencies.
File
- ./
conditional_fields.module, line 814 - Define dependencies between fields based on their states and values.
Code
function _conditional_fields_element_add_property(&$element, $property, $value, $position = 'prepend') {
// Avoid overriding default element properties that might not yet be set.
if (!isset($element[$property])) {
$element[$property] = isset($element['#type']) ? element_info_property($element['#type'], $property, array()) : array();
}
if (in_array($value, $element[$property])) {
return;
}
switch ($position) {
case 'append':
$element[$property] = array_merge($element[$property], (array) $value);
break;
case 'prepend':
default:
$element[$property] = array_merge((array) $value, $element[$property]);
break;
}
}