addCleanValueKey example


  public function setCleanValueKeys(array $cleanValueKeys) {
    $this->decoratedFormState->setCleanValueKeys($cleanValueKeys);

    return $this;
  }

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

    return $this;
  }

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

    return $this;
  }
    $name = implode('__', $element['#parents']);
    if ($form_state->hasValue($name . '__active_tab')) {
      $element['#default_tab'] = $form_state->getValue($name . '__active_tab');
    }
    $element[$name . '__active_tab'] = [
      '#type' => 'hidden',
      '#default_value' => $element['#default_tab'],
      '#attributes' => ['class' => ['vertical-tabs__active-tab']],
    ];
    // Clean up the active tab value so it's not accidentally stored in     // settings forms.     $form_state->addCleanValueKey($name . '__active_tab');

    return $element;
  }

}
$form_state = new FormState();
    $form_state->setCleanValueKeys(['key1', 'key2']);
    $this->assertSame($form_state->getCleanValueKeys()['key1', 'key2']);
  }

  /** * @covers ::addCleanValueKey */
  public function testAddCleanValueKey() {
    $form_state = new FormState();
    $form_state->setValue('value_to_clean', 'rainbow_sprinkles');
    $form_state->addCleanValueKey('value_to_clean');
    $this->assertSame($form_state->getCleanValueKeys()['form_id', 'form_token', 'form_build_id', 'op', 'value_to_clean']);
    return $form_state;
  }

  /** * @depends testAddCleanValueKey * * @covers ::cleanValues */
  public function testCleanValues($form_state) {
    $form_state->setValue('value_to_keep', 'magic_ponies');
    
'#value' => 3000,
      '#process' => [[$class, 'cleanValue']],
    ];

    return $form;
  }

  /** * Helper function to clean a value on an element. */
  public static function cleanValue(&$element, FormStateInterface $form_state, &$complete_form) {
    $form_state->addCleanValueKey('wine');
  }

  /** * {@inheritdoc} */
  public function submitForm(array &$form, FormStateInterface $form_state) {
    $form_state->cleanValues();
    // This won't have a proper JSON header, but Drupal doesn't check for that     // anyway so this is fine until it's replaced with a JsonResponse.     print Json::encode($form_state->getValues());
    exit;
  }
->shouldBeCalled();

    $this->assertSame($keys$this->formStateDecoratorBase->getCleanValueKeys());
  }

  /** * @covers ::addCleanValueKey */
  public function testAddCleanValueKey() {
    $key = 'BAR';

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

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

  /** * @covers ::cleanValues */
  public function testCleanValues() {
    $this->decoratedFormState->cleanValues()
      ->shouldBeCalled();

    
Home | Imprint | This part of the site doesn't use cookies.