You are here

public function PageManagerController::selectVariant in Page Manager 8

Same name and namespace in other branches
  1. 8.4 page_manager_ui/src/Controller/PageManagerController.php \Drupal\page_manager_ui\Controller\PageManagerController::selectVariant()

Presents a list of variants to add to the page entity.

Parameters

\Drupal\page_manager\PageInterface $page: The page entity.

Return value

array The variant selection page.

1 string reference to 'PageManagerController::selectVariant'
page_manager_ui.routing.yml in page_manager_ui/page_manager_ui.routing.yml
page_manager_ui/page_manager_ui.routing.yml

File

page_manager_ui/src/Controller/PageManagerController.php, line 211
Contains \Drupal\page_manager_ui\Controller\PageManagerController.

Class

PageManagerController
Provides route controllers for Page Manager.

Namespace

Drupal\page_manager_ui\Controller

Code

public function selectVariant(PageInterface $page) {
  $build = [
    '#theme' => 'links',
    '#links' => [],
  ];
  foreach ($this->variantManager
    ->getDefinitions() as $variant_plugin_id => $variant_plugin) {

    // The following two variants are provided by Drupal Core. They are not
    // configurable and therefore not compatible with Page Manager but have
    // similar and confusing labels. Skip them so that they are not shown in
    // the UI.
    if (in_array($variant_plugin_id, [
      'simple_page',
      'block_page',
    ])) {
      continue;
    }
    $build['#links'][$variant_plugin_id] = [
      'title' => $variant_plugin['admin_label'],
      'url' => Url::fromRoute('entity.page_variant.add_form', [
        'page' => $page
          ->id(),
        'variant_plugin_id' => $variant_plugin_id,
      ]),
      'attributes' => $this
        ->getAjaxAttributes(),
    ];
  }
  return $build;
}