function linked_field_element_validate in Linked Field 8
Element validate function for Linked Field.
Parameters
array $element: The structured array whose children shall be rendered.
\Drupal\Core\Form\FormStateInterface $form_state: The form state.
1 string reference to 'linked_field_element_validate'
File
- ./
linked_field.module, line 315 - Main file of Linked Field module.
Code
function linked_field_element_validate($element, FormStateInterface $form_state) {
$parents = array_slice($element['linked']['#parents'], 0, 3);
$settings = NestedArray::getValue($form_state
->getValues(), $parents);
if (!is_array($settings) || !isset($settings['third_party_settings']['linked_field'])) {
return;
}
$linked_field =& $settings['third_party_settings']['linked_field'];
// Remove empty Linked Field configuration form 3rd party settings.
if (empty($linked_field['linked'])) {
unset($settings['third_party_settings']['linked_field']);
}
else {
// Remove empty attributes from configuration.
foreach ($linked_field['advanced'] as $attribute => $value) {
if (!mb_strlen(trim($value))) {
unset($linked_field['advanced'][$attribute]);
}
}
}
// Set adjusted settings back into form state.
$form_state
->setValue($parents, $settings);
}