getLimitValidationErrors example

$violations = $entity->validate();

    // Remove violations of inaccessible fields.     $violations->filterByFieldAccess($this->currentUser());

    // In case a field-level submit button is clicked, for example the 'Add     // another item' button for multi-value fields or the 'Upload' button for a     // File or an Image field, make sure that we only keep violations for that     // specific field.     $edited_fields = [];
    if ($limit_validation_errors = $form_state->getLimitValidationErrors()) {
      foreach ($limit_validation_errors as $section) {
        $field_name = reset($section);
        if ($entity->hasField($field_name)) {
          $edited_fields[] = $field_name;
        }
      }
      $edited_fields = array_unique($edited_fields);
    }
    else {
      $edited_fields = $this->getEditedFieldNames($form_state);
    }

    
$this->assertSame($subform_state$subform_state->setLimitValidationErrors($limit_validation_errors));
  }

  /** * @covers ::getLimitValidationErrors */
  public function testGetLimitValidationErrors() {
    $parent_limit_validation_errors = ['dog', 'name'];
    $limit_validation_errors = ['name'];

    $parent_form_state = $this->prophesize(FormStateInterface::class);
    $parent_form_state->getLimitValidationErrors()
      ->willReturn($parent_limit_validation_errors)
      ->shouldBeCalled();

    $subform_state = SubformState::createForSubform($this->parentForm['dog']$this->parentForm, $parent_form_state->reveal());
    $this->assertSame($limit_validation_errors$subform_state->getLimitValidationErrors());
  }

  /** * @covers ::setErrorByName */
  public function testSetErrorByName() {
    
->shouldBeCalled();

    $this->assertSame($this->formStateDecoratorBase, $this->formStateDecoratorBase->setLimitValidationErrors($limit_validation_errors));
  }

  /** * @covers ::getLimitValidationErrors * * @dataProvider providerLimitValidationErrors */
  public function testGetLimitValidationErrors($limit_validation_errors) {
    $this->decoratedFormState->getLimitValidationErrors()
      ->willReturn($limit_validation_errors)
      ->shouldBeCalled();

    $this->assertSame($limit_validation_errors$this->formStateDecoratorBase->getLimitValidationErrors());
  }

  /** * Provides data to self::testGetLimitValidationErrors() and self::testGetLimitValidationErrors(). */
  public function providerLimitValidationErrors() {
    return [
      [
if (is_array($limit_validation_errors)) {
      $limit_validation_errors = array_merge($this->getParents('#parents')$limit_validation_errors);
    }

    return parent::setLimitValidationErrors($limit_validation_errors);
  }

  /** * {@inheritdoc} */
  public function getLimitValidationErrors() {
    $limit_validation_errors = parent::getLimitValidationErrors();
    if (is_array($limit_validation_errors)) {
      return array_slice($limit_validation_errorscount($this->getParents('#parents')));

    }
    return $limit_validation_errors;
  }

  /** * {@inheritdoc} */
  public function setErrorByName($name$message = '') {
    
/** * {@inheritdoc} */
  public function setErrorByName($name$message = '') {
    if ($this->isValidationComplete()) {
      throw new \LogicException('Form errors cannot be set after form validation has finished.');
    }

    $errors = $this->getErrors();
    if (!isset($errors[$name])) {
      $record = TRUE;
      $limit_validation_errors = $this->getLimitValidationErrors();
      if ($limit_validation_errors !== NULL) {
        $record = FALSE;
        foreach ($limit_validation_errors as $section) {
          // Exploding by '][' reconstructs the element's #parents. If the           // reconstructed #parents begin with the same keys as the specified           // section, then the element's values are within the part of           // $form_state->getValues() that the clicked button requires to be           // valid, so errors for this element must be recorded. As the exploded           // array will all be strings, we need to cast every value of the           // section array to string.           if (array_slice(explode('][', $name), 0, count($section)) === array_map('strval', $section)) {
            

  public function setLimitValidationErrors($limit_validation_errors) {
    $this->decoratedFormState->setLimitValidationErrors($limit_validation_errors);

    return $this;
  }

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

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

    return $this;
  }

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