function social_group_update_8004 in Open Social 8.2
Same name and namespace in other branches
- 8.9 modules/social_features/social_group/social_group.install \social_group_update_8004()
- 8 modules/social_features/social_group/social_group.install \social_group_update_8004()
- 8.3 modules/social_features/social_group/social_group.install \social_group_update_8004()
- 8.4 modules/social_features/social_group/social_group.install \social_group_update_8004()
- 8.5 modules/social_features/social_group/social_group.install \social_group_update_8004()
- 8.6 modules/social_features/social_group/social_group.install \social_group_update_8004()
- 8.7 modules/social_features/social_group/social_group.install \social_group_update_8004()
- 8.8 modules/social_features/social_group/social_group.install \social_group_update_8004()
- 10.3.x modules/social_features/social_group/social_group.install \social_group_update_8004()
- 10.0.x modules/social_features/social_group/social_group.install \social_group_update_8004()
- 10.1.x modules/social_features/social_group/social_group.install \social_group_update_8004()
- 10.2.x modules/social_features/social_group/social_group.install \social_group_update_8004()
Converts group description field type from plain text to formatted text.
File
- modules/
social_features/ social_group/ social_group.install, line 188 - Install, update and uninstall functions for the social_group module.
Code
function social_group_update_8004(&$sandbox) {
$entity = 'group';
$bundle = 'open_group';
$field_name = 'field_group_description';
$display_mode = 'default';
// Add a new column 'format' for description field type.
$spec = [
'type' => 'varchar',
'description' => '',
'length' => 255,
'not null' => FALSE,
'default' => NULL,
];
$schema = Database::getConnection()
->schema();
$table = "{$entity}__{$field_name}";
$col = "{$field_name}_format";
$schema
->addField($table, $col, $spec);
// Update the field storage settings.
$field_storage_id = "{$entity}.{$field_name}";
$field_storage = \Drupal::entityTypeManager()
->getStorage('field_storage_config')
->load($field_storage_id);
// Since the usual workflow for field storages do not allow changing the
// field type, we have to work around it in this case.
$new_field_storage = $field_storage
->toArray();
$new_field_storage['type'] = 'text_long';
$new_field_storage['module'] = 'text';
$new_field_storage['settings'] = [];
$new_field_storage['dependencies']['module'][] = 'text';
$new_field_storage = FieldStorageConfig::create($new_field_storage);
$new_field_storage->original = $new_field_storage;
$new_field_storage
->enforceIsNew(FALSE);
$new_field_storage
->save();
// Update the field settings.
$field_id = "{$entity}.{$bundle}.{$field_name}";
$field = \Drupal::entityTypeManager()
->getStorage('field_config')
->load($field_id);
$new_field = $field
->toArray();
$new_field['field_type'] = 'text_long';
$new_field['dependencies']['module'][] = 'text';
$new_field = FieldConfig::create($new_field);
$new_field->original = $field;
$new_field
->enforceIsNew(FALSE);
$new_field
->save();
// Update entity view display.
$display_id = "{$entity}.{$bundle}.{$display_mode}";
$view_display = \Drupal::entityManager()
->getStorage('entity_view_display')
->load($display_id);
if ($component = $view_display
->getComponent($field_name)) {
$view_display
->setComponent($field_name, [
'type' => 'basic_string',
'settings' => [],
] + $component)
->save();
}
// Update entity form display.
$form_display_name = 'group.open_group.default';
$form_display = \Drupal::entityTypeManager()
->getStorage('entity_form_display')
->load($form_display_name);
if (($component = $form_display
->getComponent($field_name)) && $component['type'] == 'string_textarea') {
$form_display
->setComponent($field_name, [
'type' => 'text_textarea',
'settings' => [
'rows' => 5,
'placeholder' => '',
],
] + $component)
->save();
}
}