Updates the values for a specific substructure in the data array.
The values are either set or updated but never deleted.
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
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);
}
}
}