You are here

function entityconnect_array_set_nested_value in Entity connect 7.2

Same name and namespace in other branches
  1. 7 includes/entityconnect.form.inc \entityconnect_array_set_nested_value()

Reimplements drupal_array_set_nested_value() to ansewer 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 into our array building. So we need to rewrite drupal_array_set_nested_value() to include these remove.

See also

drupal_array_set_nested_value()

1 call to entityconnect_array_set_nested_value()
_entityconnect_alter_form_state_input in includes/entityconnect.form.inc
Used to update the form state value.

File

includes/entityconnect.form.inc, line 958
Handles all form alters and submit functions for entityconnect.

Code

function entityconnect_array_set_nested_value(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 = array();
      }
      $ref =& $ref[$parent];
    }
  }
  $ref = $value;
}