You are here

protected function ViewsEmbedDialog::selectStepsOfForm 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::selectStepsOfForm()

Skip steps with only one options.

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

File

src/Form/ViewsEmbedDialog.php, line 102

Class

ViewsEmbedDialog
Provides a form to embed URLs.

Namespace

Drupal\views_entity_embed\Form

Code

protected function selectStepsOfForm(array &$form, FormStateInterface $form_state, EmbedButtonInterface $embed_button) {
  $view_element = $form_state
    ->get('view_element');
  $filterByViews = $this
    ->getViewsOptions($embed_button);

  // If embed button has only 1 view to render we skip step 1.
  if (count($filterByViews) == 1) {
    $view_element['data-view-name'] = key($filterByViews);
    $view = Views::getView($view_element['data-view-name']);
    $view
      ->initHandlers();
    $filterByDisplays = $this
      ->getViewDisplays($view, $embed_button);

    // If only 1 display is available for rendering we skip step 2.
    if (count($filterByDisplays) == 1) {
      $view_element['data-view-display'] = key($filterByDisplays);
      $view
        ->setDisplay($view_element['data-view-display']);
      $form_state
        ->set('step', 'select_arguments');
    }
    else {
      $form_state
        ->set('step', 'select_display');
    }
    $form_state
      ->set('view', $view);
    $form_state
      ->set('view_element', $view_element);
  }
  else {

    // Else set the first step
    $form_state
      ->set('step', 'select_view');
  }
}