function EntityTest::baseFieldDefinitions

Same name and namespace in other branches
  1. 9 core/modules/system/tests/modules/entity_test/src/Entity/EntityTest.php \Drupal\entity_test\Entity\EntityTest::baseFieldDefinitions()
  2. 8.9.x core/modules/system/tests/modules/entity_test/src/Entity/EntityTest.php \Drupal\entity_test\Entity\EntityTest::baseFieldDefinitions()
  3. 10 core/modules/system/tests/modules/entity_test/src/Entity/EntityTest.php \Drupal\entity_test\Entity\EntityTest::baseFieldDefinitions()

Overrides ContentEntityBase::baseFieldDefinitions

16 calls to EntityTest::baseFieldDefinitions()
CommentTestBaseField::baseFieldDefinitions in core/modules/comment/tests/modules/comment_base_field_test/src/Entity/CommentTestBaseField.php
EntitySerializedField::baseFieldDefinitions in core/modules/system/tests/modules/entity_test/src/Entity/EntitySerializedField.php
EntityTestBaseFieldDisplay::baseFieldDefinitions in core/modules/system/tests/modules/entity_test/src/Entity/EntityTestBaseFieldDisplay.php
EntityTestCompositeConstraint::baseFieldDefinitions in core/modules/system/tests/modules/entity_test/src/Entity/EntityTestCompositeConstraint.php
EntityTestComputedBundleField::baseFieldDefinitions in core/modules/system/tests/modules/entity_test/src/Entity/EntityTestComputedBundleField.php

... See full list

16 methods override EntityTest::baseFieldDefinitions()
CommentTestBaseField::baseFieldDefinitions in core/modules/comment/tests/modules/comment_base_field_test/src/Entity/CommentTestBaseField.php
EntitySerializedField::baseFieldDefinitions in core/modules/system/tests/modules/entity_test/src/Entity/EntitySerializedField.php
EntityTestBaseFieldDisplay::baseFieldDefinitions in core/modules/system/tests/modules/entity_test/src/Entity/EntityTestBaseFieldDisplay.php
EntityTestCompositeConstraint::baseFieldDefinitions in core/modules/system/tests/modules/entity_test/src/Entity/EntityTestCompositeConstraint.php
EntityTestComputedBundleField::baseFieldDefinitions in core/modules/system/tests/modules/entity_test/src/Entity/EntityTestComputedBundleField.php

... See full list

File

core/modules/system/tests/modules/entity_test/src/Entity/EntityTest.php, line 69

Class

EntityTest
Defines the test entity class.

Namespace

Drupal\entity_test\Entity

Code

public static function baseFieldDefinitions(EntityTypeInterface $entity_type) {
    $fields = parent::baseFieldDefinitions($entity_type);
    $fields['name'] = BaseFieldDefinition::create('string')->setLabel(t('Name'))
        ->setDescription(t('The name of the test entity.'))
        ->setTranslatable(TRUE)
        ->setSetting('max_length', 64)
        ->setDisplayOptions('view', [
        'label' => 'hidden',
        'type' => 'string',
        'weight' => -5,
    ])
        ->setDisplayOptions('form', [
        'type' => 'string_textfield',
        'weight' => -5,
    ]);
    $fields['created'] = BaseFieldDefinition::create('created')->setLabel(t('Authored on'))
        ->setDescription(t('Time the entity was created'))
        ->setTranslatable(TRUE);
    $fields['user_id'] = BaseFieldDefinition::create('entity_reference')->setLabel(t('User ID'))
        ->setDescription(t('The ID of the associated user.'))
        ->setSetting('target_type', 'user')
        ->setSetting('handler', 'default')
        ->setDefaultValue([
        0 => [
            'target_id' => 1,
        ],
    ])
        ->setTranslatable(TRUE)
        ->setDisplayOptions('form', [
        'type' => 'entity_reference_autocomplete',
        'weight' => -1,
        'settings' => [
            'match_operator' => 'CONTAINS',
            'size' => '60',
            'placeholder' => '',
        ],
    ]);
    return $fields + \Drupal::state()->get($entity_type->id() . '.additional_base_field_definitions', []);
}

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