You are here

protected function FieldWidgetConstraintValidatorTest::getErrorsForEntity in Zircon Profile 8

Same name and namespace in other branches
  1. 8.0 core/modules/system/src/Tests/Entity/FieldWidgetConstraintValidatorTest.php \Drupal\system\Tests\Entity\FieldWidgetConstraintValidatorTest::getErrorsForEntity()

Gets the form errors for a given entity.

Parameters

\Drupal\Core\Entity\EntityInterface $entity: The entity

array $hidden_fields: (optional) A list of hidden fields.

Return value

array The form errors.

2 calls to FieldWidgetConstraintValidatorTest::getErrorsForEntity()
FieldWidgetConstraintValidatorTest::testEntityLevelConstraintValidation in core/modules/system/src/Tests/Entity/FieldWidgetConstraintValidatorTest.php
Tests entity level constraint validation.
FieldWidgetConstraintValidatorTest::testValidationWithCompositeConstraint in core/modules/system/src/Tests/Entity/FieldWidgetConstraintValidatorTest.php
Tests widget constraint validation with composite constraints.

File

core/modules/system/src/Tests/Entity/FieldWidgetConstraintValidatorTest.php, line 75
Contains \Drupal\system\Tests\Entity\FieldWidgetConstraintValidatorTest.

Class

FieldWidgetConstraintValidatorTest
Tests validation constraints for FieldWidgetConstraintValidatorTest.

Namespace

Drupal\system\Tests\Entity

Code

protected function getErrorsForEntity(EntityInterface $entity, $hidden_fields = []) {
  $entity_type_id = 'entity_test_composite_constraint';
  $display = entity_get_form_display($entity_type_id, $entity_type_id, 'default');
  foreach ($hidden_fields as $hidden_field) {
    $display
      ->removeComponent($hidden_field);
  }
  $form = [];
  $form_state = new FormState();
  $display
    ->buildForm($entity, $form, $form_state);
  $form_state
    ->setFormObject(\Drupal::entityManager()
    ->getFormObject($entity_type_id, 'default'));
  \Drupal::formBuilder()
    ->prepareForm('field_test_entity_form', $form, $form_state);
  \Drupal::formBuilder()
    ->processForm('field_test_entity_form', $form, $form_state);

  // Validate the field constraint.

  /** @var \Drupal\Core\Entity\ContentEntityFormInterface $form_object */
  $form_object = $form_state
    ->getFormObject();
  $form_object
    ->setEntity($entity)
    ->setFormDisplay($display, $form_state)
    ->validateForm($form, $form_state);
  return $form_state
    ->getErrors();
}