protected function FieldWidgetConstraintValidatorTest::getErrorsForEntity in Drupal 10
Same name and namespace in other branches
- 8 core/tests/Drupal/KernelTests/Core/Entity/FieldWidgetConstraintValidatorTest.php \Drupal\KernelTests\Core\Entity\FieldWidgetConstraintValidatorTest::getErrorsForEntity()
- 9 core/tests/Drupal/KernelTests/Core/Entity/FieldWidgetConstraintValidatorTest.php \Drupal\KernelTests\Core\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.
File
- core/
tests/ Drupal/ KernelTests/ Core/ Entity/ FieldWidgetConstraintValidatorTest.php, line 76
Class
- FieldWidgetConstraintValidatorTest
- Tests validation constraints for FieldWidgetConstraintValidatorTest.
Namespace
Drupal\KernelTests\Core\EntityCode
protected function getErrorsForEntity(EntityInterface $entity, $hidden_fields = []) {
$entity_type_id = 'entity_test_composite_constraint';
$display = \Drupal::service('entity_display.repository')
->getFormDisplay($entity_type_id, $entity_type_id);
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::entityTypeManager()
->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();
}