You are here

public function InsertView::settingsForm in Advanced Insert View 2.0.x

Same name in this branch
  1. 2.0.x src/Plugin/Filter/InsertView.php \Drupal\insert_view_adv\Plugin\Filter\InsertView::settingsForm()
  2. 2.0.x src/Plugin/CKEditorPlugin/InsertView.php \Drupal\insert_view_adv\Plugin\CKEditorPlugin\InsertView::settingsForm()
Same name and namespace in other branches
  1. 8 src/Plugin/Filter/InsertView.php \Drupal\insert_view_adv\Plugin\Filter\InsertView::settingsForm()

Generates a filter's settings form.

Parameters

array $form: A minimally prepopulated form array.

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

Return value

array The $form array with additional form elements for the settings of this filter. The submitted form values should match $this->settings.

Overrides FilterBase::settingsForm

File

src/Plugin/Filter/InsertView.php, line 304

Class

InsertView
Provides a filter for insert view.

Namespace

Drupal\insert_view_adv\Plugin\Filter

Code

public function settingsForm(array $form, FormStateInterface $form_state) {
  $form = parent::settingsForm($form, $form_state);
  $views_list = Views::getEnabledViews();
  $options = [];
  foreach ($views_list as $machine_name => $view) {
    foreach ($view
      ->get('display') as $display) {
      $display_title = !empty($display['display_options']['title']) ? $display['display_options']['title'] : $display['display_title'];
      $options[$machine_name . '=' . $display['id']] = $this
        ->t('@view_name: @display_title (@display_name)', [
        '@view_name' => $view
          ->label(),
        '@display_title' => $display_title,
        '@display_name' => $display['id'],
      ]);
    }
  }
  $form['allowed_views'] = [
    '#type' => 'checkboxes',
    '#title' => $this
      ->t('Allowed views to insert'),
    '#description' => $this
      ->t('Leave empty to allow all views'),
    '#options' => $options,
    '#default_value' => $this->settings['allowed_views'],
  ];
  $form['render_as_empty'] = [
    '#type' => 'checkbox',
    '#title' => $this
      ->t('Do not render disabled/not allowed views'),
    '#default_value' => $this->settings['render_as_empty'],
    '#description' => $this
      ->t('If unchecked the disabled/not allowed view will be rendered as token [view:view_name=display_id=args]'),
  ];
  $form['hide_argument_input'] = [
    '#type' => 'checkbox',
    '#title' => $this
      ->t('Hide views arguments (contextual filters) input'),
    '#default_value' => $this->settings['hide_argument_input'],
    '#description' => $this
      ->t('If checked the user will not be allowed to input the argument values, only default will be used.'),
  ];
  return $form;
}