3 namespace Drupal\entity_test\Entity;
5 use Drupal\Core\Entity\EntityTypeInterface;
6 use Drupal\Core\Field\BaseFieldDefinition;
9 * Defines the test entity class for testing entity constraint violations.
12 * id = "entity_test_constraint_violation",
13 * label = @Translation("Test entity constraint violation"),
16 * "default" = "Drupal\entity_test\EntityTestForm"
19 * base_table = "entity_test_constraint_violation",
20 * persistent_cache = FALSE,
29 class EntityTestConstraintViolation extends EntityTest {
34 public static function baseFieldDefinitions(EntityTypeInterface $entity_type) {
35 $fields = parent::baseFieldDefinitions($entity_type);
37 $fields['name']->setDisplayOptions('form', [
41 $fields['name']->addConstraint('FieldWidgetConstraint', []);
43 // Add a field that uses a widget with a custom implementation for
44 // \Drupal\Core\Field\WidgetInterface::errorElement().
45 $fields['test_field'] = BaseFieldDefinition::create('integer')
46 ->setLabel(t('Test field'))
47 ->setDisplayOptions('form', [
51 ->addConstraint('FieldWidgetConstraint', []);