A class used to pass variables by reference while they are used in twig.
This is done by saving a reference to the original render array within a TwigReference via the setReference() method like this:
$obj = new TwigReference();
$obj
->setReference($variable);
When a TwigReference is accessed via the offsetGet method the resulting reference is again wrapped within a TwigReference. Therefore references to render arrays within render arrays are also retained.
To unwrap TwigReference objects the reference can be retrieved out of the object by calling the getReference() method like this:
$variable =& $obj
->getReference();
This allows render(), hide() and show() to access the original variable and change it. The process of unwrapping and passing by reference to this functions is done transparently by the TwigReferenceFunctions helper class.
Expanded class hierarchy of TwigReference
Name![]() |
Modifiers | Type | Description | Overrides |
---|---|---|---|---|
TwigReference:: |
protected | property | Holds an internal reference to the original array. | |
TwigReference:: |
public | function | Gets a reference to the internal storage. | |
TwigReference:: |
public | function | Retrieves offset from internal reference. | |
TwigReference:: |
public | function | Sets offset in internal reference and internal storage to value. | |
TwigReference:: |
public | function | Sets a reference in the internal storage. | |
TwigReference:: |
public | function | Constructs a \Drupal\Core\Template\TwigReference object. |