diff --git a/core/includes/bootstrap.inc b/core/includes/bootstrap.inc
index cf0e3dd..af355f7 100644
--- a/core/includes/bootstrap.inc
+++ b/core/includes/bootstrap.inc
@@ -207,11 +207,6 @@
define('REQUEST_TIME', (int) $_SERVER['REQUEST_TIME']);
/**
- * Flag for drupal_set_title(); text is not sanitized, so run check_plain().
- */
-const CHECK_PLAIN = 0;
-
-/**
* Flag for drupal_set_title(); text has already been sanitized.
*/
const PASS_THROUGH = -1;
@@ -1727,7 +1722,7 @@ function drupal_get_title() {
* @return
* The updated title of the current page.
*/
-function drupal_set_title($title = NULL, $output = CHECK_PLAIN) {
+function drupal_set_title($title = NULL, $output = String::CHECK_PLAIN) {
$stored_title = &drupal_static(__FUNCTION__);
if (isset($title)) {
diff --git a/core/includes/common.inc b/core/includes/common.inc
index a392a5a..30631a0 100644
--- a/core/includes/common.inc
+++ b/core/includes/common.inc
@@ -4552,6 +4552,18 @@ function drupal_render_page($page) {
$page['content']['system_main'] = drupal_set_page_content();
}
+ // Set page title, if exist.
+ array_walk_recursive($page, function($value) {
+ if (isset($values['#page_title'])) {
+ // Check for title output flag.
+ if (!isset($value['#page_title_output']) || !in_array($value['#page_title_output'], array(String::CHECK_PLAIN, PASS_THROUGH))) {
+ $page['#page_title_output'] = STRING::CHECK_PLAIN;
+ }
+
+ drupal_set_title($value['#page_title'], $value['#page_title_output']);
+ }
+ });
+
return drupal_render($page);
}
diff --git a/core/lib/Drupal/Component/Utility/String.php b/core/lib/Drupal/Component/Utility/String.php
index 3cd6472..44d6915 100644
--- a/core/lib/Drupal/Component/Utility/String.php
+++ b/core/lib/Drupal/Component/Utility/String.php
@@ -13,6 +13,11 @@
class String {
/**
+ * Flag for drupal_set_title(); text is not sanitized, so run String::checkPlain().
+ */
+ const CHECK_PLAIN = 0;
+
+ /**
* Encodes special characters in a plain-text string for display as HTML.
*
* Also validates strings as UTF-8.
diff --git a/core/modules/system/lib/Drupal/system/Tests/System/PageTitleFilteringTest.php b/core/modules/system/lib/Drupal/system/Tests/System/PageTitleTest.php
similarity index 89%
rename from core/modules/system/lib/Drupal/system/Tests/System/PageTitleFilteringTest.php
rename to core/modules/system/lib/Drupal/system/Tests/System/PageTitleTest.php
index 9d96be8..3e698d4 100644
--- a/core/modules/system/lib/Drupal/system/Tests/System/PageTitleFilteringTest.php
+++ b/core/modules/system/lib/Drupal/system/Tests/System/PageTitleTest.php
@@ -7,17 +7,18 @@
namespace Drupal\system\Tests\System;
+use Drupal\Component\Utility\String;
use Drupal\Core\Language\Language;
use Drupal\simpletest\WebTestBase;
-class PageTitleFilteringTest extends WebTestBase {
+class PageTitleTest extends WebTestBase {
/**
* Modules to enable.
*
* @var array
*/
- public static $modules = array('node');
+ public static $modules = array('node', 'test_page_test');
protected $content_user;
protected $saved_title;
@@ -27,7 +28,7 @@ class PageTitleFilteringTest extends WebTestBase {
*/
public static function getInfo() {
return array(
- 'name' => 'HTML in page titles',
+ 'name' => 'Page titles',
'description' => 'Tests correct handling or conversion by drupal_set_title() and drupal_get_title() and checks the correct escaping of site name and slogan.',
'group' => 'System'
);
@@ -63,7 +64,7 @@ function testTitleTags() {
$title = "string with HTML";
// drupal_set_title's $filter is CHECK_PLAIN by default, so the title should be
// returned with check_plain().
- drupal_set_title($title, CHECK_PLAIN);
+ drupal_set_title($title, String::CHECK_PLAIN);
$this->assertTrue(strpos(drupal_get_title(), '') === FALSE, 'Tags in title converted to entities when $output is CHECK_PLAIN.');
// drupal_set_title's $filter is passed as PASS_THROUGH, so the title should be
// returned with HTML.
@@ -122,4 +123,15 @@ function testTitleXSS() {
$this->assertNoRaw($slogan, 'Check for the unfiltered version of the slogan.');
$this->assertRaw($slogan_filtered, 'Check for the filtered version of the slogan.');
}
+
+ /**
+ * Tests the page title of render arrays.
+ *
+ * @see \Drupal\test_page_test\Controller\Test::renderTitle()
+ */
+ public function testRenderTitle() {
+ $this->drupalGet('test-render-title');
+ $this->assertTitle(t('Foo'));
+ }
+
}
diff --git a/core/modules/system/tests/modules/test_page_test/lib/Drupal/test_page_test/Controller/Test.php b/core/modules/system/tests/modules/test_page_test/lib/Drupal/test_page_test/Controller/Test.php
new file mode 100644
index 0000000..2bf2d96
--- /dev/null
+++ b/core/modules/system/tests/modules/test_page_test/lib/Drupal/test_page_test/Controller/Test.php
@@ -0,0 +1,26 @@
+