array $context: The variables available to the template.
$item: The name of the variable.
mixed The requested variable.
protected final function getContextReference(&$context, $item) {
// 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;
}
// The first test also finds empty / null render arrays
if (!$context[$item] || isset($this->is_no_reference[$item])) {
return $context[$item];
}
if (isset($context['_references'][$item])) {
return $context['_references'][$item];
}
// @todo Check if this is a render array (existence of #theme?)
if (!isset($this->is_reference[$item]) && ($context[$item] instanceof \TwigMarkup || !is_array($context[$item]))) {
$this->is_no_reference[$item] = TRUE;
return $context[$item];
}
if ($this->twig_reference == NULL) {
$this->twig_reference = new TwigReference();
}
$ref = clone $this->twig_reference;
// clone is _much_ faster than new
$ref
->setReference($context[$item]);
// Save that this is a reference
$context['_references'][$item] = $ref;
$this->is_reference[$item] = TRUE;
return $ref;
}