ContentEntityForm::validateForm

public ContentEntityForm::validateForm(array &$form, FormStateInterface $form_state)

Button-level validation handlers are highly discouraged for entity forms, as they will prevent entity validation from running. If the entity is going to be saved during the form submission, this method should be manually invoked from the button-level validation handler, otherwise an exception will be thrown.

Overrides FormBase::validateForm

File

core/lib/Drupal/Core/Entity/ContentEntityForm.php, line 91

Class

ContentEntityForm
Entity form variant for content entity types.

Namespace

Drupal\Core\Entity

Code

public function validateForm(array &$form, FormStateInterface $form_state) {
  parent::validateForm($form, $form_state);
  /** @var \Drupal\Core\Entity\ContentEntityInterface $entity */
  $entity = $this->buildEntity($form, $form_state);

  $violations = $entity->validate();

  // Remove violations of inaccessible fields and not edited fields.
  $violations
  ->filterByFieldAccess($this->currentUser())
    ->filterByFields(array_diff(array_keys($entity->getFieldDefinitions()), $this->getEditedFieldNames($form_state)));

  $this->flagViolations($violations, $form, $form_state);

  // The entity was validated.
  $entity->setValidationRequired(FALSE);
  $form_state->setTemporaryValue('entity_validated', TRUE);

  return $entity;
}
doc_Drupal
2016-10-29 08:57:17
Comments
Leave a Comment

Please login to continue.