EntityTestConstraintViolation.php

Same filename and directory in other branches
  1. 9 core/modules/system/tests/modules/entity_test/src/Entity/EntityTestConstraintViolation.php
  2. 8.9.x core/modules/system/tests/modules/entity_test/src/Entity/EntityTestConstraintViolation.php
  3. 10 core/modules/system/tests/modules/entity_test/src/Entity/EntityTestConstraintViolation.php

Namespace

Drupal\entity_test\Entity

File

core/modules/system/tests/modules/entity_test/src/Entity/EntityTestConstraintViolation.php

View source
<?php

namespace Drupal\entity_test\Entity;

use Drupal\Core\Entity\EntityTypeInterface;
use Drupal\Core\Field\BaseFieldDefinition;

/**
 * Defines the test entity class for testing entity constraint violations.
 *
 * @ContentEntityType(
 *   id = "entity_test_constraint_violation",
 *   label = @Translation("Test entity constraint violation"),
 *   handlers = {
 *     "form" = {
 *       "default" = "Drupal\entity_test\EntityTestForm"
 *     }
 *   },
 *   base_table = "entity_test_constraint_violation",
 *   persistent_cache = FALSE,
 *   entity_keys = {
 *     "id" = "id",
 *     "uuid" = "uuid",
 *     "bundle" = "type",
 *     "label" = "name"
 *   }
 * )
 */
class EntityTestConstraintViolation extends EntityTest {
    
    /**
     * {@inheritdoc}
     */
    public static function baseFieldDefinitions(EntityTypeInterface $entity_type) {
        $fields = parent::baseFieldDefinitions($entity_type);
        $fields['name']->setDisplayOptions('form', [
            'type' => 'string',
            'weight' => 0,
        ]);
        $fields['name']->addConstraint('FieldWidgetConstraint', []);
        // Add a field that uses a widget with a custom implementation for
        // \Drupal\Core\Field\WidgetInterface::errorElement().
        $fields['test_field'] = BaseFieldDefinition::create('integer')->setLabel(t('Test field'))
            ->setDisplayOptions('form', [
            'type' => 'number',
            'weight' => 1,
        ])
            ->addConstraint('FieldWidgetConstraint', []);
        return $fields;
    }

}

Classes

Title Deprecated Summary
EntityTestConstraintViolation Defines the test entity class for testing entity constraint violations.

Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.