class ViewsTestEntity
Same name and namespace in other branches
- 11.x core/modules/views/tests/src/Kernel/Entity/EntityViewsDataTest.php \Drupal\Tests\views\Kernel\Entity\ViewsTestEntity
- 10 core/modules/views/tests/src/Kernel/Entity/EntityViewsDataTest.php \Drupal\Tests\views\Kernel\Entity\ViewsTestEntity
Generic entity class for our test entity types.
Allows mocked base field definitions.
Hierarchy
- class \Drupal\Core\Entity\EntityBase implements \Drupal\Core\Entity\EntityInterface uses \Drupal\Core\Cache\RefinableCacheableDependencyTrait, \Drupal\Core\DependencyInjection\DependencySerializationTrait
- class \Drupal\Core\Entity\ContentEntityBase implements \Drupal\Core\Entity\IteratorAggregate, \Drupal\Core\Entity\ContentEntityInterface, \Drupal\Core\TypedData\TranslationStatusInterface uses \Drupal\Core\Entity\EntityChangesDetectionTrait, \Drupal\Core\Entity\SynchronizableEntityTrait extends \Drupal\Core\Entity\EntityBase
- class \Drupal\Tests\views\Kernel\Entity\ViewsTestEntity extends \Drupal\Core\Entity\ContentEntityBase
- class \Drupal\Core\Entity\ContentEntityBase implements \Drupal\Core\Entity\IteratorAggregate, \Drupal\Core\Entity\ContentEntityInterface, \Drupal\Core\TypedData\TranslationStatusInterface uses \Drupal\Core\Entity\EntityChangesDetectionTrait, \Drupal\Core\Entity\SynchronizableEntityTrait extends \Drupal\Core\Entity\EntityBase
Expanded class hierarchy of ViewsTestEntity
File
-
core/
modules/ views/ tests/ src/ Kernel/ Entity/ EntityViewsDataTest.php, line 831
Namespace
Drupal\Tests\views\Kernel\EntityView source
class ViewsTestEntity extends ContentEntityBase {
/**
* The mocked base fields for test entity types.
*
* An array keyed by entity type ID, whose values are arrays of base field
* definitions.
*
* @var array
*/
protected static $mockedBaseFieldDefinitions = [];
/**
* Sets up the mocked base field definitions.
*
* @param string $entity_type_id
* The entity type ID.
* @param array $definitions
* The array of base field definitions to mock. These are added to the
* defaults ones from the parent class.
*/
public static function setMockedBaseFieldDefinitions(string $entity_type_id, array $definitions) {
static::$mockedBaseFieldDefinitions[$entity_type_id] = $definitions;
}
/**
* {@inheritdoc}
*/
public static function baseFieldDefinitions(EntityTypeInterface $entity_type) {
$fields = parent::baseFieldDefinitions($entity_type);
if (isset(static::$mockedBaseFieldDefinitions[$entity_type->id()])) {
$mocked_fields = static::$mockedBaseFieldDefinitions[$entity_type->id()];
// Mocked fields take priority over ones from the base class.
$fields = $mocked_fields + $fields;
}
return $fields;
}
}
Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.