You are here

public function ViewInclusion::buildConfigurationForm in Context 8

Same name and namespace in other branches
  1. 8.4 src/Plugin/Condition/ViewInclusion.php \Drupal\context\Plugin\Condition\ViewInclusion::buildConfigurationForm()

Parameters

array $form:

\Drupal\Core\Form\FormStateInterface $form_state:

Return value

array

Overrides ConditionPluginBase::buildConfigurationForm

File

src/Plugin/Condition/ViewInclusion.php, line 66

Class

ViewInclusion
Provides a 'Views' condition.

Namespace

Drupal\context\Plugin\Condition

Code

public function buildConfigurationForm(array $form, FormStateInterface $form_state) {
  $views = $this->entityTypeManager
    ->getStorage('view')
    ->loadMultiple();
  $options = [];
  foreach ($views as $key => $view) {
    foreach ($view
      ->get('display') as $display) {
      if ($display['display_plugin'] === 'page') {
        $viewRoute = 'view-' . $key . '-' . $display['id'];
        $options[$viewRoute] = $view
          ->label() . ' - ' . $display['display_title'];
      }
    }
  }
  $configuration = $this
    ->getConfiguration();
  $form['views_pages'] = [
    '#title' => $this
      ->t('Views pages'),
    '#type' => 'select',
    '#options' => $options,
    '#multiple' => TRUE,
    '#default_value' => isset($configuration['view_inclusion']) && !empty($configuration['view_inclusion']) ? array_keys($configuration['view_inclusion']) : [],
  ];
  return $form;
}