Commit 85145ba9 authored by catch's avatar catch

Issue #2350877 by dawehner, Wim Leers, hussainweb: Deprecate/rename...

Issue #2350877 by dawehner, Wim Leers, hussainweb: Deprecate/rename drupal_add_feed(), drupal_add_html_head(), drupal_add_html_head_link(), drupal_add_http_header(), and allow to be set declaratively in #attached.
parent 58b78c4b
...@@ -165,7 +165,7 @@ function _batch_progress_page() { ...@@ -165,7 +165,7 @@ function _batch_progress_page() {
'#message' => $message, '#message' => $message,
'#label' => $label, '#label' => $label,
'#attached' => array( '#attached' => array(
'drupal_add_html_head' => array( 'html_head' => array(
array( array(
array( array(
// Redirect through a 'Refresh' meta tag if JavaScript is disabled. // Redirect through a 'Refresh' meta tag if JavaScript is disabled.
......
...@@ -414,7 +414,7 @@ function drupal_page_get_cache(Request $request) { ...@@ -414,7 +414,7 @@ function drupal_page_get_cache(Request $request) {
* Use \Symfony\Component\HttpFoundation\Response->headers->set(). * Use \Symfony\Component\HttpFoundation\Response->headers->set().
* See https://drupal.org/node/2181523. * See https://drupal.org/node/2181523.
*/ */
function drupal_add_http_header($name, $value, $append = FALSE) { function _drupal_add_http_header($name, $value, $append = FALSE) {
// The headers as name/value pairs. // The headers as name/value pairs.
$headers = &drupal_static('drupal_http_headers', array()); $headers = &drupal_static('drupal_http_headers', array());
...@@ -481,8 +481,8 @@ function _drupal_set_preferred_header_name($name = NULL) { ...@@ -481,8 +481,8 @@ function _drupal_set_preferred_header_name($name = NULL) {
/** /**
* Sends the HTTP response headers that were previously set, adding defaults. * Sends the HTTP response headers that were previously set, adding defaults.
* *
* Headers are set in drupal_add_http_header(). Default headers are not set * Headers are set in _drupal_add_http_header(). Default headers are not set
* if they have been replaced or unset using drupal_add_http_header(). * if they have been replaced or unset using _drupal_add_http_header().
* *
* @param array $default_headers * @param array $default_headers
* (optional) An array of headers as name/value pairs. * (optional) An array of headers as name/value pairs.
...@@ -571,7 +571,7 @@ function drupal_page_header() { ...@@ -571,7 +571,7 @@ function drupal_page_header() {
* *
* The headers allow as much as possible in proxies and browsers without any * The headers allow as much as possible in proxies and browsers without any
* particular knowledge about the pages. Modules can override these headers * particular knowledge about the pages. Modules can override these headers
* using drupal_add_http_header(). * using _drupal_add_http_header().
* *
* If the request is conditional (using If-Modified-Since and If-None-Match), * If the request is conditional (using If-Modified-Since and If-None-Match),
* and the conditions match those currently in the cache, a 304 Not Modified * and the conditions match those currently in the cache, a 304 Not Modified
......
...@@ -144,49 +144,6 @@ ...@@ -144,49 +144,6 @@
*/ */
const LOCALE_PLURAL_DELIMITER = "\03"; const LOCALE_PLURAL_DELIMITER = "\03";
/**
* Adds content to a specified region.
*
* @param $region
* Page region the content is added to.
* @param $data
* Content to be added.
*/
function drupal_add_region_content($region = NULL, $data = NULL) {
static $content = array();
if (isset($region) && isset($data)) {
$content[$region][] = $data;
}
return $content;
}
/**
* Gets assigned content for a given region.
*
* @param $region
* A specified region to fetch content for. If NULL, all regions will be
* returned.
* @param $delimiter
* Content to be inserted between imploded array elements.
*/
function drupal_get_region_content($region = NULL, $delimiter = ' ') {
$content = drupal_add_region_content();
if (isset($region)) {
if (isset($content[$region]) && is_array($content[$region])) {
return implode($delimiter, $content[$region]);
}
}
else {
foreach (array_keys($content) as $region) {
if (is_array($content[$region])) {
$content[$region] = implode($delimiter, $content[$region]);
}
}
return $content;
}
}
/** /**
* Gets the name of the currently active installation profile. * Gets the name of the currently active installation profile.
* *
...@@ -237,8 +194,11 @@ function drupal_get_profile() { ...@@ -237,8 +194,11 @@ function drupal_get_profile() {
* An array of all stored HEAD elements. * An array of all stored HEAD elements.
* *
* @see \Drupal\Core\Render\Element\HtmlTag::preRenderHtmlTag() * @see \Drupal\Core\Render\Element\HtmlTag::preRenderHtmlTag()
*
* @deprecated in Drupal 8.0.x, will be removed before Drupal 8.0.0
* Use #attached on render arrays.
*/ */
function drupal_add_html_head($data = NULL, $key = NULL) { function _drupal_add_html_head($data = NULL, $key = NULL) {
$stored_head = &drupal_static(__FUNCTION__, array()); $stored_head = &drupal_static(__FUNCTION__, array());
if (isset($data) && isset($key)) { if (isset($data) && isset($key)) {
...@@ -258,9 +218,12 @@ function drupal_add_html_head($data = NULL, $key = NULL) { ...@@ -258,9 +218,12 @@ function drupal_add_html_head($data = NULL, $key = NULL) {
* *
* @return string|array * @return string|array
* Return the rendered HTML head or the elements itself. * Return the rendered HTML head or the elements itself.
*
* @deprecated in Drupal 8.0.x, will be removed before Drupal 8.0.0
* Use #attached on render arrays.
*/ */
function drupal_get_html_head($render = TRUE) { function drupal_get_html_head($render = TRUE) {
$elements = drupal_add_html_head(); $elements = _drupal_add_html_head();
\Drupal::moduleHandler()->alter('html_head', $elements); \Drupal::moduleHandler()->alter('html_head', $elements);
if ($render) { if ($render) {
return drupal_render($elements); return drupal_render($elements);
...@@ -279,8 +242,11 @@ function drupal_get_html_head($render = TRUE) { ...@@ -279,8 +242,11 @@ function drupal_get_html_head($render = TRUE) {
* An internal system path or a fully qualified external URL of the feed. * An internal system path or a fully qualified external URL of the feed.
* @param $title * @param $title
* The title of the feed. * The title of the feed.
*
* @deprecated in Drupal 8.0.x, will be removed before Drupal 8.0.0
* Use #attached on render arrays.
*/ */
function drupal_add_feed($url = NULL, $title = '') { function _drupal_add_feed($url = NULL, $title = '') {
$stored_feed_links = &drupal_static(__FUNCTION__, array()); $stored_feed_links = &drupal_static(__FUNCTION__, array());
if (isset($url)) { if (isset($url)) {
...@@ -291,9 +257,12 @@ function drupal_add_feed($url = NULL, $title = '') { ...@@ -291,9 +257,12 @@ function drupal_add_feed($url = NULL, $title = '') {
/** /**
* Gets the feed URLs for the current page. * Gets the feed URLs for the current page.
*
* @deprecated in Drupal 8.0.x, will be removed before Drupal 8.0.0
* Use #attached on render arrays.
*/ */
function drupal_get_feeds() { function drupal_get_feeds() {
$feeds = drupal_add_feed(); $feeds = _drupal_add_feed();
return $feeds; return $feeds;
} }
...@@ -906,8 +875,11 @@ function base_path() { ...@@ -906,8 +875,11 @@ function base_path() {
* Associative array of element attributes including 'href' and 'rel'. * Associative array of element attributes including 'href' and 'rel'.
* @param $header * @param $header
* Optional flag to determine if a HTTP 'Link:' header should be sent. * Optional flag to determine if a HTTP 'Link:' header should be sent.
*
* @deprecated in Drupal 8.0.x, will be removed before Drupal 8.0.0
* Use #attached on render arrays.
*/ */
function drupal_add_html_head_link($attributes, $header = FALSE) { function _drupal_add_html_head_link($attributes, $header = FALSE) {
$element = array( $element = array(
'#tag' => 'link', '#tag' => 'link',
'#attributes' => $attributes, '#attributes' => $attributes,
...@@ -918,10 +890,10 @@ function drupal_add_html_head_link($attributes, $header = FALSE) { ...@@ -918,10 +890,10 @@ function drupal_add_html_head_link($attributes, $header = FALSE) {
// Also add a HTTP header "Link:". // Also add a HTTP header "Link:".
$href = '<' . String::checkPlain($attributes['href']) . '>;'; $href = '<' . String::checkPlain($attributes['href']) . '>;';
unset($attributes['href']); unset($attributes['href']);
$element['#attached']['drupal_add_http_header'][] = array('Link', $href . drupal_http_header_attributes($attributes), TRUE); $element['#attached']['http_header'][] = array('Link', $href . drupal_http_header_attributes($attributes), TRUE);
} }
drupal_add_html_head($element, 'drupal_add_html_head_link:' . $attributes['rel'] . ':' . $href); _drupal_add_html_head($element, 'html_head_link:' . $attributes['rel'] . ':' . $href);
} }
/** /**
...@@ -1816,7 +1788,7 @@ function drupal_merge_attached(array $a, array $b) { ...@@ -1816,7 +1788,7 @@ function drupal_merge_attached(array $a, array $b) {
* other kind of attached data, the array key must be the full name of the * other kind of attached data, the array key must be the full name of the
* callback function and each value an array of arguments. For example: * callback function and each value an array of arguments. For example:
* @code * @code
* $build['#attached']['drupal_add_http_header'] = array( * $build['#attached']['http_header'] = array(
* array('Content-Type', 'application/rss+xml; charset=utf-8'), * array('Content-Type', 'application/rss+xml; charset=utf-8'),
* ); * );
* @endcode * @endcode
...@@ -1894,7 +1866,23 @@ function drupal_process_attached($elements, $dependency_check = FALSE) { ...@@ -1894,7 +1866,23 @@ function drupal_process_attached($elements, $dependency_check = FALSE) {
// special handling. // special handling.
foreach ($elements['#attached'] as $callback => $options) { foreach ($elements['#attached'] as $callback => $options) {
foreach ($elements['#attached'][$callback] as $args) { foreach ($elements['#attached'][$callback] as $args) {
call_user_func_array($callback, $args); // Limit the amount allowed entries.
switch ($callback) {
case 'html_head':
call_user_func_array('_drupal_add_html_head', $args);
break;
case 'feed':
call_user_func_array('_drupal_add_feed', $args);
break;
case 'html_head_link':
call_user_func_array('_drupal_add_html_head_link', $args);
break;
case 'http_header':
call_user_func_array('_drupal_add_http_header', $args);
break;
default:
throw new \LogicException(sprintf('You are not allowed to use %s in #attached', $callback));
}
} }
} }
...@@ -2055,6 +2043,9 @@ function drupal_process_states(&$elements) { ...@@ -2055,6 +2043,9 @@ function drupal_process_states(&$elements) {
* *
* @see \Drupal\Core\Asset\LibraryDiscovery * @see \Drupal\Core\Asset\LibraryDiscovery
* @see hook_library_info_alter() * @see hook_library_info_alter()
*
* @deprecated in Drupal 8.0.x, will be removed before Drupal 8.0.0
* Use #attached on render arrays.
*/ */
function _drupal_add_library($library_name, $every_page = NULL) { function _drupal_add_library($library_name, $every_page = NULL) {
$added = &drupal_static(__FUNCTION__, array()); $added = &drupal_static(__FUNCTION__, array());
......
...@@ -902,7 +902,7 @@ function install_display_output($output, $install_state) { ...@@ -902,7 +902,7 @@ function install_display_output($output, $install_state) {
'content' => 'noindex, nofollow', 'content' => 'noindex, nofollow',
), ),
); );
drupal_add_html_head($noindex_meta_tag, 'install_meta_robots'); $output['#attached']['html_head'][] = [$noindex_meta_tag, 'install_meta_robots'];
// Only show the task list if there is an active task; otherwise, the page // Only show the task list if there is an active task; otherwise, the page
// request has ended before tasks have even been started, so there is nothing // request has ended before tasks have even been started, so there is nothing
......
...@@ -98,7 +98,7 @@ public function onRespond(FilterResponseEvent $event) { ...@@ -98,7 +98,7 @@ public function onRespond(FilterResponseEvent $event) {
// Attach globally-declared headers to the response object so that Symfony // Attach globally-declared headers to the response object so that Symfony
// can send them for us correctly. // can send them for us correctly.
// @todo remove this once we have removed all drupal_add_http_header() // @todo remove this once we have removed all _drupal_add_http_header()
// calls. // calls.
$headers = drupal_get_http_header(); $headers = drupal_get_http_header();
foreach ($headers as $name => $value) { foreach ($headers as $name => $value) {
......
...@@ -52,23 +52,23 @@ public function render(array $render_array) { ...@@ -52,23 +52,23 @@ public function render(array $render_array) {
$attached = isset($render_array['#attached']) ? $render_array['#attached'] : []; $attached = isset($render_array['#attached']) ? $render_array['#attached'] : [];
$attached += [ $attached += [
'drupal_add_feed' => [], 'feed' => [],
'drupal_add_html_head' => [], 'html_head' => [],
'drupal_add_html_head_link' => [], 'html_head_link' => [],
]; ];
// Add feed links from the page content. // Add feed links from the page content.
foreach ($attached['drupal_add_feed'] as $feed) { foreach ($attached['feed'] as $feed) {
$fragment->addLinkElement(new FeedLinkElement($feed[1], $this->urlGenerator->generateFromPath($feed[0]))); $fragment->addLinkElement(new FeedLinkElement($feed[1], $this->urlGenerator->generateFromPath($feed[0])));
} }
// Add generic links from the page content. // Add generic links from the page content.
foreach ($attached['drupal_add_html_head_link'] as $link) { foreach ($attached['html_head_link'] as $link) {
$fragment->addLinkElement(new LinkElement($this->urlGenerator->generateFromPath($link[0]['href']), $link[0]['rel'])); $fragment->addLinkElement(new LinkElement($this->urlGenerator->generateFromPath($link[0]['href']), $link[0]['rel']));
} }
// @todo Also transfer the contents of "drupal_add_html_head" once // @todo Also transfer the contents of "_drupal_add_html_head" once
// https://www.drupal.org/node/2296951 lands. // https://www.drupal.org/node/2296951 lands.
// @todo Transfer CSS and JS over to the fragment once those are supported // @todo Transfer CSS and JS over to the fragment once those are supported
......
...@@ -173,7 +173,7 @@ public function adminOverview() { ...@@ -173,7 +173,7 @@ public function adminOverview() {
public function pageLast() { public function pageLast() {
$items = $this->entityManager()->getStorage('aggregator_item')->loadAll(20); $items = $this->entityManager()->getStorage('aggregator_item')->loadAll(20);
$build = $this->buildPageList($items); $build = $this->buildPageList($items);
$build['#attached']['drupal_add_feed'][] = array('aggregator/rss', $this->config('system.site')->get('name') . ' ' . $this->t('aggregator')); $build['#attached']['feed'][] = array('aggregator/rss', $this->config('system.site')->get('name') . ' ' . $this->t('aggregator'));
return $build; return $build;
} }
......
...@@ -405,7 +405,7 @@ function template_preprocess_book_navigation(&$variables) { ...@@ -405,7 +405,7 @@ function template_preprocess_book_navigation(&$variables) {
if ($prev = $book_outline->prevLink($book_link)) { if ($prev = $book_outline->prevLink($book_link)) {
$prev_href = \Drupal::url('entity.node.canonical', array('node' => $prev['nid'])); $prev_href = \Drupal::url('entity.node.canonical', array('node' => $prev['nid']));
$build['#attached']['drupal_add_html_head_link'][][] = array( $build['#attached']['html_head_link'][][] = array(
'rel' => 'prev', 'rel' => 'prev',
'href' => $prev_href, 'href' => $prev_href,
); );
...@@ -417,7 +417,7 @@ function template_preprocess_book_navigation(&$variables) { ...@@ -417,7 +417,7 @@ function template_preprocess_book_navigation(&$variables) {
$book_manager = \Drupal::service('book.manager'); $book_manager = \Drupal::service('book.manager');
if ($book_link['pid'] && $parent = $book_manager->loadBookLink($book_link['pid'])) { if ($book_link['pid'] && $parent = $book_manager->loadBookLink($book_link['pid'])) {
$parent_href = \Drupal::url('entity.node.canonical', array('node' => $book_link['pid'])); $parent_href = \Drupal::url('entity.node.canonical', array('node' => $book_link['pid']));
$build['#attached']['drupal_add_html_head_link'][][] = array( $build['#attached']['html_head_link'][][] = array(
'rel' => 'up', 'rel' => 'up',
'href' => $parent_href, 'href' => $parent_href,
); );
...@@ -427,7 +427,7 @@ function template_preprocess_book_navigation(&$variables) { ...@@ -427,7 +427,7 @@ function template_preprocess_book_navigation(&$variables) {
if ($next = $book_outline->nextLink($book_link)) { if ($next = $book_outline->nextLink($book_link)) {
$next_href = \Drupal::url('entity.node.canonical', array('node' => $next['nid'])); $next_href = \Drupal::url('entity.node.canonical', array('node' => $next['nid']));
$build['#attached']['drupal_add_html_head_link'][][] = array( $build['#attached']['html_head_link'][][] = array(
'rel' => 'next', 'rel' => 'next',
'href' => $next_href, 'href' => $next_href,
); );
......
...@@ -746,7 +746,7 @@ function content_translation_page_alter(&$page) { ...@@ -746,7 +746,7 @@ function content_translation_page_alter(&$page) {
->setOption('language', $language) ->setOption('language', $language)
->setAbsolute() ->setAbsolute()
->toString(); ->toString();
$page['#attached']['drupal_add_html_head_link'][] = array( $page['#attached']['html_head_link'][] = array(
array( array(
'rel' => 'alternate', 'rel' => 'alternate',
'hreflang' => $language->id, 'hreflang' => $language->id,
......
...@@ -145,7 +145,7 @@ protected function build($forums, TermInterface $term, $topics = array(), $paren ...@@ -145,7 +145,7 @@ protected function build($forums, TermInterface $term, $topics = array(), $paren
); );
$build['#attached']['library'][] = 'forum/forum.index'; $build['#attached']['library'][] = 'forum/forum.index';
if (empty($term->forum_container->value)) { if (empty($term->forum_container->value)) {
$build['#attached']['drupal_add_feed'][] = array('taxonomy/term/' . $term->id() . '/feed', 'RSS - ' . $term->getName()); $build['#attached']['feed'][] = array('taxonomy/term/' . $term->id() . '/feed', 'RSS - ' . $term->getName());
} }
return $build; return $build;
......
...@@ -33,7 +33,7 @@ public function view(EntityInterface $node_preview, $view_mode_id = 'full', $lan ...@@ -33,7 +33,7 @@ public function view(EntityInterface $node_preview, $view_mode_id = 'full', $lan
foreach ($node_preview->uriRelationships() as $rel) { foreach ($node_preview->uriRelationships() as $rel) {
// Set the node path as the canonical URL to prevent duplicate content. // Set the node path as the canonical URL to prevent duplicate content.
$build['#attached']['drupal_add_html_head_link'][] = array( $build['#attached']['html_head_link'][] = array(
array( array(
'rel' => $rel, 'rel' => $rel,
'href' => $node_preview->url($rel), 'href' => $node_preview->url($rel),
...@@ -42,7 +42,7 @@ public function view(EntityInterface $node_preview, $view_mode_id = 'full', $lan ...@@ -42,7 +42,7 @@ public function view(EntityInterface $node_preview, $view_mode_id = 'full', $lan
if ($rel == 'canonical') { if ($rel == 'canonical') {
// Set the non-aliased canonical path as a default shortlink. // Set the non-aliased canonical path as a default shortlink.
$build['#attached']['drupal_add_html_head_link'][] = array( $build['#attached']['html_head_link'][] = array(
array( array(
'rel' => 'shortlink', 'rel' => 'shortlink',
'href' => $node_preview->url($rel, array('alias' => TRUE)), 'href' => $node_preview->url($rel, array('alias' => TRUE)),
......
...@@ -27,7 +27,7 @@ public function view(EntityInterface $node, $view_mode = 'full', $langcode = NUL ...@@ -27,7 +27,7 @@ public function view(EntityInterface $node, $view_mode = 'full', $langcode = NUL
foreach ($node->uriRelationships() as $rel) { foreach ($node->uriRelationships() as $rel) {
// Set the node path as the canonical URL to prevent duplicate content. // Set the node path as the canonical URL to prevent duplicate content.
$build['#attached']['drupal_add_html_head_link'][] = array( $build['#attached']['html_head_link'][] = array(
array( array(
'rel' => $rel, 'rel' => $rel,
'href' => $node->url($rel), 'href' => $node->url($rel),
...@@ -37,7 +37,7 @@ public function view(EntityInterface $node, $view_mode = 'full', $langcode = NUL ...@@ -37,7 +37,7 @@ public function view(EntityInterface $node, $view_mode = 'full', $langcode = NUL
if ($rel == 'canonical') { if ($rel == 'canonical') {
// Set the non-aliased canonical path as a default shortlink. // Set the non-aliased canonical path as a default shortlink.
$build['#attached']['drupal_add_html_head_link'][] = array( $build['#attached']['html_head_link'][] = array(
array( array(
'rel' => 'shortlink', 'rel' => 'shortlink',
'href' => $node->url($rel, array('alias' => TRUE)), 'href' => $node->url($rel, array('alias' => TRUE)),
......
...@@ -366,7 +366,7 @@ function rdf_preprocess_user(&$variables) { ...@@ -366,7 +366,7 @@ function rdf_preprocess_user(&$variables) {
'lang' => '', 'lang' => '',
), ),
); );
drupal_add_html_head($username_meta, 'rdf_user_username'); $variables['#attached']['html_head'][] = [$username_meta, 'rdf_user_username'];
} }
} }
} }
......
...@@ -12,13 +12,13 @@ ...@@ -12,13 +12,13 @@
use Drupal\simpletest\WebTestBase; use Drupal\simpletest\WebTestBase;
/** /**
* Make sure that drupal_add_feed() works correctly with various constructs. * Make sure that _drupal_add_feed() works correctly with various constructs.
* *
* @group Common * @group Common
*/ */
class AddFeedTest extends WebTestBase { class AddFeedTest extends WebTestBase {
/** /**
* Tests drupal_add_feed() with paths, URLs, and titles. * Tests _drupal_add_feed() with paths, URLs, and titles.
*/ */
function testBasicFeedAddNoTitle() { function testBasicFeedAddNoTitle() {
$path = $this->randomMachineName(12); $path = $this->randomMachineName(12);
...@@ -29,10 +29,10 @@ function testBasicFeedAddNoTitle() { ...@@ -29,10 +29,10 @@ function testBasicFeedAddNoTitle() {
$external_for_title = 'http://' . $this->randomMachineName(12) . '/' . $this->randomMachineName(12); $external_for_title = 'http://' . $this->randomMachineName(12) . '/' . $this->randomMachineName(12);
$fully_qualified_for_title = _url($this->randomMachineName(12), array('absolute' => TRUE)); $fully_qualified_for_title = _url($this->randomMachineName(12), array('absolute' => TRUE));
// Possible permutations of drupal_add_feed() to test. // Possible permutations of _drupal_add_feed() to test.
// - 'input_url': the path passed to drupal_add_feed(), // - 'input_url': the path passed to _drupal_add_feed(),
// - 'output_url': the expected URL to be found in the header. // - 'output_url': the expected URL to be found in the header.
// - 'title' == the title of the feed as passed into drupal_add_feed(). // - 'title' == the title of the feed as passed into _drupal_add_feed().
$urls = array( $urls = array(
'path without title' => array( 'path without title' => array(
'url' => _url($path, array('absolute' => TRUE)), 'url' => _url($path, array('absolute' => TRUE)),
......
<?php
/**
* @file
* Definition of Drupal\system\Tests\Common\RegionContentTest.
*/
namespace Drupal\system\Tests\Common;
use Drupal\simpletest\WebTestBase;
/**
* Tests setting and retrieving content from theme regions.
*
* @group Common
*/
class RegionContentTest extends WebTestBase {
/**
* Tests setting and retrieving content for theme regions.
*/
function testRegions() {
$theme_key = \Drupal::theme()->getActiveTheme()->getName();
$block_regions = array_keys(system_region_list($theme_key));
$delimiter = $this->randomMachineName(32);
$values = array();
// Set some random content for each region available.
foreach ($block_regions as $region) {
$first_chunk = $this->randomMachineName(32);
drupal_add_region_content($region, $first_chunk);
$second_chunk = $this->randomMachineName(32);
drupal_add_region_content($region, $second_chunk);
// Store the expected result for a drupal_get_region_content call for this region.
$values[$region] = $first_chunk . $delimiter . $second_chunk;
}
// Ensure drupal_get_region_content returns expected results when fetching all regions.
$content = drupal_get_region_content(NULL, $delimiter);
foreach ($content as $region => $region_content) {
$this->assertEqual($region_content, $values[$region], format_string('@region region text verified when fetching all regions', array('@region' => $region)));
}
// Ensure drupal_get_region_content returns expected results when fetching a single region.
foreach ($block_regions as $region) {
$region_content = drupal_get_region_content($region, $delimiter);
$this->assertEqual($region_content, $values[$region], format_string('@region region text verified when fetching single region.', array('@region' => $region)));
}
}
}
...@@ -1181,4 +1181,20 @@ protected function randomContextValue() { ...@@ -1181,4 +1181,20 @@ protected function randomContextValue() {
return $tokens[mt_rand(0, 4)]; return $tokens[mt_rand(0, 4)];
} }
/**
* Tests drupal_process_attached().
*/
public function testDrupalProcessAttached() {
// Specify invalid attachments in a render array.
$build['#attached']['library'][] = 'core/drupal.states';
$build['#attached']['drupal_process_states'][] = [];
try {
drupal_process_attached($build);
$this->fail("Invalid #attachment 'drupal_process_states' allowed");
}
catch (\Exception $e) {
$this->pass("Invalid #attachment 'drupal_process_states' not allowed");
}
}
} }
...@@ -110,7 +110,7 @@ function taxonomy_page_build(&$page) { ...@@ -110,7 +110,7 @@ function taxonomy_page_build(&$page) {
if ($route_match->getRouteName() == 'entity.taxonomy_term.canonical' && ($term = $route_match->getParameter('taxonomy_term')) && $term instanceof TermInterface) { if ($route_match->getRouteName() == 'entity.taxonomy_term.canonical' && ($term = $route_match->getParameter('taxonomy_term')) && $term instanceof TermInterface) {
foreach ($term->uriRelationships() as $rel) { foreach ($term->uriRelationships() as $rel) {
// Set the URI relationships, like canonical. // Set the URI relationships, like canonical.
$page['#attached']['drupal_add_html_head_link'][] = array( $page['#attached']['html_head_link'][] = array(
array( array(
'rel' => $rel, 'rel' => $rel,
'href' => $term->url($rel), 'href' => $term->url($rel),
...@@ -121,7 +121,7 @@ function taxonomy_page_build(&$page) { ...@@ -121,7 +121,7 @@ function taxonomy_page_build(&$page) {
// Set the term path as the canonical URL to prevent duplicate content. // Set the term path as the canonical URL to prevent duplicate content.
if ($rel == 'canonical') { if ($rel == 'canonical') {
// Set the non-aliased canonical path as a default shortlink. // Set the non-aliased canonical path as a default shortlink.
$page['#attached']['drupal_add_html_head_link'][] = array( $page['#attached']['html_head_link'][] = array(
array( array(
'rel' => 'shortlink', 'rel' => 'shortlink',
'href' => $term->url($rel, array('alias' => TRUE)), 'href' => $term->url($rel, array('alias' => TRUE)),
......
...@@ -231,10 +231,10 @@ public function postRender(&$output) { } ...@@ -231,10 +231,10 @@ public function postRender(&$output) { }
* duplicate it. Later on, when gatherHeaders() is run, this information * duplicate it. Later on, when gatherHeaders() is run, this information
* will be removed so that we don't hold onto it. * will be removed so that we don't hold onto it.
* *
* @see drupal_add_html_head() * @see _drupal_add_html_head()
*/ */
public function cacheStart() { public function cacheStart() {
$this->storage['head'] = drupal_add_html_head(); $this->storage['head'] = _drupal_add_html_head();
} }
/** /**
...@@ -246,7 +246,7 @@ public function cacheStart() { ...@@ -246,7 +246,7 @@ public function cacheStart() {
protected function gatherHeaders(array $render_array = []) { protected function gatherHeaders(array $render_array = []) {
// Simple replacement for head // Simple replacement for head
if (isset($this->storage['head'])) { if (isset($this->storage['head'])) {
$this->storage['head'] = str_replace($this->storage['head'], '', drupal_add_html_head()); $this->storage['head'] = str_replace($this->storage['head'], '', _drupal_add_html_head());
} }
else { else {
$this->storage['head'] = ''; $this->storage['head'] = '';
...@@ -261,7 +261,7 @@ protected function gatherHeaders(array $render_array = []) { ...@@ -261,7 +261,7 @@ protected function gatherHeaders(array $render_array = []) {
*/ */
public function restoreHeaders() { public function restoreHeaders() {
if (!empty($this->storage['head'])) { if (!empty($this->storage['head'])) {
drupal_add_html_head($this->storage['head']); _drupal_add_html_head($this->storage['head']);
} }
if (!empty($this->storage['css'])) { if (!empty($this->storage['css'])) {
foreach ($this->storage['css'] as $args) {