You are here

public function FrontendEnvironmentLibraryController::listFrontendEnvironments in Build Hooks 8.2

Same name and namespace in other branches
  1. 3.x src/Controller/FrontendEnvironmentLibraryController.php \Drupal\build_hooks\Controller\FrontendEnvironmentLibraryController::listFrontendEnvironments()

Shows a list of frontend environments that can be added.

Return value

array A render array as expected by the renderer.

1 string reference to 'FrontendEnvironmentLibraryController::listFrontendEnvironments'
build_hooks.routing.yml in ./build_hooks.routing.yml
build_hooks.routing.yml

File

src/Controller/FrontendEnvironmentLibraryController.php, line 47

Class

FrontendEnvironmentLibraryController
Provides a list of frontend environment plugins.

Namespace

Drupal\build_hooks\Controller

Code

public function listFrontendEnvironments() {
  $headers = [
    [
      'data' => $this
        ->t('Type'),
    ],
    [
      'data' => $this
        ->t('Description'),
    ],
    [
      'data' => $this
        ->t('Operations'),
    ],
  ];
  $definitions = $this->frontendEnvironmentManager
    ->getDefinitions();
  $rows = [];
  foreach ($definitions as $plugin_id => $plugin_definition) {
    $row = [];
    $row['title'] = $plugin_definition['label'];
    $row['description']['data'] = $plugin_definition['description'];
    $links['add'] = [
      'title' => $this
        ->t('Add new environment'),
      'url' => Url::fromRoute('build_hooks.admin_add', [
        'plugin_id' => $plugin_id,
      ]),
    ];
    $row['operations']['data'] = [
      '#type' => 'operations',
      '#links' => $links,
    ];
    $rows[] = $row;
  }
  $build['frontend_environments'] = [
    '#type' => 'table',
    '#header' => $headers,
    '#rows' => $rows,
    '#empty' => $this
      ->t('No types available. Please enable one of the submodules or add your own custom plugin.'),
  ];
  return $build;
}