From bb8f5741868f99691a523148a3d41aad3cff7bd7 Mon Sep 17 00:00:00 2001 From: Yeni Atencio <47239456+yeniatencio@users.noreply.github.com> Date: Mon, 4 Mar 2024 09:08:02 +1100 Subject: [PATCH] [SDPAP-8938]add new field in search listing (#64) * add new field * fix lint --- ...splay.node.tide_search_listing.default.yml | 9 +++++ ...splay.node.tide_search_listing.default.yml | 8 +++++ ...isplay.node.tide_search_listing.teaser.yml | 2 ++ ...ch_listing.field_above_results_content.yml | 24 +++++++++++++ ...orage.node.field_above_results_content.yml | 22 ++++++++++++ tide_search.install | 34 +++++++++++++++++++ 6 files changed, 99 insertions(+) create mode 100644 config/optional/field.field.node.tide_search_listing.field_above_results_content.yml create mode 100644 config/optional/field.storage.node.field_above_results_content.yml diff --git a/config/optional/core.entity_form_display.node.tide_search_listing.default.yml b/config/optional/core.entity_form_display.node.tide_search_listing.default.yml index 748f626..676214f 100644 --- a/config/optional/core.entity_form_display.node.tide_search_listing.default.yml +++ b/config/optional/core.entity_form_display.node.tide_search_listing.default.yml @@ -2,6 +2,7 @@ langcode: en status: true dependencies: config: + - field.field.node.tide_search_listing.field_above_results_content - field.field.node.tide_search_listing.field_below_results_content - field.field.node.tide_search_listing.field_custom_sort_configuration - field.field.node.tide_search_listing.field_featured_image @@ -147,6 +148,14 @@ content: region: content settings: { } third_party_settings: { } + field_above_results_content: + type: text_textarea + weight: 7 + region: content + settings: + rows: 5 + placeholder: '' + third_party_settings: { } field_below_results_content: type: text_textarea weight: 8 diff --git a/config/optional/core.entity_view_display.node.tide_search_listing.default.yml b/config/optional/core.entity_view_display.node.tide_search_listing.default.yml index 6f999d8..75f1b1a 100644 --- a/config/optional/core.entity_view_display.node.tide_search_listing.default.yml +++ b/config/optional/core.entity_view_display.node.tide_search_listing.default.yml @@ -2,6 +2,7 @@ langcode: en status: true dependencies: config: + - field.field.node.tide_search_listing.field_above_results_content - field.field.node.tide_search_listing.field_below_results_content - field.field.node.tide_search_listing.field_custom_sort_configuration - field.field.node.tide_search_listing.field_featured_image @@ -42,6 +43,13 @@ content: third_party_settings: { } weight: -20 region: content + field_above_results_content: + type: text_default + label: above + settings: { } + third_party_settings: { } + weight: 16 + region: content field_below_results_content: type: text_default label: above diff --git a/config/optional/core.entity_view_display.node.tide_search_listing.teaser.yml b/config/optional/core.entity_view_display.node.tide_search_listing.teaser.yml index 4300937..74a7acd 100644 --- a/config/optional/core.entity_view_display.node.tide_search_listing.teaser.yml +++ b/config/optional/core.entity_view_display.node.tide_search_listing.teaser.yml @@ -3,6 +3,7 @@ status: true dependencies: config: - core.entity_view_mode.node.teaser + - field.field.node.tide_search_listing.field_above_results_content - field.field.node.tide_search_listing.field_below_results_content - field.field.node.tide_search_listing.field_custom_sort_configuration - field.field.node.tide_search_listing.field_featured_image @@ -45,6 +46,7 @@ content: weight: 100 region: content hidden: + field_above_results_content: true field_below_results_content: true field_custom_sort_configuration: true field_featured_image: true diff --git a/config/optional/field.field.node.tide_search_listing.field_above_results_content.yml b/config/optional/field.field.node.tide_search_listing.field_above_results_content.yml new file mode 100644 index 0000000..fac13ef --- /dev/null +++ b/config/optional/field.field.node.tide_search_listing.field_above_results_content.yml @@ -0,0 +1,24 @@ +langcode: en +status: true +dependencies: + config: + - field.storage.node.field_above_results_content + - node.type.tide_search_listing + module: + - allowed_formats + - text +third_party_settings: + allowed_formats: + allowed_formats: { } +id: node.tide_search_listing.field_above_results_content +field_name: field_above_results_content +entity_type: node +bundle: tide_search_listing +label: 'Above results content' +description: '' +required: false +translatable: false +default_value: { } +default_value_callback: '' +settings: { } +field_type: text_long diff --git a/config/optional/field.storage.node.field_above_results_content.yml b/config/optional/field.storage.node.field_above_results_content.yml new file mode 100644 index 0000000..a49d810 --- /dev/null +++ b/config/optional/field.storage.node.field_above_results_content.yml @@ -0,0 +1,22 @@ +langcode: en +status: true +dependencies: + module: + - field_permissions + - node + - text +third_party_settings: + field_permissions: + permission_type: public +id: node.field_above_results_content +field_name: field_above_results_content +entity_type: node +type: text_long +settings: { } +module: text +locked: false +cardinality: 1 +translatable: true +indexes: { } +persist_with_no_fields: false +custom_storage: false diff --git a/tide_search.install b/tide_search.install index b8a9c53..906dada 100644 --- a/tide_search.install +++ b/tide_search.install @@ -56,3 +56,37 @@ function tide_search_update_10002() { $config->save(); } } + +/** + * Adds field_above_results_content field to search listing. + */ +function tide_search_update_10003() { + module_load_include('inc', 'tide_core', 'includes/helpers'); + $config_location = [\Drupal::service('extension.list.module')->getPath('tide_search') . '/config/optional']; + + $configs = [ + 'field.storage.node.field_above_results_content' => 'field_storage_config', + 'field.field.node.tide_search_listing.field_above_results_content' => 'field_config', + ]; + // Check if field already exported to config/sync. + foreach ($configs as $config => $type) { + $config_read = _tide_read_config($config, $config_location, TRUE); + $storage = \Drupal::entityTypeManager()->getStorage($type); + $config_entity = $storage->createFromStorageRecord($config_read); + $config_entity->save(); + } + + $form_configs = [ + 'core.entity_form_display.node.tide_search_listing.default', + 'core.entity_view_display.node.tide_search_listing.default', + 'core.entity_view_display.node.tide_search_listing.teaser', + ]; + foreach ($form_configs as $form_config) { + $config = \Drupal::configFactory()->getEditable($form_config); + $config_read = _tide_read_config($form_config, $config_location, FALSE); + $config->set('dependencies', $config_read['dependencies']); + $config->set('content', $config_read['content']); + $config->set('hidden', $config_read['hidden']); + $config->save(); + } +}