protected function AutocompleteWidgetBase::prepareElement in Entity reference 8
Prepapre the element.
@default_path The menu item to be used in the autocomplete path.
3 calls to AutocompleteWidgetBase::prepareElement()
- AutocompleteTagsWidget::formElement in lib/
Drupal/ entityreference/ Plugin/ field/ widget/ AutocompleteTagsWidget.php - Implements Drupal\field\Plugin\Type\Widget\WidgetInterface::formElement().
- AutocompleteWidget::formElement in lib/
Drupal/ entityreference/ Plugin/ field/ widget/ AutocompleteWidget.php - Implements Drupal\field\Plugin\Type\Widget\WidgetInterface::formElement().
- AutocompleteWidgetBase::formElement in lib/
Drupal/ entityreference/ Plugin/ field/ widget/ AutocompleteWidgetBase.php - Implements Drupal\field\Plugin\Type\Widget\WidgetInterface::formElement().
File
- lib/
Drupal/ entityreference/ Plugin/ field/ widget/ AutocompleteWidgetBase.php, line 61 - Definition of Drupal\entityreference\Plugin\field\widget\AutocompleteWidgetBase.
Class
- AutocompleteWidgetBase
- Parent plugin for entity-reference autocomplete widgets.
Namespace
Drupal\entityreference\Plugin\field\widgetCode
protected function prepareElement(array $items, $delta, array $element, $langcode, array &$form, array &$form_state, $default_path) {
$instance = $this->instance;
$field = $this->field;
$entity = isset($element['#entity']) ? $element['#entity'] : NULL;
// Prepare the autocomplete path.
$path = $this
->getSetting('path');
$autocomplete_path = !empty($path) ? $path : $default_path;
$autocomplete_path .= '/' . $field['field_name'] . '/' . $instance['entity_type'] . '/' . $instance['bundle'] . '/';
// Use <NULL> as a placeholder in the URL when we don't have an entity.
// Most webservers collapse two consecutive slashes.
$id = 'NULL';
if ($entity) {
if ($eid = $entity
->id()) {
$id = $eid;
}
}
$autocomplete_path .= $id;
$element += array(
'#type' => 'textfield',
'#maxlength' => 1024,
'#default_value' => implode(', ', $this
->getLabels($items)),
'#autocomplete_path' => $autocomplete_path,
'#size' => $this
->getSetting('size'),
'#element_validate' => array(
array(
$this,
'elementValidate',
),
),
);
return $element;
}