function EntityTestUpdate::baseFieldDefinitions

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

Overrides ContentEntityBase::baseFieldDefinitions

1 call to EntityTestUpdate::baseFieldDefinitions()
EntityDefinitionUpdateTest::testLongNameFieldIndexes in core/tests/Drupal/KernelTests/Core/Entity/EntityDefinitionUpdateTest.php
Check that field schema is correctly handled with long-named fields.

File

core/modules/system/tests/modules/entity_test_update/src/Entity/EntityTestUpdate.php, line 55

Class

EntityTestUpdate
Defines the test entity class for testing definition and schema updates.

Namespace

Drupal\entity_test_update\Entity

Code

public static function baseFieldDefinitions(EntityTypeInterface $entity_type) {
    // This entity type is used for generating database dumps from Drupal
    // 8.0.0-rc1, which didn't have the entity key base fields defined in
    // the parent class (ContentEntityBase), so we have to duplicate them here.
    $fields[$entity_type->getKey('id')] = BaseFieldDefinition::create('integer')->setLabel(new TranslatableMarkup('ID'))
        ->setDescription(new TranslatableMarkup('The ID of the test entity.'))
        ->setReadOnly(TRUE)
        ->setSetting('unsigned', TRUE);
    $fields[$entity_type->getKey('uuid')] = BaseFieldDefinition::create('uuid')->setLabel(new TranslatableMarkup('UUID'))
        ->setDescription(new TranslatableMarkup('The UUID of the test entity.'))
        ->setReadOnly(TRUE);
    $fields[$entity_type->getKey('bundle')] = BaseFieldDefinition::create('string')->setLabel(new TranslatableMarkup('Type'))
        ->setDescription(new TranslatableMarkup('The bundle of the test entity.'))
        ->setRequired(TRUE);
    if ($entity_type->hasKey('revision')) {
        $fields[$entity_type->getKey('revision')] = BaseFieldDefinition::create('integer')->setLabel(new TranslatableMarkup('Revision ID'))
            ->setReadOnly(TRUE)
            ->setSetting('unsigned', TRUE);
    }
    $fields[$entity_type->getKey('langcode')] = BaseFieldDefinition::create('language')->setLabel(new TranslatableMarkup('Language'));
    if ($entity_type->isRevisionable()) {
        $fields[$entity_type->getKey('langcode')]
            ->setRevisionable(TRUE);
    }
    if ($entity_type->isTranslatable()) {
        $fields[$entity_type->getKey('langcode')]
            ->setTranslatable(TRUE);
    }
    $fields['name'] = BaseFieldDefinition::create('string')->setLabel(new TranslatableMarkup('Name'))
        ->setDescription(new TranslatableMarkup('The name of the test entity.'))
        ->setTranslatable(TRUE)
        ->setRevisionable(TRUE)
        ->setSetting('max_length', 32)
        ->setDisplayOptions('view', [
        'label' => 'hidden',
        'type' => 'string',
        'weight' => -5,
    ])
        ->setDisplayOptions('form', [
        'type' => 'string_textfield',
        'weight' => -5,
    ]);
    $fields['test_single_property'] = BaseFieldDefinition::create('string')->setLabel(new TranslatableMarkup('Field with a single property'))
        ->setTranslatable(TRUE)
        ->setRevisionable(TRUE);
    $fields['test_multiple_properties'] = BaseFieldDefinition::create('multi_value_test')->setLabel(new TranslatableMarkup('Field with multiple properties'))
        ->setTranslatable(TRUE)
        ->setRevisionable(TRUE);
    $fields['test_single_property_multiple_values'] = BaseFieldDefinition::create('string')->setLabel(new TranslatableMarkup('Field with a single property and multiple values'))
        ->setCardinality(2)
        ->setTranslatable(TRUE)
        ->setRevisionable(TRUE);
    $fields['test_multiple_properties_multiple_values'] = BaseFieldDefinition::create('multi_value_test')->setLabel(new TranslatableMarkup('Field with multiple properties and multiple values'))
        ->setCardinality(2)
        ->setTranslatable(TRUE)
        ->setRevisionable(TRUE);
    $fields['test_non_rev_field'] = BaseFieldDefinition::create('string')->setLabel(new TranslatableMarkup('Non Revisionable Field'))
        ->setDescription(new TranslatableMarkup('A non-revisionable test field.'))
        ->setCardinality(1)
        ->setRevisionable(FALSE)
        ->setTranslatable(TRUE);
    $fields['test_non_mul_field'] = BaseFieldDefinition::create('string')->setLabel(new TranslatableMarkup('Non Translatable Field'))
        ->setDescription(new TranslatableMarkup('A non-translatable test field.'))
        ->setCardinality(1)
        ->setRevisionable(TRUE)
        ->setTranslatable(FALSE);
    $fields['test_non_mulrev_field'] = BaseFieldDefinition::create('string')->setLabel(new TranslatableMarkup('Non Revisionable and Translatable Field'))
        ->setDescription(new TranslatableMarkup('A non-revisionable and non-translatable test field.'))
        ->setCardinality(1)
        ->setRevisionable(FALSE)
        ->setTranslatable(FALSE);
    $fields += \Drupal::state()->get('entity_test_update.additional_base_field_definitions', []);
    return $fields;
}

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