setLimitValidationErrors example

return $this->decoratedFormState instanceof SubformStateInterface ? $this->decoratedFormState->getCompleteFormState() : $this->decoratedFormState;
  }

  /** * {@inheritdoc} */
  public function setLimitValidationErrors($limit_validation_errors) {
    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')));

    }
    

    }

    // Validate the current input.     if (!isset($elements['#validated']) || !$elements['#validated']) {
      // The following errors are always shown.       if (isset($elements['#needs_validation'])) {
        $this->performRequiredValidation($elements$form_state);
      }

      // Set up the limited validation for errors.       $form_state->setLimitValidationErrors($this->determineLimitValidationErrors($form_state));

      // Make sure a value is passed when the field is required.       if (isset($elements['#needs_validation']) && $elements['#required']) {
        // A simple call to empty() will not cut it here as some fields, like         // checkboxes, can return a valid value of '0'. Instead, check the         // length if it's a string, and the item count if it's an array.         // An unchecked checkbox has a #value of integer 0, different than         // string '0', which could be a valid value.         $is_countable = is_array($elements['#value']) || $elements['#value'] instanceof \Countable;
        $is_empty_multiple = $is_countable && count($elements['#value']) == 0;
        $is_empty_string = (is_string($elements['#value']) && mb_strlen(trim($elements['#value'])) == 0);
        
/** * {@inheritdoc} */
  public function hasFileElement() {
    return $this->decoratedFormState->hasFileElement();
  }

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

    return $this;
  }

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

  
->shouldBeCalled();

    $this->assertSame($has_file_element$this->formStateDecoratorBase->hasFileElement());
  }

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

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

  /** * @covers ::getLimitValidationErrors * * @dataProvider providerLimitValidationErrors */
  public function testGetLimitValidationErrors($limit_validation_errors) {
    
'foo' => 'Fail 1', 'foo][bar' => 'Fail 2']['foo', 'bar'], 'Fail 1'],
    ];
  }

  /** * @covers ::setErrorByName * * @dataProvider providerTestSetErrorByName */
  public function testSetErrorByName($limit_validation_errors$expected_errors) {
    $form_state = new FormState();
    $form_state->setLimitValidationErrors($limit_validation_errors);
    $form_state->clearErrors();

    $form_state->setErrorByName('test', 'Fail 1');
    $form_state->setErrorByName('test', 'Fail 2');
    $form_state->setErrorByName('options');

    $this->assertSame(!empty($expected_errors)$form_state::hasAnyErrors());
    $this->assertSame($expected_errors$form_state->getErrors());
  }

  public function providerTestSetErrorByName() {
    
/** * Validate callback for alt and title field, if the user wants them required. * * This is separated in a validate function instead of a #required flag to * avoid being validated on the process callback. */
  public static function validateRequiredFields($element, FormStateInterface $form_state) {
    // Only do validation if the function is triggered from other places than     // the image process form.     $triggering_element = $form_state->getTriggeringElement();
    if (!empty($triggering_element['#submit']) && in_array('file_managed_file_submit', $triggering_element['#submit'], TRUE)) {
      $form_state->setLimitValidationErrors([]);
    }
  }

  /** * {@inheritdoc} */
  public function calculateDependencies() {
    $dependencies = parent::calculateDependencies();
    $style_id = $this->getSetting('preview_image_style');
    /** @var \Drupal\image\ImageStyleInterface $style */
    if ($style_id && $style = ImageStyle::load($style_id)) {
      
$this->assertSame($complete_form_state->reveal()$subform_state->getCompleteFormState());
  }

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

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

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

  /** * @covers ::getLimitValidationErrors */
  public function testGetLimitValidationErrors() {
    $parent_limit_validation_errors = ['dog', 'name'];
    
Home | Imprint | This part of the site doesn't use cookies.