Skip to content

Commit

Permalink
Issue openeuropa#501: Also update timeline fields with no instances.
Browse files Browse the repository at this point in the history
  • Loading branch information
donquixote committed Jan 4, 2022
1 parent df692a1 commit aea2e0e
Showing 1 changed file with 14 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@

declare(strict_types = 1);

use Drupal\Core\Entity\FieldableEntityInterface;

/**
* Change timeline "label" column type from "varchar_ascii" to "varchar".
*/
Expand All @@ -17,9 +19,18 @@ function oe_content_timeline_field_update_8101(): void {
$key_value = \Drupal::keyValue('entity.storage_schema.sql');
$db = \Drupal::database();

$timeline_fields = $entity_field_manager->getFieldMapByFieldType('timeline_field');
foreach ($timeline_fields as $entity_type => $fields) {
foreach (array_keys($fields) as $field_name) {
// Iterate through all fields with type 'timeline_field'.
// Previously this was done with
// $timeline_fields = $entity_field_manager->getFieldMapByFieldType('timeline_field');
// Unfortunately, this misses field storages with no instances.
foreach (\Drupal::entityTypeManager()->getDefinitions() as $entity_type => $entity_type_definition) {
if (!$entity_type_definition->entityClassImplements(FieldableEntityInterface::class)) {
continue;
}
foreach ($entity_field_manager->getFieldStorageDefinitions($entity_type) as $field_name => $field_storage_definition) {
if ($field_storage_definition->getType() !== 'timeline_field') {
continue;
}
$key_name = $entity_type . '.field_schema_data.' . $field_name;
$storage_schema = $key_value->get($key_name);
$schema_field = $field_name . '_label';
Expand Down

0 comments on commit aea2e0e

Please sign in to comment.