modules/stanford_policy/stanford_policy.install
<?php
/**
* @file
* stanford_policy.install
*/
use Drupal\field\Entity\FieldStorageConfig;
/**
* Install new policy content type.
*/
function stanford_policy_update_8001() {
$entity_type_manager = \Drupal::entityTypeManager();
if ($entity_type_manager->hasDefinition('log')) {
$old_logs = $entity_type_manager->getStorage('log')->loadMultiple();
foreach ($old_logs as $log) {
$log->delete();
}
}
$log_type = \Drupal::entityTypeManager()->getDefinition('su_policy_log');
\Drupal::entityDefinitionUpdateManager()
->installEntityType($log_type);
}
/**
* Increase authority field size.
*/
function stanford_policy_update_8002() {
$database = \Drupal::database();
$database->query("ALTER TABLE node__su_policy_authority MODIFY su_policy_authority_value VARCHAR(500)");
$database->query("ALTER TABLE node_revision__su_policy_authority MODIFY su_policy_authority_value VARCHAR(500)");
$storage_key = 'node.field_schema_data.su_policy_authority';
$storage_schema = \Drupal::keyValue('entity.storage_schema.sql');
$field_schema = $storage_schema->get($storage_key);
$field_schema['node__su_policy_authority']['fields']['su_policy_authority_value']['length'] = 500;
$field_schema['node_revision__su_policy_authority']['fields']['su_policy_authority_value']['length'] = 500;
$storage_schema->set($storage_key, $field_schema);
// Update field configuration.
$config = \Drupal::configFactory()
->getEditable('field.storage.node.su_policy_authority');
$config->set('settings.max_length', 500);
$config->save(TRUE);
// Update field storage configuration.
FieldStorageConfig::loadByName('node', 'su_policy_authority')->save();
}