Quantcast
Channel: Issues for Drupal core
Viewing all articles
Browse latest Browse all 292480

Allow NULL values in Twig templates.

$
0
0

NULL variables being passed to Twig templates lead to exceptions - eg. #1961872: Convert html.tpl.php to Twig, #1843746: Convert views/templates/views-view-field.tpl.php to Twig .

NULL variables can simply be the result of calling drupal_render() on a renderable array with '#access' => FALSE within a preprocess/process function - #1975442: drupal_render() should always return a string., so it's very likely that this will turn up more in contrib than we're currently seeing in core.

I believe the offending code is:

<?php
   
// Optimized version
   
if (!isset($context[$item])) {
     
// We don't want to throw an exception, but issue a warning instead.
      // This is the easiest way to do so.
      // @todo Decide based on prod vs. dev setting
     
$msg = new \Twig_Error(t('@item could not be found in _context', array('@item'=> $item)));
     
trigger_error($msg->getMessage(), E_USER_WARNING);
      return
NULL;
    }
?>

in /core/lib/Drupal/Core/Template/TwigTemplate.php

I propose we change:

    if (!isset($context[$item])) {

to something like:

    if (!isset($context[$item]) && !is_null($context[$item])) {


Viewing all articles
Browse latest Browse all 292480

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>