public function JobItem::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 JobItemInterface::updateData

2 calls to JobItem::updateData()
JobItem::addTranslatedDataRecursive in src/Entity/JobItem.php
Recursively writes translated data to the data array of a job item.
JobItem::dataItemRevert in src/Entity/JobItem.php
Reverts data item translation to the latest existing revision.

File

src/Entity/JobItem.php, line 808

Class

JobItem
Entity class for the tmgmt_job_item entity.

Namespace

Drupal\tmgmt\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);
    }
  }
}