Update to drupal 8.0.0-rc1. For more information, see https://www.drupal.org/node/2582663
This commit is contained in:
parent
eb34d130a8
commit
f32e58e4b1
8476 changed files with 211648 additions and 170042 deletions
|
@ -22,9 +22,10 @@ use Drupal\Component\Utility\UrlHelper;
|
|||
use Drupal\Core\Asset\AttachedAssets;
|
||||
use Drupal\Core\Cache\Cache;
|
||||
use Drupal\Core\Language\LanguageInterface;
|
||||
use Drupal\Core\Render\SafeString;
|
||||
use Drupal\Core\Render\Markup;
|
||||
use Drupal\Core\Render\Renderer;
|
||||
use Drupal\Core\Site\Settings;
|
||||
use Drupal\Core\StringTranslation\TranslatableMarkup;
|
||||
use Drupal\Core\Url;
|
||||
use Symfony\Component\HttpFoundation\Response;
|
||||
use Symfony\Component\HttpFoundation\Request;
|
||||
|
@ -32,6 +33,7 @@ use Drupal\Core\PhpStorage\PhpStorageFactory;
|
|||
use Drupal\Component\Utility\NestedArray;
|
||||
use Drupal\Core\Datetime\DrupalDateTime;
|
||||
use Drupal\Core\Routing\GeneratorNotInitializedException;
|
||||
use Drupal\Core\StringTranslation\PluralTranslatableMarkup;
|
||||
use Drupal\Core\Template\Attribute;
|
||||
use Drupal\Core\Render\BubbleableMetadata;
|
||||
use Drupal\Core\Render\Element;
|
||||
|
@ -141,67 +143,11 @@ const JS_THEME = 100;
|
|||
/**
|
||||
* The delimiter used to split plural strings.
|
||||
*
|
||||
* This is the ETX (End of text) character and is used as a minimal means to
|
||||
* separate singular and plural variants in source and translation text. It
|
||||
* was found to be the most compatible delimiter for the supported databases.
|
||||
* @deprecated in Drupal 8.0.x-dev, will be removed before Drupal 9.0.0.
|
||||
* Use \Drupal\Core\StringTranslation\PluralTranslatableMarkup::DELIMITER
|
||||
* instead.
|
||||
*/
|
||||
const LOCALE_PLURAL_DELIMITER = "\03";
|
||||
|
||||
/**
|
||||
* Adds output to the HEAD tag of the HTML page.
|
||||
*
|
||||
* This function can be called as long as the headers aren't sent. Pass no
|
||||
* arguments (or NULL for both) to retrieve the currently stored elements.
|
||||
*
|
||||
* @param $data
|
||||
* A renderable array. If the '#type' key is not set then 'html_tag' will be
|
||||
* added as the default '#type'.
|
||||
* @param $key
|
||||
* A unique string key to allow implementations of hook_html_head_alter() to
|
||||
* identify the element in $data. Required if $data is not NULL.
|
||||
*
|
||||
* @return
|
||||
* An array of all stored HEAD elements.
|
||||
*
|
||||
* @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) {
|
||||
$stored_head = &drupal_static(__FUNCTION__, array());
|
||||
|
||||
if (isset($data) && isset($key)) {
|
||||
if (!isset($data['#type'])) {
|
||||
$data['#type'] = 'html_tag';
|
||||
}
|
||||
$stored_head[$key] = $data;
|
||||
}
|
||||
return $stored_head;
|
||||
}
|
||||
|
||||
/**
|
||||
* Retrieves output to be displayed in the HEAD tag of the HTML page.
|
||||
*
|
||||
* @param bool $render
|
||||
* If TRUE render the HEAD elements, otherwise return just the elements.
|
||||
*
|
||||
* @return string|array
|
||||
* 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) {
|
||||
$elements = _drupal_add_html_head();
|
||||
\Drupal::moduleHandler()->alter('html_head', $elements);
|
||||
if ($render) {
|
||||
return \Drupal::service('renderer')->renderPlain($elements);
|
||||
}
|
||||
else {
|
||||
return $elements;
|
||||
}
|
||||
}
|
||||
const LOCALE_PLURAL_DELIMITER = PluralTranslatableMarkup::DELIMITER;
|
||||
|
||||
/**
|
||||
* Prepares a 'destination' URL query parameter for use with url().
|
||||
|
@ -316,7 +262,7 @@ function check_url($uri) {
|
|||
* Optional language code to translate to a language other than what is used
|
||||
* to display the page.
|
||||
*
|
||||
* @return
|
||||
* @return \Drupal\Core\StringTranslation\TranslatableMarkup
|
||||
* A translated string representation of the size.
|
||||
*/
|
||||
function format_size($size, $langcode = NULL) {
|
||||
|
@ -325,16 +271,7 @@ function format_size($size, $langcode = NULL) {
|
|||
}
|
||||
else {
|
||||
$size = $size / Bytes::KILOBYTE; // Convert bytes to kilobytes.
|
||||
$units = array(
|
||||
t('@size KB', array(), array('langcode' => $langcode)),
|
||||
t('@size MB', array(), array('langcode' => $langcode)),
|
||||
t('@size GB', array(), array('langcode' => $langcode)),
|
||||
t('@size TB', array(), array('langcode' => $langcode)),
|
||||
t('@size PB', array(), array('langcode' => $langcode)),
|
||||
t('@size EB', array(), array('langcode' => $langcode)),
|
||||
t('@size ZB', array(), array('langcode' => $langcode)),
|
||||
t('@size YB', array(), array('langcode' => $langcode)),
|
||||
);
|
||||
$units = ['KB', 'MB', 'GB', 'TB', 'PB', 'EB', 'ZB', 'YB'];
|
||||
foreach ($units as $unit) {
|
||||
if (round($size, 2) >= Bytes::KILOBYTE) {
|
||||
$size = $size / Bytes::KILOBYTE;
|
||||
|
@ -343,7 +280,26 @@ function format_size($size, $langcode = NULL) {
|
|||
break;
|
||||
}
|
||||
}
|
||||
return str_replace('@size', round($size, 2), $unit);
|
||||
$args = ['@size' => round($size, 2)];
|
||||
$options = ['langcode' => $langcode];
|
||||
switch ($unit) {
|
||||
case 'KB':
|
||||
return new TranslatableMarkup('@size KB', $args, $options);
|
||||
case 'MB':
|
||||
return new TranslatableMarkup('@size MB', $args, $options);
|
||||
case 'GB':
|
||||
return new TranslatableMarkup('@size GB', $args, $options);
|
||||
case 'TB':
|
||||
return new TranslatableMarkup('@size TB', $args, $options);
|
||||
case 'PB':
|
||||
return new TranslatableMarkup('@size PB', $args, $options);
|
||||
case 'EB':
|
||||
return new TranslatableMarkup('@size EB', $args, $options);
|
||||
case 'ZB':
|
||||
return new TranslatableMarkup('@size ZB', $args, $options);
|
||||
case 'YB':
|
||||
return new TranslatableMarkup('@size YB', $args, $options);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -476,39 +432,6 @@ function base_path() {
|
|||
return $GLOBALS['base_path'];
|
||||
}
|
||||
|
||||
/**
|
||||
* Adds a LINK tag with a distinct 'rel' attribute to the page's HEAD.
|
||||
*
|
||||
* This function can be called as long the HTML header hasn't been sent, which
|
||||
* on normal pages is up through the preprocess step of _theme('html'). Adding
|
||||
* a link will overwrite a prior link with the exact same 'rel' and 'href'
|
||||
* attributes.
|
||||
*
|
||||
* @param $attributes
|
||||
* Associative array of element attributes including 'href' and 'rel'.
|
||||
* @param $header
|
||||
* 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) {
|
||||
$element = array(
|
||||
'#tag' => 'link',
|
||||
'#attributes' => $attributes,
|
||||
);
|
||||
$href = $attributes['href'];
|
||||
|
||||
if ($header) {
|
||||
// Also add a HTTP header "Link:".
|
||||
$href = '<' . Html::escape($attributes['href']) . '>;';
|
||||
unset($attributes['href']);
|
||||
$element['#attached']['http_header'][] = array('Link', $href . drupal_http_header_attributes($attributes), TRUE);
|
||||
}
|
||||
|
||||
_drupal_add_html_head($element, 'html_head_link:' . $attributes['rel'] . ':' . $href);
|
||||
}
|
||||
|
||||
/**
|
||||
* Deletes old cached CSS files.
|
||||
*
|
||||
|
@ -542,128 +465,6 @@ function drupal_js_defaults($data = NULL) {
|
|||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Merges two #attached arrays.
|
||||
*
|
||||
* The values under the 'drupalSettings' key are merged in a special way, to
|
||||
* match the behavior of:
|
||||
*
|
||||
* @code
|
||||
* jQuery.extend(true, {}, $settings_items[0], $settings_items[1], ...)
|
||||
* @endcode
|
||||
*
|
||||
* This means integer indices are preserved just like string indices are,
|
||||
* rather than re-indexed as is common in PHP array merging.
|
||||
*
|
||||
* Example:
|
||||
* @code
|
||||
* function module1_page_attachments(&$page) {
|
||||
* $page['a']['#attached']['drupalSettings']['foo'] = ['a', 'b', 'c'];
|
||||
* }
|
||||
* function module2_page_attachments(&$page) {
|
||||
* $page['#attached']['drupalSettings']['foo'] = ['d'];
|
||||
* }
|
||||
* // When the page is rendered after the above code, and the browser runs the
|
||||
* // resulting <SCRIPT> tags, the value of drupalSettings.foo is
|
||||
* // ['d', 'b', 'c'], not ['a', 'b', 'c', 'd'].
|
||||
* @endcode
|
||||
*
|
||||
* By following jQuery.extend() merge logic rather than common PHP array merge
|
||||
* logic, the following are ensured:
|
||||
* - Attaching JavaScript settings is idempotent: attaching the same settings
|
||||
* twice does not change the output sent to the browser.
|
||||
* - If pieces of the page are rendered in separate PHP requests and the
|
||||
* returned settings are merged by JavaScript, the resulting settings are the
|
||||
* same as if rendered in one PHP request and merged by PHP.
|
||||
*
|
||||
* @param array $a
|
||||
* An #attached array.
|
||||
* @param array $b
|
||||
* Another #attached array.
|
||||
*
|
||||
* @return array
|
||||
* The merged #attached array.
|
||||
*
|
||||
* @deprecated To be removed in Drupal 8.0.x. Use
|
||||
* \Drupal\Core\Render\BubbleableMetadata::mergeAttachments() instead.
|
||||
*/
|
||||
function drupal_merge_attached(array $a, array $b) {
|
||||
return BubbleableMetadata::mergeAttachments($a, $b);
|
||||
}
|
||||
|
||||
/**
|
||||
* Processes non-asset attachments in a render() structure.
|
||||
*
|
||||
* Libraries, JavaScript settings, feeds, HTML <head> tags and HTML <head> links
|
||||
* are attached to elements using the #attached property. The #attached property
|
||||
* is an associative array, where the keys are the attachment types and the
|
||||
* values are the attached data. For example:
|
||||
*
|
||||
* @code
|
||||
* $build['#attached'] = [
|
||||
* 'library' => ['core/jquery']
|
||||
* ];
|
||||
* $build['#attached']['http_header'] = [
|
||||
* ['Content-Type', 'application/rss+xml; charset=utf-8'],
|
||||
* ];
|
||||
* @endcode
|
||||
*
|
||||
* The available keys are:
|
||||
* - 'library' (asset libraries)
|
||||
* - 'drupalSettings' (JavaScript settings)
|
||||
* - 'feed' (RSS feeds)
|
||||
* - 'html_head' (tags in HTML <head>)
|
||||
* - 'html_head_link' (<link> tags in HTML <head>)
|
||||
* - 'http_header' (HTTP headers)
|
||||
*
|
||||
* This function processes all non-asset attachments, to apply them to the
|
||||
* current response (that means all keys except 'library' and 'drupalSettings').
|
||||
*
|
||||
* @param array $elements
|
||||
* The structured array describing the data being rendered.
|
||||
*
|
||||
* @see drupal_render()
|
||||
* @see \Drupal\Core\Asset\AssetResolver
|
||||
*
|
||||
* @throws LogicException
|
||||
* When attaching something of a non-existing attachment type.
|
||||
*/
|
||||
function drupal_process_attached(array $elements) {
|
||||
// Asset attachments are handled by \Drupal\Core\Asset\AssetResolver.
|
||||
foreach (array('library', 'drupalSettings') as $type) {
|
||||
unset($elements['#attached'][$type]);
|
||||
}
|
||||
|
||||
// Add additional types of attachments specified in the render() structure.
|
||||
foreach ($elements['#attached'] as $callback => $options) {
|
||||
foreach ($elements['#attached'][$callback] as $args) {
|
||||
// Limit the amount allowed entries.
|
||||
switch ($callback) {
|
||||
case 'html_head':
|
||||
call_user_func_array('_drupal_add_html_head', $args);
|
||||
break;
|
||||
case 'feed':
|
||||
$args = [[
|
||||
'href' => $args[0],
|
||||
'rel' => 'alternate',
|
||||
'title' => $args[1],
|
||||
'type' => 'application/rss+xml',
|
||||
]];
|
||||
call_user_func_array('_drupal_add_html_head_link', $args);
|
||||
break;
|
||||
case 'html_head_link':
|
||||
call_user_func_array('_drupal_add_html_head_link', $args);
|
||||
break;
|
||||
case 'http_header':
|
||||
// @todo Remove validation in https://www.drupal.org/node/2477223
|
||||
break;
|
||||
default:
|
||||
throw new \LogicException(sprintf('You are not allowed to use %s in #attached', $callback));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Adds JavaScript to change the state of an element based on another element.
|
||||
*
|
||||
|
@ -1057,7 +858,7 @@ function drupal_pre_render_links($element) {
|
|||
}
|
||||
// Merge attachments.
|
||||
if (isset($child['#attached'])) {
|
||||
$element['#attached'] = drupal_merge_attached($element['#attached'], $child['#attached']);
|
||||
$element['#attached'] = BubbleableMetadata::mergeAttachments($element['#attached'], $child['#attached']);
|
||||
}
|
||||
}
|
||||
return $element;
|
||||
|
@ -1097,7 +898,7 @@ function drupal_render(&$elements, $is_recursive_call = FALSE) {
|
|||
* can be passed in to save another run of
|
||||
* \Drupal\Core\Render\Element::children().
|
||||
*
|
||||
* @return string|\Drupal\Component\Utility\SafeStringInterface
|
||||
* @return string|\Drupal\Component\Render\MarkupInterface
|
||||
* The rendered HTML of all children of the element.
|
||||
*
|
||||
* @see drupal_render()
|
||||
|
@ -1112,7 +913,7 @@ function drupal_render_children(&$element, $children_keys = NULL) {
|
|||
$output .= drupal_render($element[$key]);
|
||||
}
|
||||
}
|
||||
return SafeString::create($output);
|
||||
return Markup::create($output);
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
Reference in a new issue