diff --git a/core/modules/system/src/Plugin/Block/SystemPageActionsBlock.php b/core/modules/system/src/Plugin/Block/SystemPageActionsBlock.php new file mode 100644 index 0000000..3c234a1 --- /dev/null +++ b/core/modules/system/src/Plugin/Block/SystemPageActionsBlock.php @@ -0,0 +1,134 @@ +configFactory = $config_factory; + $this->localActionManager = $local_action_manager; + $this->requestStack = $request_stack; + } + + /** + * {@inheritdoc} + */ + public static function create(ContainerInterface $container, array $configuration, $plugin_id, $plugin_definition) { + return new static( + $configuration, + $plugin_id, + $plugin_definition, + $container->get('config.factory'), + $container->get('plugin.manager.menu.local_action'), + $container->get('request_stack') + ); + } + + /** + * {@inheritdoc} + */ + public function defaultConfiguration() { + return array( + 'label_display' => FALSE, + ); + } + + /** + * {@inheritdoc} + */ + public function build() { + $build = array(); + $links = menu_local_tasks(); + $request = $this->requestStack->getCurrentRequest(); + $route_name = $request->attributes->get(RouteObjectInterface::ROUTE_NAME); + $action_links = $this->localActionManager->getActionsForRoute($route_name) + $links['actions']; + + $build['action_links'] = array( + '#markup' => $action_links, + ); + + return $build; + } + + /** + * {@inheritdoc} + */ + public function buildConfigurationForm(array $form, array &$form_state) { + $form = parent::buildConfigurationForm($form, $form_state); + + // The page actions block is never cacheable, because it may be dynamic. + $form['cache']['#disabled'] = TRUE; + $form['cache']['#description'] = $this->t('This block is never cacheable, it is not configurable.'); + $form['cache']['max_age']['#value'] = 0; + + return $form; + } + + /** + * {@inheritdoc} + */ + public function isCacheable() { + // The page actions block is never cacheable, because it may be dynamic. + return FALSE; + } + +} diff --git a/core/modules/system/src/Plugin/Block/SystemPageMessagesBlock.php b/core/modules/system/src/Plugin/Block/SystemPageMessagesBlock.php new file mode 100644 index 0000000..0122f8f --- /dev/null +++ b/core/modules/system/src/Plugin/Block/SystemPageMessagesBlock.php @@ -0,0 +1,106 @@ +configFactory = $config_factory; + } + + /** + * {@inheritdoc} + */ + public static function create(ContainerInterface $container, array $configuration, $plugin_id, $plugin_definition) { + return new static( + $configuration, + $plugin_id, + $plugin_definition, + $container->get('config.factory') + ); + } + + /** + * {@inheritdoc} + */ + public function defaultConfiguration() { + return array( + 'label_display' => FALSE, + ); + } + + /** + * {@inheritdoc} + */ + public function build() { + $build = array( + '#type' => 'status_messages', + 'pre_render' => array( + $this, 'preRender' + ) + ); + + return $build; + } + + /** + * {@inheritdoc} + */ + public function buildConfigurationForm(array $form, array &$form_state) { + $form = parent::buildConfigurationForm($form, $form_state); + + // The page messages block is never cacheable, because it may be dynamic. + $form['cache']['#disabled'] = TRUE; + $form['cache']['#description'] = $this->t('This block is never cacheable, it is not configurable.'); + $form['cache']['max_age']['#value'] = 0; + + return $form; + } + + /** + * {@inheritdoc} + */ + public function isCacheable() { + // The page messages block is never cacheable, because it may be dynamic. + return FALSE; + } + +} diff --git a/core/modules/system/src/Plugin/Block/SystemPageTabsBlock.php b/core/modules/system/src/Plugin/Block/SystemPageTabsBlock.php new file mode 100644 index 0000000..275d986 --- /dev/null +++ b/core/modules/system/src/Plugin/Block/SystemPageTabsBlock.php @@ -0,0 +1,106 @@ +configFactory = $config_factory; + } + + /** + * {@inheritdoc} + */ + public static function create(ContainerInterface $container, array $configuration, $plugin_id, $plugin_definition) { + return new static( + $configuration, + $plugin_id, + $plugin_definition, + $container->get('config.factory') + ); + } + + /** + * {@inheritdoc} + */ + public function defaultConfiguration() { + return array( + 'label_display' => FALSE, + ); + } + + /** + * {@inheritdoc} + */ + public function build() { + $build = array(); + $tabs = menu_local_tabs(); + + $build['tabs'] = array( + '#markup' => $tabs, + ); + + return $build; + } + + /** + * {@inheritdoc} + */ + public function buildConfigurationForm(array $form, array &$form_state) { + $form = parent::buildConfigurationForm($form, $form_state); + + // The page tabs block is never cacheable, because it may be dynamic. + $form['cache']['#disabled'] = TRUE; + $form['cache']['#description'] = $this->t('This block is never cacheable, it is not configurable.'); + $form['cache']['max_age']['#value'] = 0; + + return $form; + } + + /** + * {@inheritdoc} + */ + public function isCacheable() { + // The page tabs block is never cacheable, because it may be dynamic. + return FALSE; + } + +} diff --git a/core/modules/system/src/Plugin/Block/SystemPageTitleBlock.php b/core/modules/system/src/Plugin/Block/SystemPageTitleBlock.php new file mode 100644 index 0000000..a198c0c --- /dev/null +++ b/core/modules/system/src/Plugin/Block/SystemPageTitleBlock.php @@ -0,0 +1,135 @@ +configFactory = $config_factory; + $this->titleResolver = $title_resolver; + $this->requestStack = $request_stack; + } + + /** + * {@inheritdoc} + */ + public static function create(ContainerInterface $container, array $configuration, $plugin_id, $plugin_definition) { + return new static( + $configuration, + $plugin_id, + $plugin_definition, + $container->get('config.factory'), + $container->get('title_resolver'), + $container->get('request_stack') + ); + } + + /** + * {@inheritdoc} + */ + public function defaultConfiguration() { + return array( + 'label_display' => FALSE, + ); + } + + /** + * {@inheritdoc} + */ + public function build() { + $build = array(); + $title = ''; + $request = $this->requestStack->getCurrentRequest(); + if ($route = $request->attributes->get(routeObjectInterface::ROUTE_OBJECT)) { + $title = $this->titleResolver->getTitle($request, $route); + } + + $build['title'] = array( + '#markup' => $title, + ); + + return $build; + } + + /** + * {@inheritdoc} + */ + public function buildConfigurationForm(array $form, array &$form_state) { + $form = parent::buildConfigurationForm($form, $form_state); + + // The page title block is never cacheable, because it may be dynamic. + $form['cache']['#disabled'] = TRUE; + $form['cache']['#description'] = $this->t('This block is never cacheable, it is not configurable.'); + $form['cache']['max_age']['#value'] = 0; + + return $form; + } + + /** + * {@inheritdoc} + */ + public function isCacheable() { + // The page title block is never cacheable, because it may be dynamic. + return FALSE; + } + +} diff --git a/core/modules/system/system.module b/core/modules/system/system.module index ac44ab5..f703fd1 100644 --- a/core/modules/system/system.module +++ b/core/modules/system/system.module @@ -160,13 +160,28 @@ function system_help($route_name, Request $request) { function system_theme() { return array_merge(drupal_common_theme(), array( // Normally theme suggestion templates are only picked up when they are in - // themes. We explicitly define the block__system_branding_block theme - // suggestion here so that the template in core/modules/system/templates - // is picked up. + // themes. We explicitly define theme suggestions here so that the + // block templates in core/modules/system/templates are picked up. 'block__system_branding_block' => array( 'base hook' => 'block', 'template' => 'block--system-branding-block', ), + 'block__system_page_title_block' => array( + 'base hook' => 'block', + 'template' => 'block--system-page-title-block', + ), + 'block__system_page_actions_block' => array( + 'base hook' => 'block', + 'template' => 'block--system-page-actions-block', + ), + 'block__system_page_tabs_block' => array( + 'base hook' => 'block', + 'template' => 'block--system-page-tabs-block', + ), + 'block__system_page_messages_block' => array( + 'base hook' => 'block', + 'template' => 'block--system-page-messages-block', + ), 'system_themes_page' => array( 'variables' => array( 'theme_groups' => array(), @@ -1072,6 +1087,27 @@ function system_preprocess_block(&$variables) { } break; + case 'system_page_title_block': + $variables['title'] = ''; + if($variables['content']['title']['#markup']) { + $variables['title'] = $variables['content']['title']['#markup']; + } + break; + + case 'system_page_actions_block': + $variables['action_links'] = ''; + if($variables['content']['action_links']['#markup']) { + $variables['action_links'] = $variables['content']['action_links']['#markup']; + } + break; + + case 'system_page_tabs_block': + $variables['tabs'] = ''; + if($variables['content']['tabs']['#markup']) { + $variables['tabs'] = $variables['content']['tabs']['#markup']; + } + break; + case 'system_powered_by_block': $variables['attributes']['role'] = 'complementary'; break; diff --git a/core/modules/system/templates/block--system-page-actions-block.html.twig b/core/modules/system/templates/block--system-page-actions-block.html.twig new file mode 100644 index 0000000..a5972dc --- /dev/null +++ b/core/modules/system/templates/block--system-page-actions-block.html.twig @@ -0,0 +1,18 @@ +{% extends "@block/block.html.twig" %} +{# +/** + * @file + * Default theme implementation for page local actions. + * + * Available variables: + * - action_links: Actions local to the page, such as "Add menu" on the menu + * administration interface. + * + * @ingroup themeable + */ +#} +{% block content %} + {% if action_links %} + + {% endif %} +{% endblock %} diff --git a/core/modules/system/templates/block--system-page-messages-block.html.twig b/core/modules/system/templates/block--system-page-messages-block.html.twig new file mode 100644 index 0000000..0d33834 --- /dev/null +++ b/core/modules/system/templates/block--system-page-messages-block.html.twig @@ -0,0 +1,17 @@ +{% extends "@block/block.html.twig" %} +{# +/** + * @file + * Default theme implementation for page messages. + * + * Available variables: + * - messages: Status and error messages. Should be displayed prominently. + * + * @ingroup themeable + */ +#} +{% block content %} + {% if messages %} + {{ messages }} + {% endif %} +{% endblock %} diff --git a/core/modules/system/templates/block--system-page-tabs-block.html.twig b/core/modules/system/templates/block--system-page-tabs-block.html.twig new file mode 100644 index 0000000..780abe7 --- /dev/null +++ b/core/modules/system/templates/block--system-page-tabs-block.html.twig @@ -0,0 +1,16 @@ +{% extends "@block/block.html.twig" %} +{# +/** + * @file + * Default theme implementation for page tabs. + * + * Available variables: + * - tabs: The Tabs linking to any sub-pages beneath the current page (e.g., the + * view and edit tabs when displaying a node). + * + * @ingroup themeable + */ +#} +{% block content %} + {{ tabs }} +{% endblock %} diff --git a/core/modules/system/templates/block--system-page-title-block.html.twig b/core/modules/system/templates/block--system-page-title-block.html.twig new file mode 100644 index 0000000..aca427c --- /dev/null +++ b/core/modules/system/templates/block--system-page-title-block.html.twig @@ -0,0 +1,23 @@ +{% extends "@block/block.html.twig" %} +{# +/** + * @file + * Default theme implementation for a page title. + * + * Available variables: + * - title_prefix: Additional output populated by modules, intended to be + * displayed in front of the main title tag that appears in the template. + * - title: The page title, for use in the actual content. + * - title_suffix: Additional output populated by modules, intended to be + * displayed after the main title tag that appears in the template. + * + * @ingroup themeable + */ +#} +{% block content %} + {{ title_prefix }} + {% if title %} +

{{ title }}

+ {% endif %} + {{ title_suffix }} +{% endblock %} diff --git a/core/themes/bartik/templates/block--system-page-actions-block.html.twig b/core/themes/bartik/templates/block--system-page-actions-block.html.twig new file mode 100644 index 0000000..b8283b5 --- /dev/null +++ b/core/themes/bartik/templates/block--system-page-actions-block.html.twig @@ -0,0 +1,20 @@ +{% extends "@block/block.html.twig" %} +{# +/** + * @file + * Bartik's theme implementation for page local actions. + * + * Available variables: + * - action_links: Actions local to the page, such as "Add menu" on the menu + * administration interface. + * + * @ingroup themeable + */ +#} +{% block content %} + {% if action_links %} + + {% endif %} +{% endblock %} diff --git a/core/themes/bartik/templates/block--system-page-messages.html.twig b/core/themes/bartik/templates/block--system-page-messages.html.twig new file mode 100644 index 0000000..0daf784 --- /dev/null +++ b/core/themes/bartik/templates/block--system-page-messages.html.twig @@ -0,0 +1,19 @@ +{% extends "@block/block.html.twig" %} +{# +/** + * @file + * Bartik's theme implementation for page messages. + * + * Available variables: + * - messages: Status and error messages. Should be displayed prominently. + * + * @ingroup themeable + */ +#} +{% block content %} + {% if messages %} +
+ {{ messages }} +
+ {% endif %} +{% endblock %} \ No newline at end of file diff --git a/core/themes/bartik/templates/block--system-page-tabs-block.html.twig b/core/themes/bartik/templates/block--system-page-tabs-block.html.twig new file mode 100644 index 0000000..429ad98 --- /dev/null +++ b/core/themes/bartik/templates/block--system-page-tabs-block.html.twig @@ -0,0 +1,20 @@ +{% extends "@block/block.html.twig" %} +{# +/** + * @file + * Bartik's theme implementation for page tabs. + * + * Available variables: + * - tabs: The Tabs linking to any sub-pages beneath the current page (e.g., the + * view and edit tabs when displaying a node). + * + * @ingroup themeable + */ +#} +{% block content %} + {% if tabs %} + + {% endif %} +{% endblock %} diff --git a/core/themes/bartik/templates/block--system-page-title-block.html.twig b/core/themes/bartik/templates/block--system-page-title-block.html.twig new file mode 100644 index 0000000..4bd27f1 --- /dev/null +++ b/core/themes/bartik/templates/block--system-page-title-block.html.twig @@ -0,0 +1,25 @@ +{% extends "@block/block.html.twig" %} +{# +/** + * @file + * Bartik's theme implementation for a page title. + * + * Available variables: + * - title_prefix: Additional output populated by modules, intended to be + * displayed in front of the main title tag that appears in the template. + * - title: The page title, for use in the actual content. + * - title_suffix: Additional output populated by modules, intended to be + * displayed after the main title tag that appears in the template. + * + * @ingroup themeable + */ +#} +{% block content %} + {{ title_prefix }} + {% if title %} +

+ {{ title }} +

+ {% endif %} + {{ title_suffix }} +{% endblock %}