public function TwigReference::offsetGet

Retrieves offset from internal reference.

In case of a render array, it is wrapped again within a TwigReference object.

Parameters

mixed $offset: The offset to retrieve.

Return value

mixed Returns a TwigReference object wrapping the array if the retrieved offset is a complex array (i.e. not an attribute). Else it returns the retrived offset directly.

File

drupal/core/lib/Drupal/Core/Template/TwigReference.php, line 121
Definition of Drupal\Core\Template\TwigReference.

Class

TwigReference
A class used to pass variables by reference while they are used in twig.

Namespace

Drupal\Core\Template

Code

public function offsetGet($offset) {
  if (!is_array($this->writableRef[$offset]) || $offset[0] == '#') {
    return $this->writableRef[$offset];
  }

  // Wrap the returned array in a new TwigReference.
  $x = clone $this;

  // clone is faster than new
  $x
    ->setReference($this->writableRef[$offset]);
  return $x;
}