You are here

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

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\entityconnect
View 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

Namesort descending Modifiers Type Description Overrides
EntityconnectNestedArray::getValue public static function Retrieves a value from a nested array with variable depth. Overrides NestedArray::getValue
EntityconnectNestedArray::setValue public static function Sets a value in a nested array with variable depth. Overrides NestedArray::setValue
NestedArray::filter public static function Filters a nested array recursively.
NestedArray::keyExists public static function Determines whether a nested array contains the requested keys.
NestedArray::mergeDeep public static function Merges multiple arrays, recursively, and returns the merged array.
NestedArray::mergeDeepArray public static function Merges multiple arrays, recursively, and returns the merged array.
NestedArray::unsetValue public static function Unsets a value in a nested array with variable depth.