Chris@0: state->set('entity_test_new', TRUE); Chris@0: $this->entityManager->clearCachedDefinitions(); Chris@0: $this->entityDefinitionUpdateManager->applyUpdates(); Chris@0: } Chris@0: Chris@0: /** Chris@0: * Resets the entity type definition. Chris@0: */ Chris@0: protected function resetEntityType() { Chris@0: $this->state->set('entity_test_update.entity_type', NULL); Chris@0: $this->entityManager->clearCachedDefinitions(); Chris@0: $this->entityDefinitionUpdateManager->applyUpdates(); Chris@0: } Chris@0: Chris@0: /** Chris@0: * Updates the 'entity_test_update' entity type to revisionable. Chris@0: */ Chris@0: protected function updateEntityTypeToRevisionable() { Chris@0: $entity_type = clone $this->entityManager->getDefinition('entity_test_update'); Chris@0: Chris@0: $keys = $entity_type->getKeys(); Chris@0: $keys['revision'] = 'revision_id'; Chris@0: $entity_type->set('entity_keys', $keys); Chris@0: $entity_type->set('revision_table', 'entity_test_update_revision'); Chris@0: Chris@0: $this->state->set('entity_test_update.entity_type', $entity_type); Chris@0: } Chris@0: Chris@0: /** Chris@0: * Updates the 'entity_test_update' entity type not revisionable. Chris@0: */ Chris@0: protected function updateEntityTypeToNotRevisionable() { Chris@0: $entity_type = clone $this->entityManager->getDefinition('entity_test_update'); Chris@0: Chris@0: $keys = $entity_type->getKeys(); Chris@0: unset($keys['revision']); Chris@0: $entity_type->set('entity_keys', $keys); Chris@0: $entity_type->set('revision_table', NULL); Chris@0: Chris@0: $this->state->set('entity_test_update.entity_type', $entity_type); Chris@0: } Chris@0: Chris@0: /** Chris@0: * Updates the 'entity_test_update' entity type to translatable. Chris@0: */ Chris@0: protected function updateEntityTypeToTranslatable() { Chris@0: $entity_type = clone $this->entityManager->getDefinition('entity_test_update'); Chris@0: Chris@0: $entity_type->set('translatable', TRUE); Chris@0: $entity_type->set('data_table', 'entity_test_update_data'); Chris@0: Chris@0: if ($entity_type->isRevisionable()) { Chris@0: $entity_type->set('revision_data_table', 'entity_test_update_revision_data'); Chris@0: } Chris@0: Chris@0: $this->state->set('entity_test_update.entity_type', $entity_type); Chris@0: } Chris@0: Chris@0: /** Chris@0: * Updates the 'entity_test_update' entity type to not translatable. Chris@0: */ Chris@0: protected function updateEntityTypeToNotTranslatable() { Chris@0: $entity_type = clone $this->entityManager->getDefinition('entity_test_update'); Chris@0: Chris@0: $entity_type->set('translatable', FALSE); Chris@0: $entity_type->set('data_table', NULL); Chris@0: Chris@0: if ($entity_type->isRevisionable()) { Chris@0: $entity_type->set('revision_data_table', NULL); Chris@0: } Chris@0: Chris@0: $this->state->set('entity_test_update.entity_type', $entity_type); Chris@0: } Chris@0: Chris@0: /** Chris@0: * Updates the 'entity_test_update' entity type to revisionable and Chris@0: * translatable. Chris@0: */ Chris@0: protected function updateEntityTypeToRevisionableAndTranslatable() { Chris@0: $entity_type = clone $this->entityManager->getDefinition('entity_test_update'); Chris@0: Chris@0: $keys = $entity_type->getKeys(); Chris@0: $keys['revision'] = 'revision_id'; Chris@0: $entity_type->set('entity_keys', $keys); Chris@0: $entity_type->set('translatable', TRUE); Chris@0: $entity_type->set('data_table', 'entity_test_update_data'); Chris@0: $entity_type->set('revision_table', 'entity_test_update_revision'); Chris@0: $entity_type->set('revision_data_table', 'entity_test_update_revision_data'); Chris@0: Chris@0: $this->state->set('entity_test_update.entity_type', $entity_type); Chris@0: } Chris@0: Chris@0: /** Chris@0: * Adds a new base field to the 'entity_test_update' entity type. Chris@0: * Chris@0: * @param string $type Chris@0: * (optional) The field type for the new field. Defaults to 'string'. Chris@14: * @param string $entity_type_id Chris@14: * (optional) The entity type ID the base field should be attached to. Chris@14: * Defaults to 'entity_test_update'. Chris@14: * @param bool $is_revisionable Chris@14: * (optional) If the base field should be revisionable or not. Defaults to Chris@14: * FALSE. Chris@0: */ Chris@14: protected function addBaseField($type = 'string', $entity_type_id = 'entity_test_update', $is_revisionable = FALSE) { Chris@0: $definitions['new_base_field'] = BaseFieldDefinition::create($type) Chris@0: ->setName('new_base_field') Chris@14: ->setRevisionable($is_revisionable) Chris@0: ->setLabel(t('A new base field')); Chris@14: $this->state->set($entity_type_id . '.additional_base_field_definitions', $definitions); Chris@0: } Chris@0: Chris@0: /** Chris@0: * Adds a long-named base field to the 'entity_test_update' entity type. Chris@0: */ Chris@0: protected function addLongNameBaseField() { Chris@0: $key = 'entity_test_update.additional_base_field_definitions'; Chris@0: $definitions = $this->state->get($key, []); Chris@0: $definitions['new_long_named_entity_reference_base_field'] = BaseFieldDefinition::create('entity_reference') Chris@0: ->setName('new_long_named_entity_reference_base_field') Chris@0: ->setLabel(t('A new long-named base field')) Chris@0: ->setSetting('target_type', 'user') Chris@0: ->setSetting('handler', 'default'); Chris@0: $this->state->set($key, $definitions); Chris@0: } Chris@0: Chris@0: /** Chris@0: * Adds a new revisionable base field to the 'entity_test_update' entity type. Chris@0: * Chris@0: * @param string $type Chris@0: * (optional) The field type for the new field. Defaults to 'string'. Chris@0: */ Chris@0: protected function addRevisionableBaseField($type = 'string') { Chris@0: $definitions['new_base_field'] = BaseFieldDefinition::create($type) Chris@0: ->setName('new_base_field') Chris@0: ->setLabel(t('A new revisionable base field')) Chris@0: ->setRevisionable(TRUE); Chris@0: $this->state->set('entity_test_update.additional_base_field_definitions', $definitions); Chris@0: } Chris@0: Chris@0: /** Chris@0: * Modifies the new base field from 'string' to 'text'. Chris@0: */ Chris@0: protected function modifyBaseField() { Chris@0: $this->addBaseField('text'); Chris@0: } Chris@0: Chris@0: /** Chris@0: * Promotes a field to an entity key. Chris@0: */ Chris@0: protected function makeBaseFieldEntityKey() { Chris@0: $entity_type = clone $this->entityManager->getDefinition('entity_test_update'); Chris@0: $entity_keys = $entity_type->getKeys(); Chris@0: $entity_keys['new_base_field'] = 'new_base_field'; Chris@0: $entity_type->set('entity_keys', $entity_keys); Chris@0: $this->state->set('entity_test_update.entity_type', $entity_type); Chris@0: } Chris@0: Chris@0: /** Chris@0: * Removes the new base field from the 'entity_test_update' entity type. Chris@14: * Chris@14: * @param string $entity_type_id Chris@14: * (optional) The entity type ID the base field should be attached to. Chris@0: */ Chris@14: protected function removeBaseField($entity_type_id = 'entity_test_update') { Chris@14: $this->state->delete($entity_type_id . '.additional_base_field_definitions'); Chris@0: } Chris@0: Chris@0: /** Chris@0: * Adds a single-field index to the base field. Chris@0: */ Chris@0: protected function addBaseFieldIndex() { Chris@0: $this->state->set('entity_test_update.additional_field_index.entity_test_update.new_base_field', TRUE); Chris@0: } Chris@0: Chris@0: /** Chris@0: * Removes the index added in addBaseFieldIndex(). Chris@0: */ Chris@0: protected function removeBaseFieldIndex() { Chris@0: $this->state->delete('entity_test_update.additional_field_index.entity_test_update.new_base_field'); Chris@0: } Chris@0: Chris@0: /** Chris@0: * Adds a new bundle field to the 'entity_test_update' entity type. Chris@0: * Chris@0: * @param string $type Chris@0: * (optional) The field type for the new field. Defaults to 'string'. Chris@0: */ Chris@0: protected function addBundleField($type = 'string') { Chris@0: $definitions['new_bundle_field'] = FieldStorageDefinition::create($type) Chris@0: ->setName('new_bundle_field') Chris@0: ->setLabel(t('A new bundle field')) Chris@0: ->setTargetEntityTypeId('entity_test_update'); Chris@0: $this->state->set('entity_test_update.additional_field_storage_definitions', $definitions); Chris@0: $this->state->set('entity_test_update.additional_bundle_field_definitions.test_bundle', $definitions); Chris@0: } Chris@0: Chris@0: /** Chris@0: * Modifies the new bundle field from 'string' to 'text'. Chris@0: */ Chris@0: protected function modifyBundleField() { Chris@0: $this->addBundleField('text'); Chris@0: } Chris@0: Chris@0: /** Chris@0: * Removes the new bundle field from the 'entity_test_update' entity type. Chris@0: */ Chris@0: protected function removeBundleField() { Chris@0: $this->state->delete('entity_test_update.additional_field_storage_definitions'); Chris@0: $this->state->delete('entity_test_update.additional_bundle_field_definitions.test_bundle'); Chris@0: } Chris@0: Chris@0: /** Chris@0: * Adds an index to the 'entity_test_update' entity type's base table. Chris@0: * Chris@0: * @see \Drupal\entity_test\EntityTestStorageSchema::getEntitySchema() Chris@0: */ Chris@0: protected function addEntityIndex() { Chris@0: $indexes = [ Chris@0: 'entity_test_update__new_index' => ['name', 'test_single_property'], Chris@0: ]; Chris@0: $this->state->set('entity_test_update.additional_entity_indexes', $indexes); Chris@0: } Chris@0: Chris@0: /** Chris@0: * Removes the index added in addEntityIndex(). Chris@0: */ Chris@0: protected function removeEntityIndex() { Chris@0: $this->state->delete('entity_test_update.additional_entity_indexes'); Chris@0: } Chris@0: Chris@0: /** Chris@0: * Renames the base table to 'entity_test_update_new'. Chris@0: */ Chris@0: protected function renameBaseTable() { Chris@0: $entity_type = clone $this->entityManager->getDefinition('entity_test_update'); Chris@0: Chris@0: $entity_type->set('base_table', 'entity_test_update_new'); Chris@0: Chris@0: $this->state->set('entity_test_update.entity_type', $entity_type); Chris@0: } Chris@0: Chris@0: /** Chris@0: * Renames the data table to 'entity_test_update_data_new'. Chris@0: */ Chris@0: protected function renameDataTable() { Chris@0: $entity_type = clone $this->entityManager->getDefinition('entity_test_update'); Chris@0: Chris@0: $entity_type->set('data_table', 'entity_test_update_data_new'); Chris@0: Chris@0: $this->state->set('entity_test_update.entity_type', $entity_type); Chris@0: } Chris@0: Chris@0: /** Chris@0: * Renames the revision table to 'entity_test_update_revision_new'. Chris@0: */ Chris@0: protected function renameRevisionBaseTable() { Chris@0: $entity_type = clone $this->entityManager->getDefinition('entity_test_update'); Chris@0: Chris@0: $entity_type->set('revision_table', 'entity_test_update_revision_new'); Chris@0: Chris@0: $this->state->set('entity_test_update.entity_type', $entity_type); Chris@0: } Chris@0: Chris@0: /** Chris@0: * Renames the revision data table to 'entity_test_update_revision_data_new'. Chris@0: */ Chris@0: protected function renameRevisionDataTable() { Chris@0: $entity_type = clone $this->entityManager->getDefinition('entity_test_update'); Chris@0: Chris@0: $entity_type->set('revision_data_table', 'entity_test_update_revision_data_new'); Chris@0: Chris@0: $this->state->set('entity_test_update.entity_type', $entity_type); Chris@0: } Chris@0: Chris@0: /** Chris@0: * Removes the entity type. Chris@0: */ Chris@0: protected function deleteEntityType() { Chris@0: $this->state->set('entity_test_update.entity_type', 'null'); Chris@0: } Chris@0: Chris@0: }