getCompleteFormState example


  public function isNegated() {
    return !empty($this->configuration['negate']);
  }

  /** * {@inheritdoc} */
  public function buildConfigurationForm(array $form, FormStateInterface $form_state) {
    if ($form_state instanceof SubformStateInterface) {
      $form_state = $form_state->getCompleteFormState();
    }
    $contexts = $form_state->getTemporaryValue('gathered_contexts') ?: [];
    $form['context_mapping'] = $this->addContextAssignmentElement($this$contexts);
    $form['negate'] = [
      '#type' => 'checkbox',
      '#title' => $this->t('Negate the condition'),
      '#default_value' => $this->configuration['negate'],
    ];
    return $form;
  }

  
$form_item_name = static::mapPairViolationPropertyPathsToFormNames($violation->getPropertyPath()$form);
      // When adding a toolbar item, it is possible that not all conditions for       // using it have been met yet. FormBuilder refuses to rebuild forms when a       // validation error is present. But to meet the condition for the toolbar       // item, configuration must be set in a vertical tab that must still       // appear. Work-around: reduce the validation error to a warning message.       // @see \Drupal\ckeditor5\Plugin\Validation\Constraint\ToolbarItemConditionsMetConstraintValidator       if ($form_state->isRedirectDisabled() && $form_item_name === 'editor][settings][toolbar][items') {
        $this->messenger()->addWarning($violation->getMessage());
        continue;
      }
      $form_state->getCompleteFormState()->setErrorByName($form_item_name$violation->getMessage());
    }

    // Pass it on to ::submitConfigurationForm().     $form_state->get('editor')->setSettings($settings);

    // Provide the validated eventual pair in form state to     // ::getGeneratedAllowedHtmlValue(), to update filter_html's     // "allowed_html".     $form_state->set('ckeditor5_validated_pair', $eventual_editor_and_format);

    assert(TRUE === $this->checkConfigSchema(\Drupal::getContainer()->get('config.typed'), 'editor.editor.id_does_not_matter', $submitted_editor->toArray()), 'Schema errors: ' . print_r($this->checkConfigSchema(\Drupal::getContainer()->get('config.typed'), 'editor.editor.id_does_not_matter', $submitted_editor->toArray()), TRUE));
  }
elseif (!is_array($values)) {
      throw new \UnexpectedValueException('The form state values do not belong to the subform.');
    }

    return $values;
  }

  /** * {@inheritdoc} */
  public function getCompleteFormState() {
    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);
  }

    ];
    return $data;
  }

  /** * @covers ::getCompleteFormState */
  public function testGetCompleteFormStateWithParentCompleteForm() {
    $parent_form_state = $this->prophesize(FormStateInterface::class);
    $subform_state = SubformState::createForSubform($this->parentForm['dog']$this->parentForm, $parent_form_state->reveal());
    $this->assertSame($parent_form_state->reveal()$subform_state->getCompleteFormState());
  }

  /** * @covers ::getCompleteFormState */
  public function testGetCompleteFormStateWithParentSubform() {
    $complete_form_state = $this->prophesize(FormStateInterface::class);
    $parent_form_state = $this->prophesize(SubformStateInterface::class);
    $parent_form_state->getCompleteFormState()
      ->willReturn($complete_form_state->reveal())
      ->shouldBeCalled();
    
return $element;
  }

  /** * {@inheritdoc} */
  public function blockValidate($form, FormStateInterface $form_state) {
    $block_form = $form['block_form'];
    /** @var \Drupal\block_content\BlockContentInterface $block */
    $block = $block_form['#block'];
    $form_display = EntityFormDisplay::collectRenderDisplay($block, 'edit');
    $complete_form_state = $form_state instanceof SubformStateInterface ? $form_state->getCompleteFormState() : $form_state;
    $form_display->extractFormValues($block$block_form$complete_form_state);
    $form_display->validateFormValues($block$block_form$complete_form_state);
    // @todo Remove when https://www.drupal.org/project/drupal/issues/2948549 is closed.     $form_state->setTemporaryValue('block_form_parents', $block_form['#parents']);
  }

  /** * {@inheritdoc} */
  public function blockSubmit($form, FormStateInterface $form_state) {
    $this->configuration['view_mode'] = $form_state->getValue('view_mode');

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