gamify-1.1.x-dev/gamify.install
gamify.install
<?php
/**
* @file
* Install routines for gamify module.
*/
/**
* Add field points to userpoints entity.
*
* After added the field 'points' to the field definition, we have to update
* the db to effectively install the field .
*
* @see gamify_entity_base_field_info()
*/
function gamify_update_8001() {
// Configure field update parameters.
$entity_type = 'userpoints';
$fields = ['points'];
// Get the entity definition update manager.
$entity_definition_update_manager = \Drupal::entityDefinitionUpdateManager();
// Get the entity filed manager.
$entity_field_manager = \Drupal::service('entity_field.manager');
// Clear the cached field definitions.
$entity_field_manager->clearCachedFieldDefinitions();
// INSTALL FIELDS ON EVENT.
foreach ($fields as $field) {
// Get the updated field storage definitions from code.
$storage_definition = $entity_field_manager->getFieldStorageDefinitions($entity_type)[$field];
// Make sure field storage schema is loaded.
if ($storage_definition->getSchema()) {
// Install updated field storage definition.
$entity_definition_update_manager->installFieldStorageDefinition($field, $entity_type, 'userpoints', $storage_definition);
}
}
}
