LayoutController.php in Layout 8.2
File
lib/Drupal/layout/Controller/LayoutController.php
View source
<?php
namespace Drupal\layout\Controller;
use Drupal\Component\Utility\String;
use Drupal\Core\Access\AccessInterface;
use Drupal\Core\DependencyInjection\ContainerInjectionInterface;
use Drupal\layout\Plugin\Type\LayoutManager;
use Symfony\Component\DependencyInjection\ContainerInterface;
use Symfony\Component\HttpFoundation\Request;
class LayoutController implements ContainerInjectionInterface {
protected $layoutManager;
function __construct(LayoutManager $layout_manager) {
$this->layoutManager = $layout_manager;
}
public static function create(ContainerInterface $container) {
return new static($container
->get('plugin.manager.layout'));
}
public function layoutPageList() {
$layouts = $this->layoutManager
->getDefinitions();
$rows = array();
$header = array(
t('Name'),
t('Source'),
);
foreach ($layouts as $name => $layout) {
$provider_info = system_get_info($layout['provider']['type'], $layout['provider']['provider']);
$row = array();
$row['name'] = l($layout['title'], 'admin/structure/templates/manage/' . $name);
$row['provider'] = t('%name @type', array(
'%name' => $provider_info['name'],
'@type' => t($layout['provider']['type']),
));
$rows[] = $row;
}
$build = array();
$build['table'] = array(
'#theme' => 'table',
'#header' => $header,
'#rows' => $rows,
'#empty' => t('No layouts defined'),
);
return $build;
t('module');
t('theme');
}
public function layoutPageView($key) {
$instance = $this->layoutManager
->createInstance($key, array());
$regions = $instance
->getRegions();
foreach ($regions as $region => $info) {
$regions[$region] = '<div class="layout-region-demonstration">' . String::checkPlain($info['label']) . '</div>';
}
$build['demonstration']['#markup'] = $instance
->renderLayout(TRUE, $regions);
$layout = $this->layoutManager
->getDefinition($key);
$build['#title'] = t('View template %name', array(
'%name' => $layout['title'],
));
$build['#attached']['css'][] = drupal_get_path('module', 'layout') . '/css/layout.admin.css';
return $build;
}
public function checkAccess(Request $request) {
return $this->layoutManager
->getDefinition($request->attributes
->get('key')) ? AccessInterface::ALLOW : AccessInterface::DENY;
}
}