You are here

public function ViewWidget::settingsForm in Entity Reference View Widget 8

Returns a form to configure settings for the widget.

Invoked from \Drupal\field_ui\Form\EntityDisplayFormBase to allow administrators to configure the widget. The field_ui module takes care of handling submitted form values.

Parameters

array $form: The form where the settings form is being included in.

\Drupal\Core\Form\FormStateInterface $form_state: The current state of the form.

Return value

array The form definition for the widget settings.

Overrides WidgetBase::settingsForm

File

src/Plugin/Field/FieldWidget/ViewWidget.php, line 52
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

public function settingsForm(array $form, FormStateInterface $form_state) {
  $displays = Views::getApplicableViews('entity_reference_view_widget_display');
  $options = array();
  foreach ($displays as $data) {
    list($view, $display_id) = $data;
    $options[$view->storage
      ->id() . '|' . $display_id] = String::checkPlain($view->storage
      ->label() . ' | ' . $view->storage
      ->getDisplay($display_id)['display_title']);
  }
  $element['view'] = array(
    '#type' => 'select',
    '#title' => t('View'),
    '#default_value' => $this
      ->getSetting('view'),
    '#options' => $options,
    '#description' => t('Specify the View to use for selecting items. Only views that have an "Entityreference View Widget" display are shown.'),
    '#required' => TRUE,
  );
  $element['pass_argument'] = array(
    '#type' => 'checkbox',
    '#title' => t('Pass selected entity ids to View'),
    '#default_value' => $this
      ->getSetting('pass_argument'),
    '#description' => t('If enabled, the View will get all selected entity ids as the first argument. Useful for excluding already selected items.'),
  );
  $element['close_modal'] = array(
    '#type' => 'checkbox',
    '#title' => t('Close modal window after submitting the items'),
    '#default_value' => $this
      ->getSetting('close_modal'),
    '#description' => t('If enabled, the modal window will close after you had selected the entities from the view and submitted your selection.'),
  );
  $element['allow_duplicates'] = array(
    '#type' => 'checkbox',
    '#title' => t('Allow the same entity to be referenced multiple times'),
    '#default_value' => $this
      ->getSetting('allow_duplicates'),
    '#description' => t('If enabled, this will allow you to reference the same entity multiple times.'),
  );
  return $element;
}