class EntityconnectNestedArray in Entity connect 8.2
Reimplements NestedArray methods to answer specific needs of the module.
Entityconnect button adds a new level in parents array, named "add_entityconnect" and "edit_entityconnect" and we need to remove them in our array building. So we need to rewrite NestedArray::getValue()/setValue() to include these removals.
Hierarchy
- class \Drupal\Component\Utility\NestedArray
- class \Drupal\entityconnect\EntityconnectNestedArray
Expanded class hierarchy of EntityconnectNestedArray
See also
Drupal\Component\Utility\NestedArray::getValue()
Drupal\Component\Utility\NestedArray::setValue()
1 file declares its use of EntityconnectNestedArray
- EntityconnectSubmit.php in src/
Element/ EntityconnectSubmit.php
File
- src/
EntityconnectNestedArray.php, line 18
Namespace
Drupal\entityconnectView source
class EntityconnectNestedArray extends NestedArray {
/**
* {@inheritdoc}
*/
public static function &getValue(array &$array, array $parents, &$key_exists = NULL) {
$ref =& $array;
foreach ($parents as $parent) {
if (stripos($parent, 'add_entityconnect') === FALSE && stripos($parent, 'edit_entityconnect') === FALSE) {
if (is_array($ref) && array_key_exists($parent, $ref)) {
$ref =& $ref[$parent];
}
else {
$key_exists = FALSE;
$null = NULL;
return $null;
}
}
}
$key_exists = TRUE;
return $ref;
}
/**
* {@inheritdoc}
*/
public static function setValue(array &$array, array $parents, $value, $force = FALSE) {
$ref =& $array;
foreach ($parents as $parent) {
if (stripos($parent, 'add_entityconnect') === FALSE && stripos($parent, 'edit_entityconnect') === FALSE) {
// PHP auto-creates container arrays and NULL entries without error if
// $ref is NULL, but throws an error if $ref is set, but not an array.
if ($force && isset($ref) && !is_array($ref)) {
$ref = [];
}
$ref =& $ref[$parent];
}
}
$ref = $value;
}
}
Members
Name | Modifiers | Type | Description | Overrides |
---|---|---|---|---|
EntityconnectNestedArray:: |
public static | function |
Retrieves a value from a nested array with variable depth. Overrides NestedArray:: |
|
EntityconnectNestedArray:: |
public static | function |
Sets a value in a nested array with variable depth. Overrides NestedArray:: |
|
NestedArray:: |
public static | function | Filters a nested array recursively. | |
NestedArray:: |
public static | function | Determines whether a nested array contains the requested keys. | |
NestedArray:: |
public static | function | Merges multiple arrays, recursively, and returns the merged array. | |
NestedArray:: |
public static | function | Merges multiple arrays, recursively, and returns the merged array. | |
NestedArray:: |
public static | function | Unsets a value in a nested array with variable depth. |