-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathengineering_profile.install
More file actions
65 lines (56 loc) · 2 KB
/
Copy pathengineering_profile.install
File metadata and controls
65 lines (56 loc) · 2 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
<?php
/**
* @file
* engineering_profile.install
*/
use Drupal\field\Entity\FieldStorageConfig;
/**
* Implements hook_update_last_removed().
*/
function engineering_profile_update_last_removed() {
return 9106;
}
/**
* Force uninstall pdb_react from schema since it was removed.
*/
function engineering_profile_update_11000() {
$config = \Drupal::configFactory()->getEditable('core.extension');
$modules = $config->get('module');
unset($modules['pdb_react']);
$config->set('module', $modules);
$config->save(TRUE);
\Drupal::keyValue('system.schema')->delete('pdb_react');
}
/**
* Increase the size of a "string" field.
*
* @param string $entityType
* Entity type id.
* @param string $fieldName
* Field machine name.
* @param int $newSize
* New size of the field.
*/
function _stanford_profile_update_field_size(string $entityType, string $fieldName, int $newSize): void {
$database = \Drupal::database();
$database->query("ALTER TABLE {$entityType}__$fieldName MODIFY {$fieldName}_value VARCHAR($newSize)");
$database->query("ALTER TABLE {$entityType}_revision__$fieldName MODIFY {$fieldName}_value VARCHAR($newSize)");
$storage_key = "node.field_schema_data.$fieldName";
$storage_schema = \Drupal::keyValue('entity.storage_schema.sql');
$field_schema = $storage_schema->get($storage_key);
$field_schema["{$entityType}__$fieldName"]['fields']["{$fieldName}_value"]['length'] = $newSize;
$field_schema["{$entityType}_revision__$fieldName"]['fields']["{$fieldName}_value"]['length'] = $newSize;
$storage_schema->set($storage_key, $field_schema);
$config = \Drupal::configFactory()
->getEditable("field.storage.node.$fieldName");
$config->set('settings.max_length', $newSize);
$config->save(TRUE);
// Update field storage configuration.
FieldStorageConfig::loadByName($entityType, $fieldName)->save();
}
/**
* Increase News Dek field size to 500 characters.
*/
function engineering_profile_update_11001() {
_stanford_profile_update_field_size('node', 'su_news_dek', 500);
}