function EntityUpdateToPublishableTest::updateEntityTypeDefinition
Updates the 'entity_test_update' entity type to translatable and publishable.
1 call to EntityUpdateToPublishableTest::updateEntityTypeDefinition()
- EntityUpdateToPublishableTest::testConvertToPublishable in core/
modules/ system/ tests/ src/ Functional/ Update/ EntityUpdateToPublishableTest.php - Tests the conversion of an entity type to be publishable.
File
-
core/
modules/ system/ tests/ src/ Functional/ Update/ EntityUpdateToPublishableTest.php, line 147
Class
- EntityUpdateToPublishableTest
- Tests the upgrade path for making an entity publishable.
Namespace
Drupal\Tests\system\Functional\UpdateCode
protected function updateEntityTypeDefinition() {
$entity_type = clone $this->entityTypeManager
->getDefinition('entity_test_update');
$keys = $entity_type->getKeys();
$keys['published'] = 'status';
$entity_type->set('entity_keys', $keys);
$entity_type->set('translatable', TRUE);
$entity_type->set('data_table', 'entity_test_update_data');
$this->state
->set('entity_test_update.entity_type', $entity_type);
// Add the status field to the entity type.
$status = BaseFieldDefinition::create('boolean')->setLabel(t('Publishing status'))
->setDescription(t('A boolean indicating the published state.'))
->setRevisionable(TRUE)
->setTranslatable(TRUE)
->setRequired(TRUE)
->setDefaultValue(TRUE);
$this->state
->set('entity_test_update.additional_base_field_definitions', [
'status' => $status,
]);
$this->entityTypeManager
->clearCachedDefinitions();
}
Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.