Commit 00511761 authored by alexpott's avatar alexpott

Issue #1978908 by plopesc: Convert layout_page_list() to a Controller.

parent 478490f2
......@@ -5,46 +5,6 @@
* Administration functions for layouts.
*/
/**
* Page callback: Presents a list of layouts.
*
* @return array
* An array as expected by drupal_render().
*
* @see layout_menu()
*/
function layout_page_list() {
// Get list of layouts defined by enabled modules and themes.
$layouts = layout_manager()->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']);
// Build table columns for this row.
$row = array();
$row['name'] = l($layout['title'], 'admin/structure/templates/manage/' . $name);
// Type can either be 'module' or 'theme'.
$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,
);
return $build;
// Ensure the provider types are translatable. These do not need to run,
// just inform the static code parser of these source strings.
t('module');
t('theme');
}
/**
* Page callback: Demonstrates a layout template.
*
......
......@@ -12,10 +12,7 @@ function layout_menu() {
$items['admin/structure/templates'] = array(
'title' => 'Templates',
'description' => 'Overview of the list of layout templates available.',
'page callback' => 'layout_page_list',
'access callback' => 'user_access',
'access arguments' => array('administer layouts'),
'file' => 'layout.admin.inc',
'route_name' => 'layout_page_list',
);
$items['admin/structure/templates/manage/%'] = array(
'title' => 'View template',
......
layout_page_list:
pattern: '/admin/structure/templates'
defaults:
_content: '\Drupal\layout\Controller\LayoutController::layoutPageList'
requirements:
_permission: 'administer layouts'
<?php
/**
* @file
* Contains \Drupal\layout\Controller\LayoutController.
*/
namespace Drupal\layout\Controller;
use Drupal\Core\ControllerInterface;
use Drupal\layout\Plugin\Type\LayoutManager;
use Symfony\Component\DependencyInjection\ContainerInterface;
/**
* Controller routines for layout routes.
*/
class LayoutController implements ControllerInterface {
/**
* Stores the Layout manager.
*
* @var \Drupal\layout\Plugin\Type\LayoutManager
*/
protected $layoutManager;
/**
* Constructs a \Drupal\layout\Controller\LayoutController object.
*
* @param \Drupal\layout\Plugin\Type\LayoutManager $layout_manager
* The Layout manager.
*/
function __construct(LayoutManager $layout_manager) {
$this->layoutManager = $layout_manager;
}
/**
* {@inheritdoc}
*/
public static function create(ContainerInterface $container) {
return new static($container->get('plugin.manager.layout'));
}
/**
* Presents a list of layouts.
*
* @return array
* A form array as expected by drupal_render().
*/
public function layoutPageList() {
// Get list of layouts defined by enabled modules and themes.
$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']);
// Build table columns for this row.
$row = array();
$row['name'] = l($layout['title'], 'admin/structure/templates/manage/' . $name);
// Type can either be 'module' or 'theme'.
$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,
);
return $build;
// Ensure the provider types are translatable. These do not need to run,
// just inform the static code parser of these source strings.
t('module');
t('theme');
}
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment