You are here

protected function ViewWidget::formMultipleElements in Entity Reference View Widget 8

Overrides \Drupal\file\Plugin\Field\FieldWidget\FileWidget::formMultipleElements().

Modify the add_more button.

Overrides WidgetBase::formMultipleElements

File

src/Plugin/Field/FieldWidget/ViewWidget.php, line 195
Contains \Drupal\entity_reference_view_widget\Plugin\Field\FieldWidget\ViewWidget.

Class

ViewWidget
Plugin implementation of the 'entity_reference_view_widget' widget.

Namespace

Drupal\entity_reference_view_widget\Plugin\Field\FieldWidget

Code

protected function formMultipleElements(FieldItemListInterface $items, array &$form, FormStateInterface $form_state) {
  $elements = parent::formMultipleElements($items, $form, $form_state);
  $form['#attached']['library'][] = 'views/views.ajax';
  $elements['add_more'] = array(
    '#type' => 'button',
    '#value' => t('Add items'),
    '#ajax' => array(
      'callback' => array(
        $this,
        'ajaxCallback',
      ),
    ),
    '#limit_validation_errors' => array(),
  );
  return $elements;
}