Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

UHF-8908: Convert email field type to email #171

Merged
merged 6 commits into from
Mar 21, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
41 changes: 41 additions & 0 deletions helfi_tpr.install
Original file line number Diff line number Diff line change
Expand Up @@ -337,3 +337,44 @@ 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();
$database = \Drupal::database();

foreach (['tpr_unit', 'tpr_service_channel'] as $entityType) {
$fieldDefinition = $entityDefinitionManager->getFieldStorageDefinition('email', $entityType);

// 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', $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();
}
}
50 changes: 25 additions & 25 deletions helfi_tpr.links.menu.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,20 +2,38 @@ 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
description: List of TPR unit entities
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
Expand All @@ -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
Expand Down
40 changes: 20 additions & 20 deletions helfi_tpr.links.task.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
21 changes: 20 additions & 1 deletion src/Entity/BaseFieldTrait.php
Original file line number Diff line number Diff line change
Expand Up @@ -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.
*
Expand All @@ -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([
Expand Down
3 changes: 1 addition & 2 deletions src/Entity/Channel.php
Original file line number Diff line number Diff line change
Expand Up @@ -85,12 +85,11 @@ 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',
'type_string' => 'Type string',
'email' => 'Email',
];

foreach ($string_fields as $name => $label) {
Expand Down
2 changes: 1 addition & 1 deletion src/Entity/Unit.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
Loading