You are here

public function ViewsReferenceItem::fieldSettingsForm in Views Reference Field 8.2

Same name and namespace in other branches
  1. 8 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 101

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'] : [];
  $enabled_settings = isset($settings['enabled_settings']) ? $settings['enabled_settings'] : [];
  $display_options = $this
    ->getAllViewDisplayIds();
  $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' => $this
      ->t('Preselect View Options'),
    '#options' => $view_list,
    '#default_value' => $preselect_views,
    '#weight' => 2,
  ];
  $enabled_settings_list = [];
  $viewsreference_plugin_manager = \Drupal::service('plugin.manager.viewsreference.setting');
  $plugin_definitions = $viewsreference_plugin_manager
    ->getDefinitions();
  foreach ($plugin_definitions as $plugin_definition) {
    $enabled_settings_list[$plugin_definition['id']] = $plugin_definition['label'];
  }
  $form['enabled_settings'] = [
    '#type' => 'checkboxes',
    '#title' => $this
      ->t('Enable extra settings'),
    '#options' => $enabled_settings_list,
    '#default_value' => $enabled_settings,
    '#weight' => 3,
  ];
  return $form;
}