public function FieldItems::children in Twig Extender 4.x
Same name and namespace in other branches
- 8.4 modules/twig_extender_extras/src/Plugin/TwigPlugin/FieldItems.php \Drupal\twig_extender_extras\Plugin\TwigPlugin\FieldItems::children()
- 8.2 modules/twig_extender_extras/src/Plugin/TwigPlugin/FieldItems.php \Drupal\twig_extender_extras\Plugin\TwigPlugin\FieldItems::children()
- 8.3 modules/twig_extender_extras/src/Plugin/TwigPlugin/FieldItems.php \Drupal\twig_extender_extras\Plugin\TwigPlugin\FieldItems::children()
Identifies the children of an element array, optionally sorted by weight.
The children of a element array are those key/value pairs whose key does not start with a '#'. See drupal_render() for details.
Parameters
array $elements: The element array whose children are to be identified. Passed by reference.
bool $sort: Boolean to indicate whether the children should be sorted by weight.
Return value
array The filtered array to loop over.
Throws
\Exception
File
- modules/
twig_extender_extras/ src/ Plugin/ TwigPlugin/ FieldItems.php, line 38
Class
- FieldItems
- Twig plugin for loop render children.
Namespace
Drupal\twig_extender_extras\Plugin\TwigPluginCode
public function children(array $elements, $sort = FALSE) {
if (gettype($elements) !== 'array') {
throw new \Exception('Could not convert object to array.');
}
$ids = Element::children($elements, $sort);
return array_intersect_key($elements, array_flip($ids));
}