function EntityTestComputedBundleField::bundleFieldDefinitions

Same name and namespace in other branches
  1. 10 core/modules/system/tests/modules/entity_test/src/Entity/EntityTestComputedBundleField.php \Drupal\entity_test\Entity\EntityTestComputedBundleField::bundleFieldDefinitions()

Overrides ContentEntityBase::bundleFieldDefinitions

File

core/modules/system/tests/modules/entity_test/src/Entity/EntityTestComputedBundleField.php, line 66

Class

EntityTestComputedBundleField
An entity used for testing computed bundle field values.

Namespace

Drupal\entity_test\Entity

Code

public static function bundleFieldDefinitions(EntityTypeInterface $entity_type, $bundle, array $base_field_definitions) {
    $fields = parent::bundleFieldDefinitions($entity_type, $bundle, $base_field_definitions);
    $computed_field_bundles = [
        'entity_test_comp_bund_fld_bund',
        'entity_test_comp_bund_fld_bund_2',
    ];
    if (in_array($bundle, $computed_field_bundles, TRUE)) {
        // @todo Use the proper FieldStorageDefinition class instead
        // https://www.drupal.org/node/2280639.
        $storageDefinition = FieldStorageDefinition::create('string')->setName('computed_bundle_field')
            ->setTargetEntityTypeId($entity_type->id())
            ->setComputed(TRUE)
            ->setClass(ComputedTestBundleFieldItemList::class);
        $fields['computed_bundle_field'] = FieldDefinition::createFromFieldStorageDefinition($storageDefinition)->setLabel(t('A computed Bundle Field Test'))
            ->setComputed(TRUE)
            ->setClass(ComputedTestBundleFieldItemList::class);
    }
    return $fields;
}

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