public function LocalTaskItem::updateData

Updates the values for a specific substructure in the data array.

The values are either set or updated but never deleted.

Parameters

string|array $key: Key pointing to the item the values should be applied. The key can be either be an array containing the keys of a nested array hierarchy path or a string with '][' or '|' as delimiter.

array $values: Nested array of values to set.

bool $replace: (optional) When TRUE, replaces the structure at the provided key instead of writing into it.

Overrides LocalTaskItemInterface::updateData

File

translators/tmgmt_local/src/Entity/LocalTaskItem.php, line 183

Class

LocalTaskItem
Entity class for the local task item entity.

Namespace

Drupal\tmgmt_local\Entity

Code

public function updateData($key, $values = array(), $replace = FALSE) {
  $this
    ->decodeData();
  if ($replace) {
    NestedArray::setValue($this->unserializedData, \Drupal::service('tmgmt.data')
      ->ensureArrayKey($key), $values);
  }
  foreach ($values as $index => $value) {

    // In order to preserve existing values, we can not aplly the values array
    // at once. We need to apply each containing value on its own.
    // If $value is an array we need to advance the hierarchy level.
    if (is_array($value)) {
      $this
        ->updateData(array_merge(\Drupal::service('tmgmt.data')
        ->ensureArrayKey($key), array(
        $index,
      )), $value);
    }
    else {
      NestedArray::setValue($this->unserializedData, array_merge(\Drupal::service('tmgmt.data')
        ->ensureArrayKey($key), array(
        $index,
      )), $value, TRUE);
    }
  }
}