public static function DynamicEntityReferenceWidget::processFormElement in Dynamic Entity Reference 8
Same name and namespace in other branches
- 8.2 src/Plugin/Field/FieldWidget/DynamicEntityReferenceWidget.php \Drupal\dynamic_entity_reference\Plugin\Field\FieldWidget\DynamicEntityReferenceWidget::processFormElement()
Adds entity autocomplete paths to a form element.
Parameters
array $element: The form element.
\Drupal\Core\Form\FormStateInterface $form_state: The current state of the form.
array $complete_form: The complete form structure.
Return value
array The form element.
File
- src/
Plugin/ Field/ FieldWidget/ DynamicEntityReferenceWidget.php, line 151
Class
- DynamicEntityReferenceWidget
- Plugin implementation of the 'dynamic_entity_reference autocomplete' widget.
Namespace
Drupal\dynamic_entity_reference\Plugin\Field\FieldWidgetCode
public static function processFormElement(array &$element, FormStateInterface $form_state, array &$complete_form) {
$name = implode('-', $element['#parents']);
$js_class = Html::cleanCssIdentifier("js-dynamic-entity-reference-{$name}-target_type");
$element['target_type']['#attributes']['data-dynamic-entity-reference'] = $element['target_type']['#attributes']['class'][] = $js_class;
$auto_complete_paths = $element['#attached']['drupalSettings']['dynamic_entity_reference']['auto_complete_paths'];
unset($element['#attached']['drupalSettings']['dynamic_entity_reference']['auto_complete_paths']);
$element['#attached']['drupalSettings']['dynamic_entity_reference'][$js_class] = $auto_complete_paths;
return $element;
}