Updated: Comment 0
Problem/Motivation
- // Construct page title
- if (drupal_get_title()) {
+ // Construct the page title.
+ if (isset($variables['page']['#title'])) {
+ $head_title = array(
+ 'title' => strip_tags($variables['page']['#title']),
+ 'name' => String::checkPlain($site_config->get('name')),
+ );
+ }
+ elseif (drupal_get_title()) {
$head_title = array(
'title' => strip_tags(drupal_get_title()),
- 'name' => check_plain($site_name),
+ 'name' => String::checkPlain($site_config->get('name')),
);
}
else {
@@ -2889,7 +2903,6 @@ function template_preprocess_maintenance_page(&$variables) {
$variables['site_name'] = (theme_get_setting('features.name') ? check_plain($site_name) : '');
$variables['site_slogan'] = (theme_get_setting('features.slogan') ? filter_xss_admin($site_slogan) : '');
$variables['tabs'] = '';
- $variables['title'] = drupal_get_title();
// Compile a list of classes that are going to be applied to the body element.
$variables['attributes']['class'][] = 'maintenance-page';
@@ -2925,6 +2938,14 @@ function template_preprocess_maintenance_page(&$variables) {
// be called when printed.
$variables['styles'] = new RenderWrapper('drupal_get_css', array($css));
$variables['scripts'] = new RenderWrapper('drupal_get_js');
+
+ // Allow the page to define a title.
+ if (isset($variables['page']['#title'])) {
+ $variables['title'] = $variables['page']['#title'];
+ }
+ if (!isset($variables['title'])) {
+ $variables['title'] = drupal_get_title();
+ }
Why was this added to template_preprocess_maintenance_page()?
$variables['page'] can't exist there at all AFAICS. hook_theme() only allows 'content' for maintenance pages. system_region_list($GLOBALS['theme']) for core provides the following regions:
Stark:
- sidebar_first
- sidebar_second
- content
- header
- footer
- highlighted
- help
- page_top
- page_bottom
Seven:
- content
- help
- page_top
- page_bottom
- sidebar_first
Bartik:
- header
- help
- page_top
- page_bottom
- highlighted
- featured
- content
- sidebar_first
- sidebar_second
- triptych_first
- triptych_middle
- triptych_last
- footer_firstcolumn
- footer_secondcolumn
- footer_thirdcolumn
- footer_fourthcolumn
- footer
Proposed resolution
The #title for template_proprocess_maintenance_page() should be checked in 'content' not 'page'.
Comments
Comment #1
dawehnerValid question, but is the drupal_get_title() function call valid on there?
Comment #2
thedavidmeister CreditAttribution: thedavidmeister commentedwell, maintenance pages as render arrays that could have '#title' is still early days #2072647: #theme 'maintenance_page' should support render arrays in #content
Comment #3
dawehnerAs talked we should just use the render array issue. #2072647: #theme 'maintenance_page' should support render arrays in #content
Comment #4
thedavidmeister CreditAttribution: thedavidmeister commentedah yes, but since then I realised that the other issue doesn't actually use drupal_set_title(), only drupal_get_title(), so it won't make as much sense to do this fix over there as it doesn't actually touch the titles directly. The other issue does block fixing this though.
Comment #5
thedavidmeister CreditAttribution: thedavidmeister commentedThis is blocked by #2072647: #theme 'maintenance_page' should support render arrays in #content because without that, there's no renderable array you could attack #title to.
Comment #6
thedavidmeister CreditAttribution: thedavidmeister commentedupdating title
Comment #6.0
thedavidmeister CreditAttribution: thedavidmeister commentedcode
Comment #6.1
thedavidmeister CreditAttribution: thedavidmeister commentedUpdated issue summary.
Comment #7
thedavidmeister CreditAttribution: thedavidmeister commentedshould no longer be blocked
Comment #8
lauriiiI think this is about documentation that is missing the page variable
Comment #15
andypostComment #21
larowlanThe code now does this
Where
['page']['#title']
comes from'#type' => 'page'
which is defined in\Drupal\Core\Render\Element\Page::getInfo
. The 'page' variable comes from'#theme' => 'page'
which is returned from the render element, where 'page' is the name of the render element for '#theme' => 'page'.So this now works as designed.