public static function ConfigActionsTransform::add in Config Actions 8
Walk a tree and add a value at the end of the path
Parameters
array $tree : A base on which to add the path:
array $path : An array of keys to walk in the tree:
$value : what ever is to be add at the end of the path:
bool $append TRUE to merge with existing data, FALSE to replace:
Return value
array: A copy of the $tree with the new value added
4 calls to ConfigActionsTransform::add()
- ConfigActionsAdd::transform in src/
Plugin/ ConfigActions/ ConfigActionsAdd.php - Main transform to perform the add
- ConfigActionsDefault::transform in src/
Plugin/ ConfigActions/ ConfigActionsDefault.php - Main transform to perform the change
- ConfigActionsTransform::change in src/
ConfigActionsTransform.php - Walk a tree and add change the value at the end of a path
- ConfigActionsTransformTest::testAdd in tests/
src/ Unit/ ConfigActionsTransformTest.php - @covers ::add
File
- src/
ConfigActionsTransform.php, line 171
Class
- ConfigActionsTransform
- Perform transformations on data needed for config_actions plugins
Namespace
Drupal\config_actionsCode
public static function add(array $tree, array $path, $value, $append = FALSE) {
if ($append) {
$current_value = static::read($tree, $path);
if (!isset($current_value) && !is_array($value)) {
$value = [
$value,
];
}
elseif (is_array($current_value)) {
if (!is_array($value)) {
$value = array_merge($current_value, [
$value,
]);
}
else {
$value = NestedArray::mergeDeepArray([
$current_value,
$value,
], TRUE);
}
}
}
static::tree_change_data($tree, $path, $value);
return $tree;
}