protected function SocialLinkWidget::formMultipleElements in Social Link Field 8
Special handling to create form elements for multiple values.
Handles generic features for multiple fields:
- number of widgets
- AHAH-'add more' button
- table display and drag-n-drop value reordering
Overrides WidgetBase::formMultipleElements
File
- src/
Plugin/ Field/ FieldWidget/ SocialLinkWidget.php, line 272
Class
- SocialLinkWidget
- Plugin implementation of the 'open_hours' widget.
Namespace
Drupal\social_link_field\Plugin\Field\FieldWidgetCode
protected function formMultipleElements(FieldItemListInterface $items, array &$form, FormStateInterface $form_state) {
$form['#wrapper_id'] = Html::getUniqueID($items
->getName());
// Just in this case is important to preserve default value order.
if (!$this
->getSetting('select_social') && $this->cardinality !== FieldStorageDefinitionInterface::CARDINALITY_UNLIMITED && stripos($this->routeName, 'entity.field_config') === FALSE) {
$this
->ensureItemsOrder($items);
}
$elements = parent::formMultipleElements($items, $form, $form_state);
$elements['#prefix'] = '<div id="' . $form['#wrapper_id'] . '">';
$elements['#suffix'] = '</div>';
$elements['add_more']['#ajax']['wrapper'] = $form['#wrapper_id'];
if ($this
->getSetting('disable_weight')) {
// Disable item order change.
$elements['#theme'] = 'field_multiple_value_no_draggable_form';
}
return $elements;
}