/** * Unsets a value in this configuration object. * * @param string $key * Name of the key whose value should be unset. * * @return $this * The configuration object. */ public function clear($key) { $parts = explode('.', $key); if (count($parts) == 1) { unset($this->data[$key]); } else { NestedArray::unsetValue($this->data, $parts); } return $this; }
/** * Removes destination property. * * @param string $property * The name of the destination property. */ public function removeDestinationProperty($property) { unset($this->rawDestination[$property]); NestedArray::unsetValue($this->destination, explode(static::PROPERTY_SEPARATOR, $property)); }
/** * Implements \Drupal\Core\Form\FormStateInterface::unsetValue() */ public function unsetValue($key) { NestedArray::unsetValue($this->getValues(), (array) $key); return $this; }
/** * Overrides the specified library asset. * * @param array $library * The containing library definition. * @param array $sub_key * An array containing the sub-keys specifying the library asset, e.g. * @code['js']@endcode or @code['css', 'component']@endcode * @param array $overrides * Specifies the overrides, this is an array where the key is the asset to * be overridden while the value is overriding asset. */ protected function setOverrideValue(array &$library, array $sub_key, array $overrides, $theme_path) { foreach ($overrides as $original => $replacement) { // Get the attributes of the asset to be overridden. If the key does // not exist, then throw an exception. $key_exists = NULL; $parents = array_merge($sub_key, [$original]); // Save the attributes of the library asset to be overridden. $attributes = NestedArray::getValue($library, $parents, $key_exists); if ($key_exists) { // Remove asset to be overridden. NestedArray::unsetValue($library, $parents); // No need to replace if FALSE is specified, since that is a removal. if ($replacement) { // Ensure the replacement path is relative to drupal root. $replacement = $this->resolveThemeAssetPath($theme_path, $replacement); $new_parents = array_merge($sub_key, [$replacement]); // Replace with an override if specified. NestedArray::setValue($library, $new_parents, $attributes); } } } }
/** * Tests unsetting nested array values. * * @covers ::unsetValue */ public function testUnsetValue() { // Verify unsetting a non-existing nested element throws no errors and the // non-existing key is properly reported. $key_existed = NULL; $parents = $this->parents; $parents[] = 'foo'; NestedArray::unsetValue($this->form, $parents, $key_existed); $this->assertTrue(isset($this->form['details']['element']['#value']), 'Outermost nested element key still exists.'); $this->assertFalse($key_existed, 'Non-existing key not found.'); // Verify unsetting a nested element. $key_existed = NULL; NestedArray::unsetValue($this->form, $this->parents, $key_existed); $this->assertFalse(isset($this->form['details']['element']), 'Removed nested element not found.'); $this->assertTrue($key_existed, 'Existing key was found.'); }
public function clear($property) { NestedArray::unsetValue($this->data, $this->toKey($property)); return $this; }