drupal/core/modules/layout/layout.module

83 lines
2.0 KiB
Plaintext

<?php
/**
* @file
* Manages page layouts for content presentation.
*/
/**
* 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;
}
/**
* Access callback: Checks the existence of a layout.
*
* @param string $key
* The key of the page layout being requested.
*
* @return bool
* TRUE if the current user can access page layout menu items; FALSE
* otherwise.
*/
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
* The layout plugin manager instance.
*/
function layout_manager() {
return drupal_container()->get('plugin.manager.layout');
}
/**
* Implements hook_theme().
*
* Expose all layouts as theme items, so themes can override layout markup.
*/
function layout_theme($existing, $type, $theme, $path) {
$items = array();
foreach (layout_manager()->getDefinitions() as $name => $layout) {
$items[$layout['theme']] = array(
'variables' => array('content' => NULL),
'path' => $layout['path'],
'template' => $layout['template'],
);
}
return $items;
}