protected function ConditionalFieldsFormHelper::processDependeeFields in Conditional Fields 8
Same name and namespace in other branches
- 4.x src/ConditionalFieldsFormHelper.php \Drupal\conditional_fields\ConditionalFieldsFormHelper::processDependeeFields()
Determine and register dependee field effects.
1 call to ConditionalFieldsFormHelper::processDependeeFields()
- ConditionalFieldsFormHelper::processDependentFields in src/
ConditionalFieldsFormHelper.php - Build and attach #states properties to dependent fields.
File
- src/
ConditionalFieldsFormHelper.php, line 96
Class
- ConditionalFieldsFormHelper
- Helper to interact with forms.
Namespace
Drupal\conditional_fieldsCode
protected function processDependeeFields($dependees) {
// Cycle the dependant's dependees.
foreach ($dependees as $dependency) {
$dependee = $dependency['dependee'];
if (empty($this->form['#conditional_fields'][$dependee])) {
continue;
}
$dependee_info = $this->form['#conditional_fields'][$dependee];
end($dependee_info['parents']);
$unset = key($dependee_info['parents']);
if (is_int($dependee_info['parents'][$unset]) && $dependee_info['parents'][$unset] > 0) {
unset($dependee_info['parents'][$unset]);
}
$dependee_form_field = NestedArray::getValue($this->form, $dependee_info['parents']);
$options = $dependency['options'];
if (!empty($options['values']) && is_string($options['values'])) {
$options['values'] = explode("\r\n", $options['values']);
}
$options['selector'] = self::getSelector($options['selector'], $dependee_form_field);
$state = $this
->getState($dependee, $dependee_form_field, $options);
// Add validation callback to element if the dependency can be evaluated.
if (in_array($options['condition'], [
'value',
'empty',
'!empty',
'checked',
'!checked',
])) {
self::elementAddProperty($this->dependent_form_field, '#element_validate', [
self::class,
'dependentValidate',
], 'append');
}
$this
->addStateToGroup($state, $options);
$selector = conditional_fields_field_selector(NestedArray::getValue($this->form, [
$this->dependent_location[0],
]));
$this->effects[$selector] = self::getEffect($options);
}
}