public static function TwigReferenceFunctions::__callStatic

Magic function to call functions called from twig templates with a reference to the original variable.

This checks if the array provided by value is containing a reference to the original version. If yes it replaces the argument with its reference.

Parameters

$name: The name of the function to call.

$arguments: The arguments to process and pass to the called function.

Return value

mixed Returns the output of the called function.

See also

TwigReference

File

drupal/core/lib/Drupal/Core/Template/TwigReferenceFunctions.php, line 77
Definition of Drupal\Core\Template\TwigReferenceFunctions.

Class

TwigReferenceFunctions
A helper used to unwrap TwigReference objects transparently.

Namespace

Drupal\Core\Template

Code

public static function __callStatic($name, $arguments) {
  foreach ($arguments as $key => $val) {
    if (is_object($val) && $val instanceof TwigReference) {
      $arguments[$key] =& $val
        ->getReference();
    }
  }

  // Needed to pass by reference -- could also restrict to maximum one
  // argument instead
  $args = array();
  foreach ($arguments as $key => &$arg) {
    $args[$key] =& $arg;
  }
  return call_user_func_array($name, $args);
}