You are here

public function ViewsEmbedDialog::buildSelectArguments in Views entity embed 8

Same name and namespace in other branches
  1. 2.0.x src/Form/ViewsEmbedDialog.php \Drupal\views_entity_embed\Form\ViewsEmbedDialog::buildSelectArguments()

Form constructor for the entity embedding step.

Parameters

array $form: An associative array containing the structure of the form.

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

Return value

array The form structure.

1 call to ViewsEmbedDialog::buildSelectArguments()
ViewsEmbedDialog::buildForm in src/Form/ViewsEmbedDialog.php
Form constructor.

File

src/Form/ViewsEmbedDialog.php, line 354

Class

ViewsEmbedDialog
Provides a form to embed URLs.

Namespace

Drupal\views_entity_embed\Form

Code

public function buildSelectArguments(array $form, FormStateInterface $form_state) {
  $view = $form_state
    ->get('view');
  $form['#title'] = $this
    ->t('Select Argument for @title view', [
    '@title' => $view
      ->getTitle(),
  ]);
  $select_arguments = $form_state
    ->get('select_arguments');
  $form['build_select_arguments'] = [
    '#type' => 'fieldset',
    '#title' => $this
      ->t('Views settings'),
    '#tree' => TRUE,
  ];
  $form['build_select_arguments']['override_title'] = [
    '#type' => 'checkbox',
    '#title' => $this
      ->t('Override title'),
    '#default_value' => isset($select_arguments['override_title']) ? $select_arguments['override_title'] : '',
  ];
  $form['build_select_arguments']['title'] = [
    '#type' => 'textfield',
    '#title' => $this
      ->t('Title'),
    '#default_value' => isset($select_arguments['title']) ? $select_arguments['title'] : '',
    '#states' => [
      'visible' => [
        [
          ':input[name="build_select_arguments[override_title]"]' => [
            'checked' => TRUE,
          ],
        ],
      ],
    ],
  ];
  $arguments = $view->display_handler
    ->getHandlers('argument');
  if (!empty($arguments)) {
    $form['build_select_arguments']['filters'] = [
      '#type' => 'details',
      '#title' => t('Views contexual filters'),
    ];
    foreach ($arguments as $id => $argument) {
      $form['build_select_arguments']['filters'][$id] = [
        '#type' => 'textfield',
        '#title' => $argument
          ->adminLabel(),
        '#default_value' => isset($select_arguments[$id]) ? $select_arguments[$id] : '',
      ];
    }
  }
  else {
    $form['build_select_arguments']['no_contextual_filters'] = [
      '#type' => 'item',
      '#description' => t('This View does not have a contexual filters.'),
    ];
  }
  $form['actions'] = [
    '#type' => 'actions',
  ];
  $form['actions']['save_modal'] = [
    '#type' => 'submit',
    '#value' => $this
      ->t('Embed'),
    '#button_type' => 'primary',
    // No regular submit-handler. This form only works via JavaScript.
    '#submit' => [],
    '#ajax' => [
      'callback' => '::submitSelectArguments',
      'event' => 'click',
    ],
  ];
  return $form;
}