Quantcast
Viewing all articles
Browse latest Browse all 294835

drupal_render() should always return a string.

Currently drupal_render can either return NULL or a string.

This can cause hard-to-debug issues with Twig templates and probably in other places too. It also seems to just be adding needless extra complexity to a function that's otherwise already quite complicated.

See #1961872: Convert html.tpl.php to Twig for an example.

- A variable to be rendered is created in the preprocess (page_top)
- The variable is set to #access => FALSE by a module's preprocess function (in this case overlay)
- The variable is rendered by drupal_render() in the process phase and becomes NULL instead of a string
- Twig complains "@item could not be found in _context"
- Only solution is to start special-casing any variable that could likely have access checks with (string) type casting or $foo . ''; or to wrap everything in Twig templates with {% if foo %}. This is kinda clumsy/fragile/ugly.

I don't see any advantage to returning NULL instead of '', only disadvantages, to the point where it looks like a mistake. I'm open to discussion/education though :)


Viewing all articles
Browse latest Browse all 294835

Trending Articles



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