Skip to content

Instantly share code, notes, and snippets.

@wimleers
Created November 26, 2014 11:16
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save wimleers/4a952f0f7592efa8d71b to your computer and use it in GitHub Desktop.
Save wimleers/4a952f0f7592efa8d71b to your computer and use it in GitHub Desktop.
<?php
class Renderer {
// unchanged relative to HEAD
public function renderRoot(&$elements) {
return $this->render($elements, TRUE);
}
// new!
public function renderPlain(&$elements) {
$current_stack = $this->stack;
$this->stack = NULL;
$output = $this->render($elements, TRUE);
$this->stack = $current_stack;
return $output;
}
// and in ::render(), we still have this:
public function render(…) {
if ($this->stack->count() !== 1) {
throw new \LogicException('A stray drupal_render() invocation with $is_root_call = TRUE is causing bubbling of attached assets to break.');
}
}
}
@wimleers
Copy link
Author

::renderRoot() may not be called inside ::renderRoot()

::renderPlain() may be called from inside anything. (Hence tokens and check_markup() can be called from anything — which makes sense.)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment