Update to Drupal 8.0.0 beta 14. For more information, see https://drupal.org/node/2544542

This commit is contained in:
Pantheon Automation 2015-08-27 12:03:05 -07:00 committed by Greg Anderson
parent 3b2511d96d
commit 81ccda77eb
2155 changed files with 54307 additions and 46870 deletions

View file

@ -43,10 +43,11 @@ use Drupal\Component\Utility\SafeStringInterface;
* htmlspecialchars() and the entire attribute string is marked safe for output.
*/
class Attribute implements \ArrayAccess, \IteratorAggregate, SafeStringInterface {
/**
* Stores the attribute data.
*
* @var array
* @var \Drupal\Core\Template\AttributeValueBase[]
*/
protected $storage = array();
@ -261,6 +262,21 @@ class Attribute implements \ArrayAccess, \IteratorAggregate, SafeStringInterface
return $return;
}
/**
* Returns all storage elements as an array.
*
* @return array
* An associative array of attributes.
*/
public function toArray() {
$return = [];
foreach ($this->storage as $name => $value) {
$return[$name] = $value->value();
}
return $return;
}
/**
* Implements the magic __clone() method.
*/

View file

@ -7,7 +7,10 @@
namespace Drupal\Core\Template;
use Drupal\Component\Utility\SafeMarkup;
use Drupal\Core\Cache\CacheBackendInterface;
use Drupal\Core\PhpStorage\PhpStorageFactory;
use Drupal\Core\Render\SafeString;
/**
* A class that defines a Twig environment for Drupal.
@ -34,14 +37,15 @@ class TwigEnvironment extends \Twig_Environment {
*
* @param string $root
* The app root.
* @param \Drupal\Core\Cache\CacheBackendInterface $cache
* The cache bin.
* @param \Twig_LoaderInterface $loader
* The Twig loader or loader chain.
* @param array $options
* The options for the Twig environment.
*/
public function __construct($root, \Twig_LoaderInterface $loader = NULL, $options = array()) {
// @todo Pass as arguments from the DIC.
$this->cache_object = \Drupal::cache();
public function __construct($root, CacheBackendInterface $cache, \Twig_LoaderInterface $loader = NULL, $options = array()) {
$this->cache_object = $cache;
// Ensure that twig.engine is loaded, given that it is needed to render a
// template because functions like TwigExtension::escapeFilter() are called.
@ -115,12 +119,7 @@ class TwigEnvironment extends \Twig_Environment {
if (!class_exists($cls, FALSE)) {
$cache_filename = $this->getCacheFilename($name);
if ($cache_filename === FALSE) {
$compiled_source = $this->compileSource($this->loader->getSource($name), $name);
eval('?' . '>' . $compiled_source);
}
else {
if ($cache_filename !== FALSE) {
// If autoreload is on, check that the template has not been
// modified since the last compilation.
if ($this->isAutoReload() && !$this->isFresh($cache_filename, $name)) {
@ -132,6 +131,10 @@ class TwigEnvironment extends \Twig_Environment {
$this->storage()->load($cache_filename);
}
}
if (!class_exists($cls, FALSE)) {
$compiled_source = $this->compileSource($this->loader->getSource($name), $name);
eval('?' . '>' . $compiled_source);
}
}
if (!$this->runtimeInitialized) {
@ -193,15 +196,15 @@ class TwigEnvironment extends \Twig_Environment {
* @param array $context
* An array of parameters to pass to the template.
*
* @return string
* The rendered inline template.
* @return \Drupal\Component\Utility\SafeStringInterface|string
* The rendered inline template as a SafeString object.
*
* @see \Drupal\Core\Template\Loader\StringLoader::exists()
*/
public function renderInline($template_string, array $context = array()) {
// Prefix all inline templates with a special comment.
$template_string = '{# inline_template_start #}' . $template_string;
return $this->loadTemplate($template_string, NULL)->render($context);
return SafeString::create($this->loadTemplate($template_string, NULL)->render($context));
}
}

View file

@ -222,7 +222,7 @@ class TwigExtension extends \Twig_Extension {
$options['absolute'] = TRUE;
$generated_url = $this->urlGenerator->generateFromRoute($name, $parameters, $options, TRUE);
// Return as render array, so we can bubble the cacheability metadata.
// Return as render array, so we can bubble the bubbleable metadata.
$build = ['#markup' => $generated_url->getGeneratedUrl()];
$generated_url->applyTo($build);
return $build;
@ -247,7 +247,7 @@ class TwigExtension extends \Twig_Extension {
$options['absolute'] = TRUE;
$generated_url = $this->urlGenerator->generateFromPath($path, $options, TRUE);
// Return as render array, so we can bubble the cacheability metadata.
// Return as render array, so we can bubble the bubbleable metadata.
$build = ['#markup' => $generated_url->getGeneratedUrl()];
$generated_url->applyTo($build);
return $build;
@ -260,17 +260,20 @@ class TwigExtension extends \Twig_Extension {
* The link text for the anchor tag as a translated string.
* @param \Drupal\Core\Url|string $url
* The URL object or string used for the link.
* @param array $attributes
* An optional array of link attributes.
* @param array|\Drupal\Core\Template\Attribute $attributes
* An optional array or Attribute object of link attributes.
*
* @return array
* A render array representing a link to the given URL.
*/
public function getLink($text, $url, array $attributes = []) {
public function getLink($text, $url, $attributes = []) {
if (!$url instanceof Url) {
$url = Url::fromUri($url);
}
if ($attributes) {
if ($attributes instanceof Attribute) {
$attributes = $attributes->toArray();
}
if ($existing_attributes = $url->getOption('attributes')) {
$attributes = array_merge($existing_attributes, $attributes);
}

View file

@ -21,14 +21,14 @@ class TwigNodeVisitor implements \Twig_NodeVisitorInterface {
/**
* {@inheritdoc}
*/
function enterNode(\Twig_NodeInterface $node, \Twig_Environment $env) {
public function enterNode(\Twig_NodeInterface $node, \Twig_Environment $env) {
return $node;
}
/**
* {@inheritdoc}
*/
function leaveNode(\Twig_NodeInterface $node, \Twig_Environment $env) {
public function leaveNode(\Twig_NodeInterface $node, \Twig_Environment $env) {
// We use this to inject a call to render_var -> TwigExtension->renderVar()
// before anything is printed.
if ($node instanceof \Twig_Node_Print) {
@ -62,7 +62,7 @@ class TwigNodeVisitor implements \Twig_NodeVisitorInterface {
/**
* {@inheritdoc}
*/
function getPriority() {
public function getPriority() {
// Just above the Optimizer, which is the normal last one.
return 256;
}