You are here

public function ViewsReferenceItem::fieldSettingsForm in Views Reference Field 8

Same name and namespace in other branches
  1. 8.2 src/Plugin/Field/FieldType/ViewsReferenceItem.php \Drupal\viewsreference\Plugin\Field\FieldType\ViewsReferenceItem::fieldSettingsForm()

Returns a form for the field-level settings.

Invoked from \Drupal\field_ui\Form\FieldConfigEditForm to allow administrators to configure field-level settings.

Parameters

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

\Drupal\Core\Form\FormStateInterface $form_state: The form state of the (entire) configuration form.

Return value

array The form definition for the field settings.

Overrides EntityReferenceItem::fieldSettingsForm

File

src/Plugin/Field/FieldType/ViewsReferenceItem.php, line 148

Class

ViewsReferenceItem
Defines the 'viewsreference' entity field type.

Namespace

Drupal\viewsreference\Plugin\Field\FieldType

Code

public function fieldSettingsForm(array $form, FormStateInterface $form_state) {
  $form = parent::fieldSettingsForm($form, $form_state);
  $settings = $this
    ->getSettings();
  $preselect_views = isset($settings['preselect_views']) ? $settings['preselect_views'] : [];
  $default_plugins = isset($settings['plugin_types']) ? $settings['plugin_types'] : [];
  $display_options = $this
    ->getAllPluginList();
  $view_list = $this
    ->getAllViewsNames();
  $form['plugin_types'] = [
    '#type' => 'checkboxes',
    '#options' => $display_options,
    '#title' => $this
      ->t('View display plugins to allow'),
    '#default_value' => $default_plugins,
    '#weight' => 1,
  ];
  $form['preselect_views'] = [
    '#type' => 'checkboxes',
    '#title' => t('Preselect View Options'),
    '#options' => $view_list,
    '#default_value' => $preselect_views,
    '#weight' => 2,
  ];
  return $form;
}