public static function TwigExtension::recursiveMergeFilter in Components! 8.2
Same name and namespace in other branches
- 3.x src/Template/TwigExtension.php \Drupal\components\Template\TwigExtension::recursiveMergeFilter()
Recursively merges an array into the element, replacing existing values.
{{ form|recursive_merge( {'element': {'attributes': {'placeholder': 'Label'}}} ) }}
Parameters
array|iterable|\Traversable $element: The parent renderable array to merge into.
iterable|array $array: The array to merge.
Return value
array The merged renderable array.
Throws
\Twig\Error\RuntimeError When $element is not an array or "Traversable".
3 calls to TwigExtension::recursiveMergeFilter()
- TwigExtension::setFilter in src/
Template/ TwigExtension.php - Sets a deeply-nested property on an array.
- TwigExtensionFiltersTest::testRecursiveMergeFilter in tests/
src/ Unit/ TwigExtensionFiltersTest.php - Tests the recursive_merge filter.
- TwigExtensionFiltersTest::testRecursiveMergeFilterException in tests/
src/ Unit/ TwigExtensionFiltersTest.php - Tests exceptions during recursive_merge filter.
File
- src/
Template/ TwigExtension.php, line 131
Class
- TwigExtension
- A class providing components' Twig extensions.
Namespace
Drupal\components\TemplateCode
public static function recursiveMergeFilter($element, $array) {
if (!twig_test_iterable($element)) {
throw new RuntimeError(sprintf('The recursive_merge filter only works on arrays or "Traversable" objects, got "%s".', gettype($element)));
}
return array_replace_recursive($element, $array);
}