function EntityTestUniqueConstraint::baseFieldDefinitions

Same name in other branches
  1. 10 core/modules/system/tests/modules/entity_test/src/Entity/EntityTestUniqueConstraint.php \Drupal\entity_test\Entity\EntityTestUniqueConstraint::baseFieldDefinitions()

Overrides EntityTest::baseFieldDefinitions

File

core/modules/system/tests/modules/entity_test/src/Entity/EntityTestUniqueConstraint.php, line 42

Class

EntityTestUniqueConstraint
Defines a test entity class for unique constraint.

Namespace

Drupal\entity_test\Entity

Code

public static function baseFieldDefinitions(EntityTypeInterface $entity_type) {
    $fields = parent::baseFieldDefinitions($entity_type);
    $fields['field_test_text'] = BaseFieldDefinition::create('string')->setLabel(t('unique_field_test'))
        ->setCardinality(3)
        ->addConstraint('UniqueField');
    $fields['field_test_reference'] = BaseFieldDefinition::create('entity_reference')->setLabel(t('unique_reference_test'))
        ->setCardinality(2)
        ->addConstraint('UniqueField')
        ->setSetting('target_type', 'user');
    return $fields;
}

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