Skip to content

Commit

Permalink
DGIR-148 : Fix update hook issue
Browse files Browse the repository at this point in the history
  • Loading branch information
Prashant-bd committed Jan 18, 2024
1 parent 700aa9f commit 9778b28
Showing 1 changed file with 4 additions and 7 deletions.
11 changes: 4 additions & 7 deletions embargo.install
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
*/

use Drupal\Core\Field\BaseFieldDefinition;
use Drupal\Core\Update\UpdateException;
use Drupal\Core\Utility\UpdateException;

/**
* Add a new field to the existing Embargo entity type.
Expand All @@ -20,16 +20,13 @@ function embargo_update_8001() {
try {
// Create a new field definition.
$new_field = BaseFieldDefinition::create('entity_reference')
->setLabel(t('New Embargoed File'))
->setLabel(t('Embargoed File'))
->setDescription(t('New field for attaching media to the Embargo node.'))
->setSetting('target_type', 'media')
->setCardinality(BaseFieldDefinition::CARDINALITY_UNLIMITED);

// Install the new definition.
$definition_manager->installFieldStorageDefinition('new_embargoed_file', $entity_type_id, $bundle, $new_field);

// Clear the cache.
drupal_flush_all_caches();
$definition_manager->installFieldStorageDefinition('embargoed_file', $entity_type_id, $bundle, $new_field);
}
catch (UpdateException $e) {
// Handle exception if needed.
Expand All @@ -38,5 +35,5 @@ function embargo_update_8001() {
}

// Provide a message indicating the update has been applied.
return t('Added new_embargoed_file to the Embargo entity.');
return t('Added embargoed_file to the Embargo entity.');
}

0 comments on commit 9778b28

Please sign in to comment.