defaultValuesFormValidate example

public function validateForm(array &$form, FormStateInterface $form_state) {
    parent::validateForm($form$form_state);

    // Before proceeding validation, rebuild the entity to make sure it's     // up-to-date. This is needed because element validators may update form     // state, and other validators use the entity for validating the field.     // @todo remove in https://www.drupal.org/project/drupal/issues/3372934.     $this->entity = $this->buildEntity($form$form_state);

    if (isset($form['default_value']) && (!isset($form['set_default_value']) || $form_state->getValue('set_default_value'))) {
      $items = $this->getTypedData($form['#entity']);
      $items->defaultValuesFormValidate($form['default_value']$form$form_state);
    }
  }

  /** * {@inheritdoc} */
  public function submitForm(array &$form, FormStateInterface $form_state) {
    parent::submitForm($form$form_state);

    // Handle the default value.     $default_value = [];
    
$field_name,
      ]);
      foreach ($submitted_values as $delta => $value) {
        if (!in_array($value['format']$allowed_formats, TRUE)) {
          $form_state->setErrorByName(
            "default_value_input][{$field_name}][{$delta}][format",
            $this->t("The selected text format is not allowed.")
          );
        }
      }
    }
    parent::defaultValuesFormValidate($element$form$form_state);
  }

}
->onlyMethods(['defaultValueWidget', 'validate'])
      ->setConstructorArgs([$field_definition])
      ->getMock();
    $field_list->expects($this->any())
      ->method('defaultValueWidget')
      ->willReturn(NULL);
    $field_list->expects($this->never())
      ->method('validate');
    $form = [];
    $form_state = new FormState();

    $field_list->defaultValuesFormValidate([]$form$form_state);
  }

  /** * @covers ::defaultValuesFormSubmit */
  public function testDefaultValuesFormSubmit() {
    $field_definition = $this->createMock(FieldDefinitionInterface::class);
    /** @var \Drupal\Core\Field\FieldItemList|\PHPUnit\Framework\MockObject\MockObject $field_list */
    $field_list = $this->getMockBuilder(FieldItemList::class)
      ->onlyMethods(['defaultValueWidget', 'getValue'])
      ->setConstructorArgs([$field_definition])
      
Home | Imprint | This part of the site doesn't use cookies.