diff --git a/core/modules/layout/layout.admin.css b/core/modules/layout/layout.admin.css new file mode 100644 index 0000000..05574d9 --- /dev/null +++ b/core/modules/layout/layout.admin.css @@ -0,0 +1,26 @@ +.layout-display { + background: rgb(224, 224, 224); +} + +.layout-region-demonstration { + color: white; + margin: 3px; + padding: 10px; + text-transform: uppercase; + font-size: 0.8em; + + background-image: linear-gradient(bottom, rgb(70,70,71) 40%, rgb(91,91,94) 70%, rgb(125,124,125) 88%); + background-image: -o-linear-gradient(bottom, rgb(70,70,71) 40%, rgb(91,91,94) 70%, rgb(125,124,125) 88%); + background-image: -moz-linear-gradient(bottom, rgb(70,70,71) 40%, rgb(91,91,94) 70%, rgb(125,124,125) 88%); + background-image: -webkit-linear-gradient(bottom, rgb(70,70,71) 40%, rgb(91,91,94) 70%, rgb(125,124,125) 88%); + background-image: -ms-linear-gradient(bottom, rgb(70,70,71) 40%, rgb(91,91,94) 70%, rgb(125,124,125) 88%); + + background-image: -webkit-gradient( + linear, + left bottom, + left top, + color-stop(0.4, rgb(70,70,71)), + color-stop(0.7, rgb(91,91,94)), + color-stop(0.88, rgb(125,124,125)) + ); +} diff --git a/core/modules/layout/layout.admin.inc b/core/modules/layout/layout.admin.inc new file mode 100644 index 0000000..3ba2f78 --- /dev/null +++ b/core/modules/layout/layout.admin.inc @@ -0,0 +1,66 @@ +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: Demonstrate a layout template. + * + * @see layout_menu() + */ +function layout_page_view($key) { + $layout = layout_manager()->getDefinition($key); + drupal_set_title(t('View template %name', array('%name' => $layout['title'])), PASS_THROUGH); + + // Render the layout in an admin context with region demonstrations. + $instance = layout_manager()->createInstance($key, array()); + $regions = $instance->getRegions(); + foreach ($regions as $region => $info) { + $regions[$region] = '
' . check_plain($info['label']) . '
'; + } + $build['demonstration'] = array( + '#type' => 'markup', + '#markup' => $instance->renderLayout(TRUE, $regions), + ); + $build['#attached']['css'][] = drupal_get_path('module', 'layout') . '/layout.admin.css'; + return $build; +} diff --git a/core/modules/layout/layout.module b/core/modules/layout/layout.module index 7d82798..f4fb110 100644 --- a/core/modules/layout/layout.module +++ b/core/modules/layout/layout.module @@ -6,6 +6,48 @@ */ /** + * Implements hook_menu(). + */ +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', + ); + $items['admin/structure/templates/manage/%'] = array( + 'title' => 'View template', + 'page callback' => 'layout_page_view', + 'page arguments' => array(4), + 'access callback' => 'layout_user_access', + 'access arguments' => array(4), + 'file' => 'layout.admin.inc', + ); + return $items; +} + +/** + * Menu access callback. Check for layout existance. + */ +function layout_user_access($key) { + return (user_access('administer layouts') && layout_manager()->getDefinition($key)); +} + +/** + * Implements hook_permission(). + */ +function layout_permission() { + return array( + 'administer layouts' => array( + 'title' => t('Administer templates'), + 'description' => t('Access administration functions for templates.'), + ), + ); +} + +/** * Get the layout plugin manager instance. * * @return Drupal\layout\Plugin\Type\LayoutManager diff --git a/core/modules/layout/lib/Drupal/layout/Plugin/Derivative/Layout.php b/core/modules/layout/lib/Drupal/layout/Plugin/Derivative/Layout.php index ce82c65..a6c4ea9 100644 --- a/core/modules/layout/lib/Drupal/layout/Plugin/Derivative/Layout.php +++ b/core/modules/layout/lib/Drupal/layout/Plugin/Derivative/Layout.php @@ -106,6 +106,7 @@ protected function iterateDirectories($dir, $provider) { $this->derivatives[$key] = $directory->read($fileinfo->getBasename('.yml')); $this->derivatives[$key]['theme'] = $key; $this->derivatives[$key]['path'] = $fileinfo->getPath(); + $this->derivatives[$key]['provider'] = $provider; // If the layout author didn't specify a template name, assume the same // name as the yml file. if (!isset($this->derivatives[$key]['template'])) { diff --git a/core/modules/layout/lib/Drupal/layout/Plugin/LayoutInterface.php b/core/modules/layout/lib/Drupal/layout/Plugin/LayoutInterface.php index 7521c57..a835f23 100644 --- a/core/modules/layout/lib/Drupal/layout/Plugin/LayoutInterface.php +++ b/core/modules/layout/lib/Drupal/layout/Plugin/LayoutInterface.php @@ -18,15 +18,24 @@ * Returns a list of regions. * * @return array - * An array of region machine names. + * An associative array of region information keyed by region machine + * names. Each region information element is a two item associative array + * with a 'label' and a 'type' key designating the human readable label + * and the type of the region. */ public function getRegions(); /** * Renders layout and returns the rendered markup. * + * @param boolean $admin + * TRUE if the rendered layout is displayed in an administrative context, + * FALSE otherwise. + * @param array $regions + * An array of region render arrays keyed by region machine names. + * * @return string * Rendered HTML output from the layout. */ - public function renderLayout(); + public function renderLayout($admin = FALSE, $regions = array()); } diff --git a/core/modules/layout/lib/Drupal/layout/Plugin/layout/layout/StaticLayout.php b/core/modules/layout/lib/Drupal/layout/Plugin/layout/layout/StaticLayout.php index 3ded379..f3f6762 100644 --- a/core/modules/layout/lib/Drupal/layout/Plugin/layout/layout/StaticLayout.php +++ b/core/modules/layout/lib/Drupal/layout/Plugin/layout/layout/StaticLayout.php @@ -78,7 +78,7 @@ public function getAdminScriptFiles() { /** * Implements Drupal\layout\Plugin\LayoutInterface::renderLayout(). */ - public function renderLayout($admin = FALSE) { + public function renderLayout($admin = FALSE, $regions = array()) { $definition = $this->getDefinition(); // Assemble a render array with the regions and attached CSS/JS. @@ -89,10 +89,8 @@ public function renderLayout($admin = FALSE) { // Render all regions needed for this layout. foreach ($this->getRegions() as $region => $info) { - // @todo This is just stub code to fill in regions with stuff for now. - // When blocks are related to layouts and not themes, we can make this - // really be filled in with blocks. - $build['#content'][$region] = '

' . $info['label'] . '

'; + // Initialize regions which were not provided as empty. + $build['#content'][$region] = empty($regions[$region]) ? '' : $regions[$region]; } // Fill in attached CSS and JS files based on metadata. diff --git a/core/modules/layout/lib/Drupal/layout/Tests/LayoutDerivativesTest.php b/core/modules/layout/lib/Drupal/layout/Tests/LayoutDerivativesTest.php index 0766838..5b5b0eb 100644 --- a/core/modules/layout/lib/Drupal/layout/Tests/LayoutDerivativesTest.php +++ b/core/modules/layout/lib/Drupal/layout/Tests/LayoutDerivativesTest.php @@ -52,7 +52,7 @@ function testDerivatives() { // Render the layout and look at whether expected region names and classes // were in the output. - $render = $layout->renderLayout(); + $render = $this->renderLayoutDemonstration($layout); $this->drupalSetContent($render); $this->assertText('Middle column'); $this->assertRaw('class="layout-display layout-one-col'); @@ -68,7 +68,7 @@ function testDerivatives() { // Render the layout and look at whether expected region names and classes // were in the output. - $render = $layout->renderLayout(); + $render = $this->renderLayoutDemonstration($layout); $this->drupalSetContent($render); $this->assertText('Left side'); $this->assertText('Right side'); @@ -76,6 +76,19 @@ function testDerivatives() { } /** + * Render the layout with sample region content. + */ + function renderLayoutDemonstration($layout) { + // Add sample content in the regions that is looked for in the tests. + $regions = $layout->getRegions(); + foreach ($regions as $region => $info) { + $regions[$region] = '

' . $info['label'] . '

'; + } + + return $layout->renderLayout(FALSE, $regions); + } + + /** * Test layout functionality as applies to pages. */ function testPageLayout() { diff --git a/core/modules/layout/tests/layout_test.module b/core/modules/layout/tests/layout_test.module index b9eb63b..74de123 100644 --- a/core/modules/layout/tests/layout_test.module +++ b/core/modules/layout/tests/layout_test.module @@ -27,11 +27,19 @@ function layout_test_page() { global $theme; $theme = 'layout_test_theme'; theme_enable(array($theme)); + $display = entity_load('display', 'test_twocol'); $layout = $display->getLayoutInstance(); + // @todo This tests that the layout can render its regions, but does not test // block rendering: http://drupal.org/node/1812720. - return $layout->renderLayout(); + // Add sample content in the regions that is looked for in the tests. + $regions = $layout->getRegions(); + foreach ($regions as $region => $info) { + $regions[$region] = '

' . $info['label'] . '

'; + } + + return $layout->renderLayout(FALSE, $regions); } /**