core/lib/Drupal/Core/Template/TwigExtension.php | 23 +++++++++++++++++++++++ core/modules/update/update.module | 7 +------ 2 files changed, 24 insertions(+), 6 deletions(-) diff --git a/core/lib/Drupal/Core/Template/TwigExtension.php b/core/lib/Drupal/Core/Template/TwigExtension.php index e204ba9..b311347 100644 --- a/core/lib/Drupal/Core/Template/TwigExtension.php +++ b/core/lib/Drupal/Core/Template/TwigExtension.php @@ -4,7 +4,9 @@ use Drupal\Component\Utility\Html; use Drupal\Component\Render\MarkupInterface; +use Drupal\Core\Cache\CacheableDependencyInterface; use Drupal\Core\Datetime\DateFormatterInterface; +use Drupal\Core\Render\AttachmentsInterface; use Drupal\Core\Render\RenderableInterface; use Drupal\Core\Render\RendererInterface; use Drupal\Core\Routing\UrlGeneratorInterface; @@ -410,6 +412,8 @@ public function escapeFilter(\Twig_Environment $env, $arg, $strategy = 'html', $ return NULL; } + $this->bubbleArgMetadata($arg); + // Keep Twig_Markup objects intact to support autoescaping. if ($autoescape && ($arg instanceof \Twig_Markup || $arg instanceof MarkupInterface)) { return $arg; @@ -462,6 +466,24 @@ public function escapeFilter(\Twig_Environment $env, $arg, $strategy = 'html', $ return $this->renderer->render($arg); } + protected function bubbleArgMetadata($arg) { + if ($arg instanceof CacheableDependencyInterface || $arg instanceof AttachmentsInterface) { + $arg_bubbleable = []; + if ($arg instanceof CacheableDependencyInterface) { + $arg_bubbleable['#cache']['contexts'] = $arg->getCacheContexts(); + $arg_bubbleable['#cache']['tags'] = $arg->getCacheTags(); + $arg_bubbleable['#cache']['max-age'] = $arg->getCacheMaxAge(); + } + if ($arg instanceof AttachmentsInterface) { + $arg_bubbleable['#attached'] = $arg->getAttachments(); + } + if ($arg_bubbleable) { + // @todo Inject the Renderer in https://www.drupal.org/node/2529438. + drupal_render($arg_bubbleable); + } + } + } + /** * Wrapper around render() for twig printed output. * @@ -504,6 +526,7 @@ public function renderVar($arg) { } if (is_object($arg)) { + $this->bubbleArgMetadata($arg); if ($arg instanceof RenderableInterface) { $arg = $arg->toRenderable(); } diff --git a/core/modules/update/update.module b/core/modules/update/update.module index fadd2e4..01db0a7 100644 --- a/core/modules/update/update.module +++ b/core/modules/update/update.module @@ -567,12 +567,7 @@ function _update_project_status_sort($a, $b) { */ function template_preprocess_update_last_check(&$variables) { $variables['time'] = \Drupal::service('date.formatter')->formatTimeDiffSince($variables['last']); - $variables['link'] = [ - '#type' => 'link', - '#title' => t('Check manually'), - '#url' => Url::fromRoute('update.manual_status', [], ['query' => \Drupal::destination()->getAsArray()]), - ]; - + $variables['link'] = \Drupal::l(t('Check manually'), new Url('update.manual_status', array(), array('query' => \Drupal::destination()->getAsArray()))); } /**