diff --git a/core/modules/system/src/Block/SystemPageActionsBlock.php b/core/modules/system/src/Block/SystemPageActionsBlock.php new file mode 100644 index 0000000..b4fe8d5 --- /dev/null +++ b/core/modules/system/src/Block/SystemPageActionsBlock.php @@ -0,0 +1,140 @@ +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']; + if (empty($action_links)) { + return FALSE; + } + + $build['action_links'] = array( + '#markup' => $action_links, + ); + + return $build; + } + + /** + * {@inheritdoc} + */ + public function buildConfigurationForm(array $form, FormStateInterface $form_state) { + $form = parent::buildConfigurationForm($form, $form_state); + + // The "Page actions" block is never cacheable, due to access checking. + $form['cache']['#disabled'] = TRUE; + $form['cache']['#description'] = $this->t('This block is never cacheable because access checking is needed, it is not configurable.'); + $form['cache']['max_age']['#value'] = 0; + + return $form; + } + + /** + * {@inheritdoc} + */ + public function isCacheable() { + // The "Page Actions" block is never cacheable, because its contents depends + // on access checks, which are currently uncacheable. + // @todo Make cacheable once https://drupal.org/node/2287071 lands. + return FALSE; + } + +} diff --git a/core/modules/system/src/Block/SystemPageTabsBlock.php b/core/modules/system/src/Block/SystemPageTabsBlock.php new file mode 100644 index 0000000..11920da --- /dev/null +++ b/core/modules/system/src/Block/SystemPageTabsBlock.php @@ -0,0 +1,107 @@ +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() { + $tabs = menu_local_tabs(); + if (empty($tabs)) { + return FALSE; + } + $build['tabs']['#markup'] = menu_local_tabs(); + return $build; + } + + /** + * {@inheritdoc} + */ + public function buildConfigurationForm(array $form, FormStateInterface $form_state) { + $form = parent::buildConfigurationForm($form, $form_state); + + // The "Page tabs" block is never cacheable, due to access checking. + $form['cache']['#disabled'] = TRUE; + $form['cache']['#description'] = $this->t('This block is never cacheable because access checking is needed, it is not configurable.'); + $form['cache']['max_age']['#value'] = 0; + + return $form; + } + + /** + * {@inheritdoc} + */ + public function isCacheable() { + // The "Page Tabs" block is never cacheable, because its contents depends + // on access checks, which are currently uncacheable. + // @todo Make cacheable once https://drupal.org/node/2287071 lands. + return FALSE; + } + +} diff --git a/core/modules/system/src/Block/SystemPageTitleBlock.php b/core/modules/system/src/Block/SystemPageTitleBlock.php new file mode 100644 index 0000000..142dd63 --- /dev/null +++ b/core/modules/system/src/Block/SystemPageTitleBlock.php @@ -0,0 +1,139 @@ +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); + } + if (empty($title)) { + return FALSE; + } + + $build['title'] = array( + '#markup' => $title, + ); + + return $build; + } + + /** + * {@inheritdoc} + */ + public function buildConfigurationForm(array $form, FormStateInterface $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'] = 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 007595e..d72f562 100644 --- a/core/modules/system/system.module +++ b/core/modules/system/system.module @@ -162,6 +162,18 @@ function system_theme() { 'render element' => 'elements', 'base hook' => '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_menu_block' => array( 'render element' => 'elements', 'base hook' => 'block', @@ -777,7 +789,24 @@ function system_preprocess_block(&$variables) { $variables['site_slogan'] = $variables['content']['site_slogan']['#markup']; } 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-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-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..d95521a --- /dev/null +++ b/core/themes/bartik/templates/block--system-page-title-block.html.twig @@ -0,0 +1,23 @@ +{% 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 %} + {% if title %} +

+ {{ title }} +

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