diff --git a/devel.links.menu.yml b/devel.links.menu.yml index 2a90f86..cf164b0 100644 --- a/devel.links.menu.yml +++ b/devel.links.menu.yml @@ -91,3 +91,10 @@ devel.event_info: title: 'Events Info' route_name: devel.event_info menu_name: devel + +# Layouts info +devel.layout_info_page: + title: 'Layouts Info' + parent: system.admin_reports + description: 'Overview of layouts available to the site.' + route_name: devel.layout_info diff --git a/devel.routing.yml b/devel.routing.yml index 6b91709..a2da0e2 100644 --- a/devel.routing.yml +++ b/devel.routing.yml @@ -242,3 +242,15 @@ devel.event_info: _admin_route: TRUE requirements: _permission: 'access devel information' + +# Layouts info +devel.layout_info: + path: '/admin/reports/layouts' + defaults: + _controller: '\Drupal\devel\Controller\LayoutInfoController::layoutInfoPage' + _title: 'Layouts' + options: + _admin_route: TRUE + requirements: + _permission: 'access devel information' + _module_dependencies: 'layout_discovery' diff --git a/src/Controller/LayoutInfoController.php b/src/Controller/LayoutInfoController.php new file mode 100644 index 0000000..b3455fb --- /dev/null +++ b/src/Controller/LayoutInfoController.php @@ -0,0 +1,85 @@ +layoutPluginManager = $pluginManagerLayout; + } + + /** + * {@inheritdoc} + */ + public static function create(ContainerInterface $container) { + return new static( + $container->get('plugin.manager.core.layout') + ); + } + + /** + * Builds the Layout Info page. + * + * @return array + * Array of page elements to render. + */ + public function layoutInfoPage() { + $definedLayouts = []; + $layouts = $this->layoutPluginManager->getDefinitions(); + foreach ($layouts as $layout) { + // @todo Revisit once https://www.drupal.org/node/2660124 gets in, getting + // the image should be as simple as $layout->getIcon(). + $image = NULL; + if ($layout->getIconPath() != NULL) { + $image = [ + 'data' => [ + '#theme' => 'image', + '#uri' => $layout->getIconPath(), + '#alt' => $layout->getLabel(), + '#height' => '65', + ] + ]; + } + $definedLayouts[] = [ + $image, + $layout->getLabel(), + $layout->getDescription(), + $layout->getCategory(), + implode(', ', $layout->getRegionLabels()), + $layout->getProvider(), + ]; + } + + return [ + '#theme' => 'table', + '#header' => [ + $this->t('Icon'), + $this->t('Label'), + $this->t('Description'), + $this->t('Category'), + $this->t('Regions'), + $this->t('Provider'), + ], + '#rows' => $definedLayouts, + '#empty' => $this->t('No layouts available.'), + ]; + } + +} diff --git a/src/Tests/LayoutInfoControllerTest.php b/src/Tests/LayoutInfoControllerTest.php new file mode 100644 index 0000000..3ec88f5 --- /dev/null +++ b/src/Tests/LayoutInfoControllerTest.php @@ -0,0 +1,46 @@ +drupalCreateUser(array( + 'access devel information', + )); + $this->drupalLogin($web_user); + } + + function testLayoutInfoPage() { + // Test Devel load and render routes for the Layout Info page. + $this->drupalGet('admin/reports/layouts'); + $this->assertResponse(200); + $this->assertText('Layouts', 'Layouts title is present'); + $this->assertText('Icon', 'Icon column header is present'); + $this->assertText('Label', 'Label column header is present'); + $this->assertText('Description', 'Description column header is present'); + $this->assertText('Category', 'Category column header is present'); + $this->assertText('Regions', 'Regions column header is present'); + $this->assertText('Provider', 'Provider column header is present'); + } + +}