You are here

public function MaestroTemplateFormBase::fetchViewsDisplays in Maestro 8.2

Same name and namespace in other branches
  1. 3.x src/Form/MaestroTemplateFormBase.php \Drupal\maestro\Form\MaestroTemplateFormBase::fetchViewsDisplays()

Fetches the views displays associated to this template form.

File

src/Form/MaestroTemplateFormBase.php, line 332

Class

MaestroTemplateFormBase
Class MaestroTemplateFormBase.

Namespace

Drupal\maestro\Form

Code

public function fetchViewsDisplays(array $form, FormStateInterface $form_state) {
  $options = [];
  if ($form_state
    ->getValue('add_view') != '') {
    $view = Views::getView($form_state
      ->getValue('add_view'));
    if ($view) {
      foreach ($view->storage
        ->get('display') as $display_machine_name => $arr) {
        $options[$display_machine_name . ';' . $arr['display_title']] = $arr['display_title'];
      }
    }
    else {
      $options[''] = $this
        ->t('Please reselect View');
    }
    $form['show_details_area']['add_view_display']['#options'] = $options;
  }
  else {
    $form['show_details_area']['add_view_display'] = [
      '#display' => FALSE,
      '#prefix' => '<div id="dropdown-views-bundles-replace">',
      '#suffix' => '</div>',
    ];
  }
  return $form['show_details_area']['add_view_display'];
}