From 8e7d296c6609d5d98d9a14b16ae61b58eb3bd267 Mon Sep 17 00:00:00 2001 From: tuutti Date: Wed, 20 Mar 2024 17:00:10 +0200 Subject: [PATCH 1/6] UHF-8908: Convert email field type to email --- helfi_tpr.install | 29 +++++++++++++++++++++++++++++ src/Entity/BaseFieldTrait.php | 21 ++++++++++++++++++++- src/Entity/Unit.php | 2 +- 3 files changed, 50 insertions(+), 2 deletions(-) diff --git a/helfi_tpr.install b/helfi_tpr.install index a3f7233..9a9c183 100644 --- a/helfi_tpr.install +++ b/helfi_tpr.install @@ -337,3 +337,32 @@ function helfi_tpr_update_8047() : void { \Drupal::entityDefinitionUpdateManager() ->installFieldStorageDefinition('information', 'tpr_service_channel', 'helfi_tpr', $field); } + +/** + * UHF-8908 Convert email field type to email. + */ +function helfi_tpr_update_8048() : void { + $entityDefinitionManager = \Drupal::entityDefinitionUpdateManager(); + $fieldDefinition = $entityDefinitionManager->getFieldStorageDefinition('email', 'tpr_unit'); + + // Uninstall old string email field. + if ($fieldDefinition->getType() === 'string') { + $entityDefinitionManager->uninstallFieldStorageDefinition($fieldDefinition); + } + + $field = BaseFieldDefinition::create('email') + ->setLabel(new TranslatableMarkup('Email')) + ->setTranslatable(FALSE) + ->setRevisionable(FALSE) + ->setSettings([ + 'max_length' => 255, + ]) + ->setDisplayConfigurable('view', TRUE) + ->setDisplayConfigurable('form', TRUE) + ->setDisplayOptions('form', [ + 'type' => 'readonly_field_widget', + ]); + + \Drupal::entityDefinitionUpdateManager() + ->installFieldStorageDefinition('email', 'tpr_unit', 'helfi_tpr', $field); +} diff --git a/src/Entity/BaseFieldTrait.php b/src/Entity/BaseFieldTrait.php index f942c0e..299bedb 100644 --- a/src/Entity/BaseFieldTrait.php +++ b/src/Entity/BaseFieldTrait.php @@ -12,6 +12,26 @@ */ trait BaseFieldTrait { + /** + * Helper function to create an email field. + * + * @param string $label + * The label. + * @param int $cardinality + * The cardinality. + * + * @return \Drupal\Core\Field\BaseFieldDefinition + * The field definition. + */ + protected static function createEmailField(string $label, int $cardinality = 1) : BaseFieldDefinition { + return static::createBaseField(BaseFieldDefinition::create('email'), $label) + ->setCardinality($cardinality) + ->setDefaultValue('') + ->setSettings([ + 'max_length' => 255, + ]); + } + /** * Helper function to create a basic string field. * @@ -25,7 +45,6 @@ trait BaseFieldTrait { */ protected static function createStringField(string $label, int $cardinality = 1) : BaseFieldDefinition { return static::createBaseField(BaseFieldDefinition::create('string'), $label) - // @codingStandardsIgnoreLine ->setCardinality($cardinality) ->setDefaultValue('') ->setSettings([ diff --git a/src/Entity/Unit.php b/src/Entity/Unit.php index d1f4e53..3c3fea9 100644 --- a/src/Entity/Unit.php +++ b/src/Entity/Unit.php @@ -211,7 +211,7 @@ public static function baseFieldDefinitions(EntityTypeInterface $entity_type) : ->setDisplayConfigurable('form', TRUE); $fields['phone'] = static::createPhoneField('Phone', BaseFieldDefinition::CARDINALITY_UNLIMITED) ->setTranslatable(FALSE); - $fields['email'] = static::createStringField('Email') + $fields['email'] = static::createEmailField('Email') ->setTranslatable(FALSE); $fields['accessibility_phone'] = static::createStringField('Accessibility phone') ->setTranslatable(FALSE); From f72f6315d20838077d881445d8b833f32e6d9d0a Mon Sep 17 00:00:00 2001 From: tuutti Date: Wed, 20 Mar 2024 17:05:15 +0200 Subject: [PATCH 2/6] UHF-8908: phpcs fixes --- helfi_tpr.install | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/helfi_tpr.install b/helfi_tpr.install index 9a9c183..6c096dc 100644 --- a/helfi_tpr.install +++ b/helfi_tpr.install @@ -350,13 +350,13 @@ function helfi_tpr_update_8048() : void { $entityDefinitionManager->uninstallFieldStorageDefinition($fieldDefinition); } - $field = BaseFieldDefinition::create('email') + $field = BaseFieldDefinition::create('email') ->setLabel(new TranslatableMarkup('Email')) ->setTranslatable(FALSE) ->setRevisionable(FALSE) - ->setSettings([ - 'max_length' => 255, - ]) + ->setSettings([ + 'max_length' => 255, + ]) ->setDisplayConfigurable('view', TRUE) ->setDisplayConfigurable('form', TRUE) ->setDisplayOptions('form', [ From 30b07fae039277d929ec2722dd81c9317c541955 Mon Sep 17 00:00:00 2001 From: tuutti Date: Wed, 20 Mar 2024 18:13:44 +0200 Subject: [PATCH 3/6] UHF-8908: Convert service channel email field as well --- helfi_tpr.install | 43 ++++++++++++++++++++++-------------------- src/Entity/Channel.php | 2 +- 2 files changed, 24 insertions(+), 21 deletions(-) diff --git a/helfi_tpr.install b/helfi_tpr.install index 6c096dc..6784f2f 100644 --- a/helfi_tpr.install +++ b/helfi_tpr.install @@ -341,28 +341,31 @@ function helfi_tpr_update_8047() : void { /** * UHF-8908 Convert email field type to email. */ -function helfi_tpr_update_8048() : void { +function helfi_tpr_update_8049() : void { $entityDefinitionManager = \Drupal::entityDefinitionUpdateManager(); - $fieldDefinition = $entityDefinitionManager->getFieldStorageDefinition('email', 'tpr_unit'); - // Uninstall old string email field. - if ($fieldDefinition->getType() === 'string') { - $entityDefinitionManager->uninstallFieldStorageDefinition($fieldDefinition); - } + foreach (['tpr_unit', 'tpr_service_channel'] as $entityType) { + $fieldDefinition = $entityDefinitionManager->getFieldStorageDefinition('email', $entityType); - $field = BaseFieldDefinition::create('email') - ->setLabel(new TranslatableMarkup('Email')) - ->setTranslatable(FALSE) - ->setRevisionable(FALSE) - ->setSettings([ - 'max_length' => 255, - ]) - ->setDisplayConfigurable('view', TRUE) - ->setDisplayConfigurable('form', TRUE) - ->setDisplayOptions('form', [ - 'type' => 'readonly_field_widget', - ]); + // Uninstall old string email field. + if ($fieldDefinition->getType() === 'string') { + $entityDefinitionManager->uninstallFieldStorageDefinition($fieldDefinition); + } - \Drupal::entityDefinitionUpdateManager() - ->installFieldStorageDefinition('email', 'tpr_unit', 'helfi_tpr', $field); + $field = BaseFieldDefinition::create('email') + ->setLabel(new TranslatableMarkup('Email')) + ->setTranslatable(FALSE) + ->setRevisionable(FALSE) + ->setSettings([ + 'max_length' => 255, + ]) + ->setDisplayConfigurable('view', TRUE) + ->setDisplayConfigurable('form', TRUE) + ->setDisplayOptions('form', [ + 'type' => 'readonly_field_widget', + ]); + + \Drupal::entityDefinitionUpdateManager() + ->installFieldStorageDefinition('email', $entityType, 'helfi_tpr', $field); + } } diff --git a/src/Entity/Channel.php b/src/Entity/Channel.php index d3a9e19..0bca99b 100644 --- a/src/Entity/Channel.php +++ b/src/Entity/Channel.php @@ -85,7 +85,7 @@ public static function baseFieldDefinitions(EntityTypeInterface $entity_type) { $fields = parent::baseFieldDefinitions($entity_type); $fields['name_synonyms'] = static::createStringField('Name synonyms', BaseFieldDefinition::CARDINALITY_UNLIMITED); - $fields['email'] = static::createStringField('Email'); + $fields['email'] = static::createEmailField('Email'); $string_fields = [ 'type' => 'Type', From a0169c4ffe549e6766197d9b1c0dfbc8d1881dc5 Mon Sep 17 00:00:00 2001 From: tuutti Date: Thu, 21 Mar 2024 07:27:55 +0200 Subject: [PATCH 4/6] UHF-8908: Group TPR entity types --- composer.json | 2 +- helfi_tpr.links.menu.yml | 50 ++++++++++++++++++++-------------------- helfi_tpr.links.task.yml | 40 ++++++++++++++++---------------- 3 files changed, 46 insertions(+), 46 deletions(-) diff --git a/composer.json b/composer.json index 3e6bb55..87ff1b4 100644 --- a/composer.json +++ b/composer.json @@ -13,7 +13,7 @@ "drupal/views_infinite_scroll": "^2.0" }, "conflict": { - "drupal/helfi_api_base": "<2.0" + "drupal/helfi_api_base": "<2.6.6" }, "require-dev": { "dealerdirect/phpcodesniffer-composer-installer": "^0.7.0", diff --git a/helfi_tpr.links.menu.yml b/helfi_tpr.links.menu.yml index 99c30a8..cc06b1b 100644 --- a/helfi_tpr.links.menu.yml +++ b/helfi_tpr.links.menu.yml @@ -2,7 +2,31 @@ tpr_unit.settings: title: TPR - Unit settings description: Configure TPR unit entity type route_name: tpr_unit.settings - parent: system.admin_structure + parent: helfi_api_base.entity_settings + +tpr_service.settings: + title: TPR - Service settings + description: Configure TPR service entity type + route_name: tpr_service.settings + parent: helfi_api_base.entity_settings + +tpr_errand_service.settings: + title: TPR - Errand Service settings + description: Configure TPR errand service entity type + route_name: tpr_errand_service.settings + parent: helfi_api_base.entity_settings + +tpr_service_channel.settings: + title: TPR - Service channel settings + description: Configure TPR service channel entity type + route_name: tpr_service_channel.settings + parent: helfi_api_base.entity_settings + +tpr_ontology_word_details.settings: + title: TPR - Ontology word details settings + description: Configure TPR Ontology word details entity type + route_name: tpr_ontology_word_details.settings + parent: helfi_api_base.entity_settings entity.tpr_unit.collection: title: TPR - Unit entities @@ -10,12 +34,6 @@ entity.tpr_unit.collection: route_name: entity.tpr_unit.collection parent: helfi_api_base.integrations -tpr_service.settings: - title: TPR - Service settings - description: Configure TPR service entity type - route_name: tpr_service.settings - parent: system.admin_structure - entity.tpr_service.collection: title: TPR - Service entities description: List of TPR service entities @@ -28,30 +46,12 @@ entity.tpr_errand_service.collection: route_name: entity.tpr_errand_service.collection parent: helfi_api_base.integrations -tpr_errand_service.settings: - title: TPR - Errand Service settings - description: Configure TPR errand service entity type - route_name: tpr_errand_service.settings - parent: system.admin_structure - entity.tpr_service_channel.collection: title: TPR - Service channel entities description: List of TPR service channel entities route_name: entity.tpr_service_channel.collection parent: helfi_api_base.integrations -tpr_service_channel.settings: - title: TPR - Service channel settings - description: Configure TPR service channel entity type - route_name: tpr_service_channel.settings - parent: system.admin_structure - -tpr_ontology_word_details.settings: - title: TPR - Ontology word details settings - description: Configure TPR Ontology word details entity type - route_name: tpr_ontology_word_details.settings - parent: system.admin_structure - entity.tpr_ontology_word_details.collection: title: TPR - Ontology word details entities description: List of TPR - Ontology word details entities diff --git a/helfi_tpr.links.task.yml b/helfi_tpr.links.task.yml index 7734da6..fa5d1a4 100644 --- a/helfi_tpr.links.task.yml +++ b/helfi_tpr.links.task.yml @@ -3,50 +3,50 @@ tpr_unit.settings: route_name: tpr_unit.settings base_route: tpr_unit.settings +tpr_service.settings: + title: Settings + route_name: tpr_service.settings + base_route: tpr_service.settings + +tpr_errand_service.settings: + title: Settings + route_name: tpr_errand_service.settings + base_route: tpr_errand_service.settings + +tpr_service_channel.settings: + title: Settings + route_name: tpr_service_channel.settings + base_route: tpr_service_channel.settings + +tpr_ontology_word_details.settings: + title: Settings + route_name: tpr_ontology_word_details.settings + base_route: tpr_ontology_word_details.settings + tpr_unit.content_list: title: TPR - Unit route_name: entity.tpr_unit.collection base_route: helfi_api_base.integrations weight: 10 -tpr_service.settings: - title: Settings - route_name: tpr_service.settings - base_route: tpr_service.settings - tpr_service.content_list: title: TPR - Service route_name: entity.tpr_service.collection base_route: helfi_api_base.integrations weight: 10 -tpr_errand_service.settings: - title: Settings - route_name: tpr_errand_service.settings - base_route: tpr_errand_service.settings - tpr_errand_service.content_list: title: TPR - Errand Service route_name: entity.tpr_errand_service.collection base_route: helfi_api_base.integrations weight: 10 -tpr_service_channel.settings: - title: Settings - route_name: tpr_service_channel.settings - base_route: tpr_service_channel.settings - tpr_service_channel.content_list: title: TPR - Service channel route_name: entity.tpr_service_channel.collection base_route: helfi_api_base.integrations weight: 10 -tpr_ontology_word_details.settings: - title: Settings - route_name: tpr_ontology_word_details.settings - base_route: tpr_ontology_word_details.settings - tpr_ontology_word_details.content_list: title: TPR - Ontology word details route_name: entity.tpr_ontology_word_details.collection From 39af4c35192aba333552706bdf9796d4c52bbdd8 Mon Sep 17 00:00:00 2001 From: tuutti Date: Thu, 21 Mar 2024 08:11:14 +0200 Subject: [PATCH 5/6] UHF-8908: Fixed service channel --- helfi_tpr.install | 2 +- src/Entity/Channel.php | 1 - 2 files changed, 1 insertion(+), 2 deletions(-) diff --git a/helfi_tpr.install b/helfi_tpr.install index 6784f2f..984d942 100644 --- a/helfi_tpr.install +++ b/helfi_tpr.install @@ -341,7 +341,7 @@ function helfi_tpr_update_8047() : void { /** * UHF-8908 Convert email field type to email. */ -function helfi_tpr_update_8049() : void { +function helfi_tpr_update_8048() : void { $entityDefinitionManager = \Drupal::entityDefinitionUpdateManager(); foreach (['tpr_unit', 'tpr_service_channel'] as $entityType) { diff --git a/src/Entity/Channel.php b/src/Entity/Channel.php index 0bca99b..7fc3748 100644 --- a/src/Entity/Channel.php +++ b/src/Entity/Channel.php @@ -90,7 +90,6 @@ public static function baseFieldDefinitions(EntityTypeInterface $entity_type) { $string_fields = [ 'type' => 'Type', 'type_string' => 'Type string', - 'email' => 'Email', ]; foreach ($string_fields as $name => $label) { From ac2532cc5b418879e13d591f3a45f7686a99498f Mon Sep 17 00:00:00 2001 From: tuutti Date: Thu, 21 Mar 2024 11:30:14 +0200 Subject: [PATCH 6/6] UHF-8908: Mark entities as needs_update --- helfi_tpr.install | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/helfi_tpr.install b/helfi_tpr.install index 984d942..16fd13a 100644 --- a/helfi_tpr.install +++ b/helfi_tpr.install @@ -343,6 +343,7 @@ function helfi_tpr_update_8047() : void { */ function helfi_tpr_update_8048() : void { $entityDefinitionManager = \Drupal::entityDefinitionUpdateManager(); + $database = \Drupal::database(); foreach (['tpr_unit', 'tpr_service_channel'] as $entityType) { $fieldDefinition = $entityDefinitionManager->getFieldStorageDefinition('email', $entityType); @@ -367,5 +368,13 @@ function helfi_tpr_update_8048() : void { \Drupal::entityDefinitionUpdateManager() ->installFieldStorageDefinition('email', $entityType, 'helfi_tpr', $field); + + // Mark migrate map as 'needs update'. + if (!$database->schema()->tableExists('migrate_map_' . $entityType)) { + return; + } + $database->update('migrate_map_' . $entityType)->fields([ + 'source_row_status' => MigrateIdMapInterface::STATUS_NEEDS_UPDATE, + ])->execute(); } }