- Issue created by @tostinni
After converting a text field to text_long
, when inspecting the database you will find NULL
values inside the field format column which will cause troubles when updating the content as you will need to select the format for each textearea.
For the moment, we added a new hook_post_update_NAME()
to handle this by updating the database.
Here is the code used :
/**
* Update field_caption format to restricted_html.
*/
function MODULE_post_update_caption_format(&$sandbox) {
$field_map = [];
$field_map['media'] = [
'field_caption' => 'text_long',
];
$field_map['paragraph'] = [
'field_caption' => 'text_long',
];
$database = \Drupal::database();
$field_map = [];
$field_map['media'] = [
'field_caption' => 'text_long',
];
$field_map['paragraph'] = [
'field_caption' => 'text_long',
];
$updated = '';
foreach($field_map as $entity_type => $fields) {
foreach($fields as $field_name => $field_type) {
$num_updated = $database->update("{$entity_type}__{$field_name}")
->fields([
'field_caption_format' => 'restricted_html',
])
->execute();
$updated .= "{$entity_type}__{$field_name}: ". $num_updated ." fields updated.\n";
// Update revision table too.
$num_updated = $database->update("{$entity_type}_revision__{$field_name}")
->fields([
'field_caption_format' => 'restricted_html',
])
->execute();
$updated .= "{$entity_type}_revision__{$field_name}: ". $num_updated ." fields updated.\n";
}
}
return $updated;
}
Implement this in FieldTypeConverter
class.
Active
1.0
Code