ViewsBuilderController.php in Views Templates 8
File
src/Controller/ViewsBuilderController.php
View source
<?php
namespace Drupal\views_templates\Controller;
use Drupal\Component\Plugin\PluginManagerInterface;
use Drupal\Core\Controller\ControllerBase;
use Drupal\Core\Url;
use Symfony\Component\DependencyInjection\ContainerInterface;
class ViewsBuilderController extends ControllerBase {
protected $builderManager;
public function __construct(PluginManagerInterface $builderManager) {
$this->builderManager = $builderManager;
}
public static function create(ContainerInterface $container) {
return new static($container
->get('plugin.manager.views_templates.builder'));
}
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'),
];
foreach ($this->builderManager
->getDefinitions() as $definition) {
$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;
}
}