You are here

public function ViewsBuilderController::templateList in Views Templates 8

Create template list table.

Return value

array Render array of template list.

1 string reference to 'ViewsBuilderController::templateList'
views_templates.routing.yml in ./views_templates.routing.yml
views_templates.routing.yml

File

src/Controller/ViewsBuilderController.php, line 47

Class

ViewsBuilderController
ViewBuilderController class.

Namespace

Drupal\views_templates\Controller

Code

public function templateList() {
  $table = [
    '#type' => 'table',
    '#header' => [
      $this
        ->t('Name'),
      $this
        ->t('Description'),
      $this
        ->t('Add'),
    ],
    '#empty' => $this
      ->t('There are no available Views Templates'),
  ];

  /** @var \Drupal\views_templates\Plugin\ViewsBuilderPluginInterface $definition */
  foreach ($this->builderManager
    ->getDefinitions() as $definition) {

    /** @var \Drupal\views_templates\Plugin\ViewsBuilderPluginInterface $builder */
    $builder = $this->builderManager
      ->createInstance($definition['id']);
    if ($builder
      ->templateExists()) {
      $plugin_id = $builder
        ->getPluginId();
      $row = [
        'name' => [
          '#plain_text' => $builder
            ->getAdminLabel(),
        ],
        'description' => [
          '#plain_text' => $builder
            ->getDescription(),
        ],
        'add' => [
          '#type' => 'link',
          '#title' => $this
            ->t('Add'),
          '#url' => Url::fromRoute('views_templates.create_from_template', [
            'view_template' => $plugin_id,
          ]),
        ],
      ];
      $table[$plugin_id] = $row;
    }
  }
  return $table;
}