Updated to Drupal 8.5. Core Media not yet in use.
[yaffs-website] / web / core / modules / system / tests / modules / entity_test / src / Entity / EntityTestConstraintViolation.php
1 <?php
2
3 namespace Drupal\entity_test\Entity;
4
5 use Drupal\Core\Entity\EntityTypeInterface;
6 use Drupal\Core\Field\BaseFieldDefinition;
7
8 /**
9  * Defines the test entity class for testing entity constraint violations.
10  *
11  * @ContentEntityType(
12  *   id = "entity_test_constraint_violation",
13  *   label = @Translation("Test entity constraint violation"),
14  *   handlers = {
15  *     "form" = {
16  *       "default" = "Drupal\entity_test\EntityTestForm"
17  *     }
18  *   },
19  *   base_table = "entity_test_constraint_violation",
20  *   persistent_cache = FALSE,
21  *   entity_keys = {
22  *     "id" = "id",
23  *     "uuid" = "uuid",
24  *     "bundle" = "type",
25  *     "label" = "name"
26  *   }
27  * )
28  */
29 class EntityTestConstraintViolation extends EntityTest {
30
31   /**
32    * {@inheritdoc}
33    */
34   public static function baseFieldDefinitions(EntityTypeInterface $entity_type) {
35     $fields = parent::baseFieldDefinitions($entity_type);
36
37     $fields['name']->setDisplayOptions('form', [
38       'type' => 'string',
39       'weight' => 0,
40     ]);
41     $fields['name']->addConstraint('FieldWidgetConstraint', []);
42
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', [
48         'type' => 'number',
49         'weight' => 1,
50       ])
51       ->addConstraint('FieldWidgetConstraint', []);
52
53     return $fields;
54   }
55
56 }