Skip to content

Commit

Permalink
Merge pull request #413 from City-of-Helsinki/UHF-7249-popular-servic…
Browse files Browse the repository at this point in the history
…es-editable-title

UHF-7249: Adds update hook to add title field for popular services pa…
  • Loading branch information
lonkaanna authored Dec 16, 2022
2 parents 884041e + 8f423ea commit c7ce913
Show file tree
Hide file tree
Showing 8 changed files with 130 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ dependencies:
config:
- field.field.paragraph.popular_services.field_service_items
- paragraphs.paragraphs_type.popular_services
- field.field.paragraph.popular_services.field_popular_services_title
module:
- paragraphs
_core:
Expand All @@ -13,9 +14,17 @@ targetEntityType: paragraph
bundle: popular_services
mode: default
content:
field_popular_services_title:
type: string_textfield
weight: 0
region: content
settings:
size: 60
placeholder: ''
third_party_settings: { }
field_service_items:
type: paragraphs
weight: 0
weight: 1
region: content
settings:
title: Paragraph
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ dependencies:
config:
- field.field.paragraph.popular_services.field_service_items
- paragraphs.paragraphs_type.popular_services
- field.field.paragraph.popular_services.field_popular_services_title
module:
- entity_reference_revisions
_core:
Expand All @@ -13,14 +14,22 @@ targetEntityType: paragraph
bundle: popular_services
mode: default
content:
field_popular_services_title:
type: string
label: hidden
settings:
link_to_entity: false
third_party_settings: { }
weight: 0
region: content
field_service_items:
type: entity_reference_revisions_entity_view
label: hidden
settings:
view_mode: default
link: ''
third_party_settings: { }
weight: 0
weight: 1
region: content
hidden:
search_api_excerpt: true
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
langcode: en
status: true
dependencies:
config:
- field.storage.paragraph.field_popular_services_title
- paragraphs.paragraphs_type.popular_services
id: paragraph.popular_services.field_popular_services_title
field_name: field_popular_services_title
entity_type: paragraph
bundle: popular_services
label: Title
description: 'If this field is left empty, the title will be "Popular services"'
required: false
translatable: false
default_value: { }
default_value_callback: ''
settings: { }
field_type: string
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
langcode: en
status: true
dependencies:
module:
- paragraphs
id: paragraph.field_popular_services_title
field_name: field_popular_services_title
entity_type: paragraph
type: string
settings:
max_length: 255
case_sensitive: false
is_ascii: false
module: core
locked: false
cardinality: 1
translatable: true
indexes: { }
persist_with_no_fields: false
custom_storage: false
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
description: 'Jos kenttä jätetään tyhjäksi, otsikoksi tulee "Suosittuja palveluja"'
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
description: 'Om detta lämnas tomt, titel är "Populära tjänster"'
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
core.entity_form_display.paragraph.popular_services.default:
expected_config:
content:
field_service_items:
weight: 0
update_actions:
add:
content:
field_popular_services_title:
type: string_textfield
weight: 0
region: content
settings:
size: 60
placeholder: ''
third_party_settings: { }
change:
content:
field_service_items:
weight: 1
core.entity_view_display.paragraph.popular_services.default:
expected_config:
content:
field_service_items:
weight: 0
update_actions:
add:
content:
field_popular_services_title:
type: string
label: hidden
settings:
link_to_entity: false
third_party_settings: { }
weight: 0
region: content
change:
content:
field_service_items:
weight: 1
31 changes: 30 additions & 1 deletion helfi_features/helfi_content/helfi_content.install
Original file line number Diff line number Diff line change
Expand Up @@ -973,4 +973,33 @@ function helfi_content_update_9038() {
foreach ($configurations as $configuration) {
ConfigHelper::installNewConfigTranslation($configTranslationLocation, $configuration);
}
}
}

/**
* Update the popular service paragraph with new field.
*/
function helfi_content_update_9039() {
/** @var \Drupal\update_helper\Updater $updateHelper */
$updateHelper = \Drupal::service('update_helper.updater');

// Add the new fields for popular services paragraph.
$configLocation = dirname(__FILE__) . '/config/install/';
$configTranslationLocation = dirname(__FILE__) . '/config/language/';

// Key field storage and value is field configuration.
$configFields = [
'field.storage.paragraph.field_popular_services_title' => 'field.field.paragraph.popular_services.field_popular_services_title',
];

// Install title field and its translations.
foreach ($configFields as $field_storage => $field_config) {
ConfigHelper::installNewField($configLocation, $field_storage, $field_config);
ConfigHelper::installNewConfigTranslation($configTranslationLocation, $field_config);
}

// Execute configuration update definitions with logging of success.
$updateHelper->executeUpdate('helfi_content', 'helfi_content_update_9039');

// Output logged messages to related channel of update execution.
return $updateHelper->logger()->output();
}

0 comments on commit c7ce913

Please sign in to comment.