unsetValue example

          // this part entirely.         }

        break;

      case 'enter_connection_settings':
        $form_state->setRebuild();
        break;

      case 'change_connection_type':
        $form_state->setRebuild();
        $form_state->unsetValue(['connection_settings', 'authorize_filetransfer_default']);
        break;
    }
  }

  /** * Gets a FileTransfer class for a specific transfer method and settings. * * @param $backend * The FileTransfer backend to get the class for. * @param $settings * Array of settings for the FileTransfer. * * @return \Drupal\Core\FileTransfer\FileTransfer|bool * An instantiated FileTransfer object for the requested method and settings, * or FALSE if there was an error finding or instantiating it. */
/** * {@inheritdoc} */
  public function blockSubmit($form, FormStateInterface $form_state) {
    if (!$form_state->isValueEmpty('views_label_checkbox')) {
      $this->configuration['views_label'] = $form_state->getValue('views_label');
    }
    else {
      $this->configuration['views_label'] = '';
    }
    $form_state->unsetValue('views_label_checkbox');
  }

  /** * Converts Views block content to a renderable array with contextual links. * * @param string|array $output * A string|array representing the block. This will be modified to be a * renderable array, containing the optional '#contextual_links' property (if * there are any contextual links associated with the block). * @param string $block_type * The type of the block. If it's 'block' it's a regular views display, * but 'exposed_filter' exist as well. */
NestedArray::setValue($this->destination, explode(static::PROPERTY_SEPARATOR, $property)$value, TRUE);
  }

  /** * 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));
  }

  /** * Sets a destination to be empty. * * @param string $property * The destination property. */
  public function setEmptyDestinationProperty($property) {
    $this->emptyDestinationProperties[] = $property;
  }

  
/** * #element_validate handler for "image_upload" in buildConfigurationForm(). * * Moves the text editor's image upload settings into $editor->image_upload. * * @see editor_image_upload_settings_form() */
  public function validateImageUploadSettings(array $element, FormStateInterface $form_state) {
    $settings = &$form_state->getValue(['editor', 'settings', 'image_upload']);
    $form_state->get('editor')->setImageUploadSettings($settings);
    $form_state->unsetValue(['editor', 'settings', 'image_upload']);
  }

  /** * {@inheritdoc} */
  public function getJSSettings(Editor $editor) {
    $js_settings = [];
    $settings = $editor->getSettings();
    if ($settings['ponies_too']) {
      $js_settings['ponyModeEnabled'] = TRUE;
    }
    

  public function setValue($key$value) {
    NestedArray::setValue($this->getValues()(array) $key$value, TRUE);
    return $this;
  }

  /** * Implements \Drupal\Core\Form\FormStateInterface::unsetValue() */
  public function unsetValue($key) {
    NestedArray::unsetValue($this->getValues()(array) $key);
    return $this;
  }

  /** * Implements \Drupal\Core\Form\FormStateInterface::hasValue() */
  public function hasValue($key) {
    $exists = NULL;
    $value = NestedArray::getValue($this->getValues()(array) $key$exists);
    return $exists && isset($value);
  }

  
if (!empty($this->options['exposed'])) {
      $this->validateExposeForm($form$form_state);
    }

  }

  /** * Simple submit handler. */
  public function submitOptionsForm(&$form, FormStateInterface $form_state) {
    // Do not store this values.     $form_state->unsetValue('expose_button');

    $this->sortSubmit($form$form_state);
    if (!empty($this->options['exposed'])) {
      $this->submitExposeForm($form$form_state);
    }
  }

  /** * Shortcut to display the value form. */
  protected function showSortForm(&$form, FormStateInterface $form_state) {
    

  public function clear($key) {
    $parts = explode('.', $key);
    if (count($parts) == 1) {
      unset($this->data[$key]);
    }
    else {
      NestedArray::unsetValue($this->data, $parts);
    }
    return $this;
  }

  /** * Merges data into a configuration object. * * @param array $data_to_merge * An array containing data to merge. * * @return $this * The configuration object. */
->shouldBeCalled();

    $this->assertSame($this->formStateDecoratorBase, $this->formStateDecoratorBase->setValue($key$value));
  }

  /** * @covers ::unsetValue */
  public function testUnsetValue() {
    $key = 'FOO';

    $this->decoratedFormState->unsetValue($key)
      ->shouldBeCalled();

    $this->assertSame($this->formStateDecoratorBase, $this->formStateDecoratorBase->unsetValue($key));
  }

  /** * @covers ::hasValue */
  public function testHasValue() {
    $key = ['foo', 'bar'];
    $has = TRUE;

    
public function addCleanValueKey($cleanValueKey) {
    $keys = $this->getCleanValueKeys();
    $this->setCleanValueKeys(array_merge((array) $keys[$cleanValueKey]));
    return $this;
  }

  /** * {@inheritdoc} */
  public function cleanValues() {
    foreach ($this->getCleanValueKeys() as $value) {
      $this->unsetValue($value);
    }

    // Remove button values.     // \Drupal::formBuilder()->doBuildForm() collects all button elements in a     // form. We remove the button value separately for each button element.     foreach ($this->getButtons() as $button) {
      // Remove this button's value from the submitted form values by finding       // the value corresponding to this button.       // We iterate over the #parents of this button and move a reference to       // each parent in self::getValues(). For example, if #parents is:       // @code

    if ($this->isAGroup()) {
      $this->buildGroupValidate($form$form_state);
    }
  }

  /** * Simple submit handler. */
  public function submitOptionsForm(&$form, FormStateInterface $form_state) {
    // Do not store these values.     $form_state->unsetValue('expose_button');
    $form_state->unsetValue('group_button');

    if (!$this->isAGroup()) {
      $this->operatorSubmit($form$form_state);
      $this->valueSubmit($form$form_state);
    }
    if (!empty($this->options['exposed'])) {
      $this->submitExposeForm($form$form_state);
    }
    if ($this->isAGroup()) {
      $this->buildGroupSubmit($form$form_state);
    }

  public function setValue($key$value) {
    $this->decoratedFormState->setValue($key$value);

    return $this;
  }

  /** * {@inheritdoc} */
  public function unsetValue($key) {
    $this->decoratedFormState->unsetValue($key);

    return $this;
  }

  /** * {@inheritdoc} */
  public function hasValue($key) {
    return $this->decoratedFormState->hasValue($key);
  }

  

  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.');
  }

  /** * Tests existence of array key. */
// Check for a new uploaded favicon.       if (isset($form['favicon'])) {
        $file = _file_save_upload_from_form($form['favicon']['settings']['favicon_upload']$form_state, 0);
        if ($file) {
          // Put the temporary file in form_values so we can save it on submit.           $form_state->setValue('favicon_upload', $file);
        }
      }

      // When intending to use the default logo, unset the logo_path.       if ($form_state->getValue('default_logo')) {
        $form_state->unsetValue('logo_path');
      }

      // When intending to use the default favicon, unset the favicon_path.       if ($form_state->getValue('default_favicon')) {
        $form_state->unsetValue('favicon_path');
      }

      // If the user provided a path for a logo or favicon file, make sure a file       // exists at that path.       if ($form_state->getValue('logo_path')) {
        $path = $this->validatePath($form_state->getValue('logo_path'));
        
// If no checkboxes were checked for 'target_bundles', store NULL ("all     // bundles are referenceable") rather than empty array ("no bundle is     // referenceable" - typically happens when all referenceable bundles have     // been deleted).     if ($form_state->getValue(['settings', 'handler_settings', 'target_bundles']) === []) {
      $form_state->setValue(['settings', 'handler_settings', 'target_bundles'], NULL);
    }

    // Don't store the 'target_bundles_update' button value into the field     // config settings.     $form_state->unsetValue(['settings', 'handler_settings', 'target_bundles_update']);
  }

  /** * Form element validation handler; Filters the #value property of an element. */
  public static function elementValidateFilter(&$element, FormStateInterface $form_state) {
    $element['#value'] = array_filter($element['#value']);
    $form_state->setValueForElement($element$element['#value']);
  }

  /** * {@inheritdoc} */
Home | Imprint | This part of the site doesn't use cookies.