From 21c2527a98eda287fc25e299423d00d4f731569b Mon Sep 17 00:00:00 2001 From: Joshua Fernandes Date: Mon, 1 Nov 2021 09:02:51 +0530 Subject: [PATCH 1/8] Added hook install to create a Main Footer Menu Behat test updated Auto create menu added for alter. On-behalf-of: @salsadigitalauorg joshua.fernandes@salsadigital.com.au --- ...rm_display.taxonomy_term.sites.default.yml | 10 +++ ...ew_display.taxonomy_term.sites.default.yml | 9 ++ ...term.sites.field_site_footer_main_menu.yml | 22 +++++ ...onomy_term.field_site_footer_main_menu.yml | 19 +++++ ...i_resource_config.taxonomy_term--sites.yml | 6 ++ tests/behat/features/jsonapi.feature | 1 + tests/behat/features/menu.feature | 75 ++++++++++------ tests/behat/features/sites.feature | 1 + tide_site.info.yml | 2 + tide_site.install | 85 +++++++++++++++++++ tide_site.module | 1 + 11 files changed, 207 insertions(+), 24 deletions(-) create mode 100644 config/install/field.field.taxonomy_term.sites.field_site_footer_main_menu.yml create mode 100644 config/install/field.storage.taxonomy_term.field_site_footer_main_menu.yml diff --git a/config/install/core.entity_form_display.taxonomy_term.sites.default.yml b/config/install/core.entity_form_display.taxonomy_term.sites.default.yml index 9e71555..c03cda5 100644 --- a/config/install/core.entity_form_display.taxonomy_term.sites.default.yml +++ b/config/install/core.entity_form_display.taxonomy_term.sites.default.yml @@ -6,6 +6,7 @@ dependencies: - field.field.taxonomy_term.sites.field_prominence_ack_to_country - field.field.taxonomy_term.sites.field_site_domains - field.field.taxonomy_term.sites.field_site_footer_logos + - field.field.taxonomy_term.sites.field_site_footer_main_menu - field.field.taxonomy_term.sites.field_site_footer_menu - field.field.taxonomy_term.sites.field_site_footer_text - field.field.taxonomy_term.sites.field_site_homepage @@ -112,6 +113,15 @@ content: third_party_settings: { } type: entity_reference_autocomplete region: content + field_site_footer_main_menu: + weight: 5 + settings: + match_operator: CONTAINS + size: 60 + placeholder: '' + third_party_settings: { } + type: entity_reference_autocomplete + region: content field_site_og_image: weight: 12 settings: diff --git a/config/install/core.entity_view_display.taxonomy_term.sites.default.yml b/config/install/core.entity_view_display.taxonomy_term.sites.default.yml index f89cb23..1caf943 100644 --- a/config/install/core.entity_view_display.taxonomy_term.sites.default.yml +++ b/config/install/core.entity_view_display.taxonomy_term.sites.default.yml @@ -6,6 +6,7 @@ dependencies: - field.field.taxonomy_term.sites.field_prominence_ack_to_country - field.field.taxonomy_term.sites.field_site_domains - field.field.taxonomy_term.sites.field_site_footer_logos + - field.field.taxonomy_term.sites.field_site_footer_main_menu - field.field.taxonomy_term.sites.field_site_footer_menu - field.field.taxonomy_term.sites.field_site_footer_text - field.field.taxonomy_term.sites.field_site_homepage @@ -99,6 +100,14 @@ content: third_party_settings: { } type: entity_reference_label region: content + field_site_footer_main_menu: + weight: 4 + label: above + settings: + link: true + third_party_settings: { } + type: entity_reference_label + region: content field_site_og_image: type: entity_reference_entity_view weight: 10 diff --git a/config/install/field.field.taxonomy_term.sites.field_site_footer_main_menu.yml b/config/install/field.field.taxonomy_term.sites.field_site_footer_main_menu.yml new file mode 100644 index 0000000..89a96ad --- /dev/null +++ b/config/install/field.field.taxonomy_term.sites.field_site_footer_main_menu.yml @@ -0,0 +1,22 @@ +langcode: en +status: true +dependencies: + config: + - field.storage.taxonomy_term.field_site_footer_main_menu + - taxonomy.vocabulary.sites +id: taxonomy_term.sites.field_site_footer_main_menu +field_name: field_site_footer_main_menu +entity_type: taxonomy_term +bundle: sites +label: 'Footer Main menu' +description: '' +required: false +translatable: false +default_value: { } +default_value_callback: '' +settings: + handler: 'default:menu' + handler_settings: + target_bundles: null + auto_create: false +field_type: entity_reference diff --git a/config/install/field.storage.taxonomy_term.field_site_footer_main_menu.yml b/config/install/field.storage.taxonomy_term.field_site_footer_main_menu.yml new file mode 100644 index 0000000..9270164 --- /dev/null +++ b/config/install/field.storage.taxonomy_term.field_site_footer_main_menu.yml @@ -0,0 +1,19 @@ +langcode: en +status: true +dependencies: + module: + - system + - taxonomy +id: taxonomy_term.field_site_footer_main_menu +field_name: field_site_footer_main_menu +entity_type: taxonomy_term +type: entity_reference +settings: + target_type: menu +module: core +locked: false +cardinality: 1 +translatable: true +indexes: { } +persist_with_no_fields: false +custom_storage: false diff --git a/config/optional/jsonapi_extras.jsonapi_resource_config.taxonomy_term--sites.yml b/config/optional/jsonapi_extras.jsonapi_resource_config.taxonomy_term--sites.yml index de758b7..e4c6f98 100644 --- a/config/optional/jsonapi_extras.jsonapi_resource_config.taxonomy_term--sites.yml +++ b/config/optional/jsonapi_extras.jsonapi_resource_config.taxonomy_term--sites.yml @@ -104,3 +104,9 @@ resourceFields: enhancer: id: '' disabled: false + field_site_footer_main_menu: + fieldName: field_site_footer_main_menu + publicName: field_site_footer_main_menu + enhancer: + id: '' + disabled: false diff --git a/tests/behat/features/jsonapi.feature b/tests/behat/features/jsonapi.feature index b9522c0..d7e2a09 100644 --- a/tests/behat/features/jsonapi.feature +++ b/tests/behat/features/jsonapi.feature @@ -27,3 +27,4 @@ Feature: JSONAPI exposure And the JSON node "data[0].attributes.field_site_footer_text.value" should be equal to "test site footer" And the JSON node "data[0].relationships.field_site_main_menu" should exist And the JSON node "data[0].relationships.field_site_footer_menu" should exist + And the JSON node "data[0].relationships.field_site_footer_main_menu" should exist diff --git a/tests/behat/features/menu.feature b/tests/behat/features/menu.feature index 3bbd682..60fe6fe 100644 --- a/tests/behat/features/menu.feature +++ b/tests/behat/features/menu.feature @@ -12,10 +12,12 @@ Feature: Sites menu autocreate And no "sites" terms: | Test 1 | And no menus: - | site-main-menu-test-1 | - | site-main-menu-test-1-test-11 | - | site-footer-menu-test-1 | - | site-footer-menu-test-1-test-11 | + | site-main-menu-test-1 | + | site-main-menu-test-1-test-11 | + | site-footer-menu-test-1 | + | site-footer-menu-test-1-test-11 | + | site-footer-main-menu-test-1 | + | site-footer-main-menu-test-1-test-11 | @api Scenario: Menu autocreate - new and existing sites @@ -29,14 +31,18 @@ Feature: Sites menu autocreate And I see field "Footer menu" And I see field "autocreate_footer_menu" And the "autocreate_footer_menu" checkbox should be checked + And I see field "Footer Main menu" + And I see field "autocreate_footer_main_menu" + And the "autocreate_footer_main_menu" checkbox should be checked # Assert auto-creation and association. When I press "Save" Then I should see the following success messages: - | success messages | - | Created new term Test 1. | - | Automatically created Main menu - Test 1 menu and assigned to Main menu field. | - | Automatically created Footer menu - Test 1 menu and assigned to Footer menu field. | + | success messages | + | Created new term Test 1. | + | Automatically created Main menu - Test 1 menu and assigned to Main menu field. | + | Automatically created Footer menu - Test 1 menu and assigned to Footer menu field. | + | Automatically created Footer Main menu - Test 1 menu and assigned to Footer Main menu field. | When I click "Test 1" And I click "Edit" Then the "Name" field should contain "Test 1" @@ -45,6 +51,8 @@ Feature: Sites menu autocreate And I don't see field "autocreate_main_menu" And the "Footer menu" field should contain "Footer menu - Test 1 (site-footer-menu-test-1)" And I don't see field "autocreate_footer_menu" + And the "Footer Main menu" field should contain "Footer Main menu - Test 1 (site-footer-main-menu-test-1)" + And I don't see field "autocreate_footer_main_menu" # Assert that menus are not auto-created again. When I fill in "Domains" with "test2.example.com" @@ -54,9 +62,10 @@ Feature: Sites menu autocreate | success messages | | Updated term Test 1. | And I should not see the following success messages: - | success messages | - | Automatically created Main menu - Test 1 menu and assigned to Main menu field. | - | Automatically created Footer menu - Test 1 menu and assigned to Footer menu field. | + | success messages | + | Automatically created Main menu - Test 1 menu and assigned to Main menu field. | + | Automatically created Footer menu - Test 1 menu and assigned to Footer menu field. | + | Automatically created Footer Main menu - Test 1 menu and assigned to Footer Main menu field. | # Assert that menu association was not lost after editing term. And I click "Edit" @@ -66,15 +75,19 @@ Feature: Sites menu autocreate And I don't see field "autocreate_main_menu" And the "Footer menu" field should contain "Footer menu - Test 1 (site-footer-menu-test-1)" And I don't see field "autocreate_footer_menu" + And the "Footer Main menu" field should contain "Footer Main menu - Test 1 (site-footer-main-menu-test-1)" + And I don't see field "autocreate_footer_main_menu" # Cleanup. Doing this manually since entities were created through UI. And no "sites" terms: | Test 1 | And no menus: - | site-main-menu-test-1 | - | site-main-menu-test-1-test-11 | - | site-footer-menu-test-1 | - | site-footer-menu-test-1-test-11 | + | site-main-menu-test-1 | + | site-main-menu-test-1-test-11 | + | site-footer-menu-test-1 | + | site-footer-menu-test-1-test-11 | + | site-footer-main-menu-test-1 | + | site-footer-main-menu-test-1-test-11 | @api Scenario: Menu autocreate - new and existing sections @@ -93,18 +106,23 @@ Feature: Sites menu autocreate And I see field "Footer menu" And I see field "autocreate_footer_menu" And the "autocreate_footer_menu" checkbox should be checked + And I see field "Footer Main menu" + And I see field "autocreate_footer_main_menu" + And the "autocreate_footer_main_menu" checkbox should be checked # Assert auto-creation and association. Footer menu will not be created just # yet - it will be created after the term is edited. When I uncheck "autocreate_footer_menu" + When I uncheck "autocreate_footer_main_menu" And I press "Save" Then I should see the following success messages: | success messages | | Created new term Test 1.1 | | Automatically created Main menu - Test 1 - Test 1.1 menu and assigned to Main menu field. | Then I should not see the following success messages: - | success messages | - | Automatically created Footer menu - Test 1 - Test 1.1 menu and assigned to Footer menu field. | + | success messages | + | Automatically created Footer menu - Test 1 - Test 1.1 menu and assigned to Footer menu field. | + | Automatically created Footer Main menu - Test 1 - Test 1.1 menu and assigned to Footer Main menu field. | When I click "Test 1.1" And I click "Edit" Then the "Name" field should contain "Test 1.1" @@ -113,17 +131,22 @@ Feature: Sites menu autocreate And I don't see field "autocreate_main_menu" And the "Footer menu" field should not contain "Footer menu - Test 1 - Test 1.1 (site-footer-menu-test-1-test-11)" And I see field "autocreate_footer_menu" + And the "Footer Main menu" field should not contain "Footer Main menu - Test 1 - Test 1.1 (site-footer-menu-main-test-1-test-11)" + And I see field "autocreate_footer_menu" # Assert that for sections menus are not set to be created by default. And the "autocreate_footer_menu" checkbox should not be checked + And the "autocreate_footer_main_menu" checkbox should not be checked # Assert that follow-up menu creation works. When I check "autocreate_footer_menu" + When I check "autocreate_footer_main_menu" And I press "Save" Then I should see the following success messages: - | success messages | - | Updated term Test 1.1. | - | Automatically created Footer menu - Test 1 - Test 1.1 menu and assigned to Footer menu field. | + | success messages | + | Updated term Test 1.1. | + | Automatically created Footer menu - Test 1 - Test 1.1 menu and assigned to Footer menu field. | + | Automatically created Footer Main menu - Test 1 - Test 1.1 menu and assigned to Footer Main menu field. | And I should not see the following success messages: | success messages | | Automatically created Main menu - Test 1 - Test 1.1 menu and assigned to Main menu field. | @@ -136,13 +159,17 @@ Feature: Sites menu autocreate And I don't see field "autocreate_main_menu" And the "Footer menu" field should contain "Footer menu - Test 1 - Test 1.1 (site-footer-menu-test-1-test-11)" And I don't see field "autocreate_footer_menu" + And the "Footer Main menu" field should contain "Footer Main menu - Test 1 - Test 1.1 (site-footer-main-menu-test-1-test-11)" + And I don't see field "autocreate_footer_main_menu" # Cleanup. Doing this manually since entities were created through UI. And no "sites" terms: | Test 1 | | Test 1.1 | And no menus: - | site-main-menu-test-1 | - | site-main-menu-test-1-test-11 | - | site-footer-menu-test-1 | - | site-footer-menu-test-1-test-11 | + | site-main-menu-test-1 | + | site-main-menu-test-1-test-11 | + | site-footer-menu-test-1 | + | site-footer-menu-test-1-test-11 | + | site-footer-main-menu-test-1 | + | site-footer-main-menu-test-1-test-11 | diff --git a/tests/behat/features/sites.feature b/tests/behat/features/sites.feature index a9404d0..f7900f9 100644 --- a/tests/behat/features/sites.feature +++ b/tests/behat/features/sites.feature @@ -13,6 +13,7 @@ Feature: Sites taxonomy vocabulary And I see field "Footer text" And I see field "Domains" And I see field "Main menu" + And I see field "Footer Main menu" And I see field "Footer menu" And I see field "Homepage" And I don't see field "Description" diff --git a/tide_site.info.yml b/tide_site.info.yml index 2f423c0..d09bf6f 100644 --- a/tide_site.info.yml +++ b/tide_site.info.yml @@ -25,6 +25,7 @@ config_devel: - field.field.taxonomy_term.sites.field_prominence_ack_to_country - field.field.taxonomy_term.sites.field_site_domains - field.field.taxonomy_term.sites.field_site_footer_logos + - field.field.taxonomy_term.sites.field_site_footer_main_menu - field.field.taxonomy_term.sites.field_site_footer_menu - field.field.taxonomy_term.sites.field_site_footer_text - field.field.taxonomy_term.sites.field_site_homepage @@ -41,6 +42,7 @@ config_devel: - field.storage.taxonomy_term.field_prominence_ack_to_country - field.storage.taxonomy_term.field_site_domains - field.storage.taxonomy_term.field_site_footer_logos + - field.storage.taxonomy_term.field_site_footer_main_menu - field.storage.taxonomy_term.field_site_footer_menu - field.storage.taxonomy_term.field_site_footer_text - field.storage.taxonomy_term.field_site_homepage diff --git a/tide_site.install b/tide_site.install index 18c4e65..6b7c847 100644 --- a/tide_site.install +++ b/tide_site.install @@ -422,3 +422,88 @@ function tide_site_update_8019() { } } } + +/** + * Add a new Footer Main menu on the Site Taxonomy. + */ +function tide_site_update_8020() { + + $config_location = [Settings::get('config_sync_directory', FALSE)]; + module_load_include('inc', 'tide_core', 'includes/helpers'); + try { + _tide_read_config('field.storage.taxonomy_term.field_site_footer_main_menu', $config_location, TRUE); + } + catch (Exception $ex) { + if ($ex->getMessage() == 'Configuration does not exist in any provided locations') { + + $configs = [ + 'field.storage.taxonomy_term.field_site_footer_main_menu' => 'field_storage_config', + 'field.field.taxonomy_term.sites.field_site_footer_main_menu' => 'field_config', + ]; + $config_location = [drupal_get_path('module', 'tide_site') . '/config/install']; + // 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(); + } + + // Adding the field to display form. + $entity_form_display = Drupal::entityTypeManager() + ->getStorage('entity_form_display') + ->load('taxonomy_term.sites.default'); + if ($entity_form_display) { + $entity_form_display->setComponent('field_site_footer_main_menu', [ + 'weight' => 5, + 'settings' => [ + 'match_operator' => 'CONTAINS', + 'size' => 60, + 'placeholder' => '', + ], + 'third_party_settings' => [], + 'type' => 'entity_reference_autocomplete', + 'region' => 'content', + ]); + } + $entity_form_display->save(); + + // Adding the field to display view. + $entity_view_display = Drupal::entityTypeManager() + ->getStorage('entity_view_display') + ->load('taxonomy_term.sites.default'); + if ($entity_view_display) { + $entity_view_display->setComponent('field_site_footer_main_menu', [ + 'weight' => 4, + 'label' => 'above', + 'settings' => [ + 'link' => TRUE, + ], + 'third_party_settings' => [], + 'region' => 'content', + 'type' => 'entity_reference_label', + ]); + } + $entity_view_display->save(); + + $config_factory = \Drupal::configFactory(); + $config = $config_factory->getEditable('jsonapi_extras.jsonapi_resource_config.taxonomy_term--sites'); + + $content = $config->get('resourceFields'); + if (!isset($content['field_site_footer_main_menu'])) { + $content['field_site_footer_main_menu'] = [ + 'fieldName' => 'field_site_footer_main_menu', + 'publicName' => 'field_site_footer_main_menu', + 'enhancer' => [ + 'id' => '', + ], + 'disabled' => FALSE, + ]; + + $config->set('resourceFields', $content); + } + + $config->save(); + } + } +} diff --git a/tide_site.module b/tide_site.module index dce10dc..930e35d 100644 --- a/tide_site.module +++ b/tide_site.module @@ -210,6 +210,7 @@ function tide_site_form_taxonomy_term_form_alter(&$form, FormStateInterface $for $altered = $menu_helper->alterFormFields($form, [ 'field_site_main_menu', 'field_site_footer_menu', + 'field_site_footer_main_menu', ]); if (!empty($altered)) { From cc17c7b96f9de77373a25b8ad6610d7cfb226224 Mon Sep 17 00:00:00 2001 From: Joshua Fernandes Date: Mon, 1 Nov 2021 09:26:47 +0530 Subject: [PATCH 2/8] Updated the behat test. On-behalf-of: @salsadigitalauorg joshua.fernandes@salsadigital.com.au --- tests/behat/features/menu.feature | 40 +++++++++++++++---------------- 1 file changed, 20 insertions(+), 20 deletions(-) diff --git a/tests/behat/features/menu.feature b/tests/behat/features/menu.feature index 60fe6fe..45bad7d 100644 --- a/tests/behat/features/menu.feature +++ b/tests/behat/features/menu.feature @@ -12,12 +12,12 @@ Feature: Sites menu autocreate And no "sites" terms: | Test 1 | And no menus: - | site-main-menu-test-1 | - | site-main-menu-test-1-test-11 | - | site-footer-menu-test-1 | - | site-footer-menu-test-1-test-11 | - | site-footer-main-menu-test-1 | - | site-footer-main-menu-test-1-test-11 | + | site-main-menu-test-1 | + | site-main-menu-test-1-test-11 | + | site-footer-menu-test-1 | + | site-footer-menu-test-1-test-11 | + | site-footer-main-menu-test-1 | + | site-footer-main-menu-test-1-11 | @api Scenario: Menu autocreate - new and existing sites @@ -82,12 +82,12 @@ Feature: Sites menu autocreate And no "sites" terms: | Test 1 | And no menus: - | site-main-menu-test-1 | - | site-main-menu-test-1-test-11 | - | site-footer-menu-test-1 | - | site-footer-menu-test-1-test-11 | - | site-footer-main-menu-test-1 | - | site-footer-main-menu-test-1-test-11 | + | site-main-menu-test-1 | + | site-main-menu-test-1-test-11 | + | site-footer-menu-test-1 | + | site-footer-menu-test-1-test-11 | + | site-footer-main-menu-test-1 | + | site-footer-main-menu-test-1-11 | @api Scenario: Menu autocreate - new and existing sections @@ -131,7 +131,7 @@ Feature: Sites menu autocreate And I don't see field "autocreate_main_menu" And the "Footer menu" field should not contain "Footer menu - Test 1 - Test 1.1 (site-footer-menu-test-1-test-11)" And I see field "autocreate_footer_menu" - And the "Footer Main menu" field should not contain "Footer Main menu - Test 1 - Test 1.1 (site-footer-menu-main-test-1-test-11)" + And the "Footer Main menu" field should not contain "Footer Main menu - Test 1 - Test 1.1 (site-footer-main-menu-test-1-11)" And I see field "autocreate_footer_menu" # Assert that for sections menus are not set to be created by default. And the "autocreate_footer_menu" checkbox should not be checked @@ -159,7 +159,7 @@ Feature: Sites menu autocreate And I don't see field "autocreate_main_menu" And the "Footer menu" field should contain "Footer menu - Test 1 - Test 1.1 (site-footer-menu-test-1-test-11)" And I don't see field "autocreate_footer_menu" - And the "Footer Main menu" field should contain "Footer Main menu - Test 1 - Test 1.1 (site-footer-main-menu-test-1-test-11)" + And the "Footer Main menu" field should contain "Footer Main menu - Test 1 - Test 1.1 (site-footer-main-menu-test-1-11)" And I don't see field "autocreate_footer_main_menu" # Cleanup. Doing this manually since entities were created through UI. @@ -167,9 +167,9 @@ Feature: Sites menu autocreate | Test 1 | | Test 1.1 | And no menus: - | site-main-menu-test-1 | - | site-main-menu-test-1-test-11 | - | site-footer-menu-test-1 | - | site-footer-menu-test-1-test-11 | - | site-footer-main-menu-test-1 | - | site-footer-main-menu-test-1-test-11 | + | site-main-menu-test-1 | + | site-main-menu-test-1-test-11 | + | site-footer-menu-test-1 | + | site-footer-menu-test-1-test-11 | + | site-footer-main-menu-test-1 | + | site-footer-main-menu-test-1-11 | From 86ec3c8dd6ca0884e995cb24207744a985a6b201 Mon Sep 17 00:00:00 2001 From: Joshua Fernandes Date: Mon, 1 Nov 2021 10:00:39 +0530 Subject: [PATCH 3/8] Updated the behat test. On-behalf-of: @salsadigitalauorg joshua.fernandes@salsadigital.com.au --- tests/behat/features/menu.feature | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/tests/behat/features/menu.feature b/tests/behat/features/menu.feature index 45bad7d..071bf72 100644 --- a/tests/behat/features/menu.feature +++ b/tests/behat/features/menu.feature @@ -132,7 +132,7 @@ Feature: Sites menu autocreate And the "Footer menu" field should not contain "Footer menu - Test 1 - Test 1.1 (site-footer-menu-test-1-test-11)" And I see field "autocreate_footer_menu" And the "Footer Main menu" field should not contain "Footer Main menu - Test 1 - Test 1.1 (site-footer-main-menu-test-1-11)" - And I see field "autocreate_footer_menu" + And I see field "autocreate_footer_main_menu" # Assert that for sections menus are not set to be created by default. And the "autocreate_footer_menu" checkbox should not be checked And the "autocreate_footer_main_menu" checkbox should not be checked @@ -159,7 +159,6 @@ Feature: Sites menu autocreate And I don't see field "autocreate_main_menu" And the "Footer menu" field should contain "Footer menu - Test 1 - Test 1.1 (site-footer-menu-test-1-test-11)" And I don't see field "autocreate_footer_menu" - And the "Footer Main menu" field should contain "Footer Main menu - Test 1 - Test 1.1 (site-footer-main-menu-test-1-11)" And I don't see field "autocreate_footer_main_menu" # Cleanup. Doing this manually since entities were created through UI. From 0c29148560c591f545c8156a5ee3eeb4565f14f0 Mon Sep 17 00:00:00 2001 From: Joshua Fernandes Date: Mon, 1 Nov 2021 10:54:19 +0530 Subject: [PATCH 4/8] Default value for Main Footer Menu - should be the same as the value of the Main menu On-behalf-of: @salsadigitalauorg joshua.fernandes@salsadigital.com.au --- tide_site.install | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/tide_site.install b/tide_site.install index 6b7c847..199af76 100644 --- a/tide_site.install +++ b/tide_site.install @@ -506,4 +506,17 @@ function tide_site_update_8020() { $config->save(); } } + + $query = \Drupal::entityQuery('taxonomy_term'); + $query->condition('vid', "sites"); + $tids = $query->execute(); + $terms = \Drupal::entityTypeManager()->getStorage('taxonomy_term')->loadMultiple($tids); + if (!empty($terms)) { + foreach ($terms as $term) { + if (isset($term->get('field_site_main_menu')->target_id)) { + $term->field_site_footer_main_menu->setValue($term->get('field_site_main_menu')->target_id); + $term->Save(); + } + } + } } From 58c726dbc5c89194e144a0d89bc1d98a18762162 Mon Sep 17 00:00:00 2001 From: Joshua Fernandes Date: Mon, 1 Nov 2021 11:05:06 +0530 Subject: [PATCH 5/8] Check if field already exported to config/sync. On-behalf-of: @salsadigitalauorg joshua.fernandes@salsadigital.com.au --- tide_site.install | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/tide_site.install b/tide_site.install index 199af76..29de133 100644 --- a/tide_site.install +++ b/tide_site.install @@ -445,8 +445,11 @@ function tide_site_update_8020() { 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(); + $id = $storage->getIDFromConfigName($config, $storage->getEntityType()->getConfigPrefix()); + if ($storage->load($id) == NULL) { + $config_entity = $storage->createFromStorageRecord($config_read); + $config_entity->save(); + } } // Adding the field to display form. From 3100021ac0d60c768b28defd4bc1ae95ed60291f Mon Sep 17 00:00:00 2001 From: Joshua Fernandes Date: Mon, 1 Nov 2021 14:43:21 +0530 Subject: [PATCH 6/8] Check if field already exported to config/sync. On-behalf-of: @salsadigitalauorg joshua.fernandes@salsadigital.com.au --- tide_site.install | 141 ++++++++++++++++++++++------------------------ 1 file changed, 66 insertions(+), 75 deletions(-) diff --git a/tide_site.install b/tide_site.install index 29de133..79fb9bd 100644 --- a/tide_site.install +++ b/tide_site.install @@ -427,89 +427,80 @@ function tide_site_update_8019() { * Add a new Footer Main menu on the Site Taxonomy. */ function tide_site_update_8020() { - - $config_location = [Settings::get('config_sync_directory', FALSE)]; + $configs = [ + 'field.storage.taxonomy_term.field_site_footer_main_menu' => 'field_storage_config', + 'field.field.taxonomy_term.sites.field_site_footer_main_menu' => 'field_config', + ]; module_load_include('inc', 'tide_core', 'includes/helpers'); - try { - _tide_read_config('field.storage.taxonomy_term.field_site_footer_main_menu', $config_location, TRUE); + $config_location = [drupal_get_path('module', 'tide_site') . '/config/install']; + // 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); + $id = $storage->getIDFromConfigName($config, $storage->getEntityType()->getConfigPrefix()); + var_dump($id); + if ($storage->load($id) == NULL) { + $config_entity = $storage->createFromStorageRecord($config_read); + $config_entity->save(); + } } - catch (Exception $ex) { - if ($ex->getMessage() == 'Configuration does not exist in any provided locations') { - - $configs = [ - 'field.storage.taxonomy_term.field_site_footer_main_menu' => 'field_storage_config', - 'field.field.taxonomy_term.sites.field_site_footer_main_menu' => 'field_config', - ]; - $config_location = [drupal_get_path('module', 'tide_site') . '/config/install']; - // 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); - $id = $storage->getIDFromConfigName($config, $storage->getEntityType()->getConfigPrefix()); - if ($storage->load($id) == NULL) { - $config_entity = $storage->createFromStorageRecord($config_read); - $config_entity->save(); - } - } - - // Adding the field to display form. - $entity_form_display = Drupal::entityTypeManager() - ->getStorage('entity_form_display') - ->load('taxonomy_term.sites.default'); - if ($entity_form_display) { - $entity_form_display->setComponent('field_site_footer_main_menu', [ - 'weight' => 5, - 'settings' => [ - 'match_operator' => 'CONTAINS', - 'size' => 60, - 'placeholder' => '', - ], - 'third_party_settings' => [], - 'type' => 'entity_reference_autocomplete', - 'region' => 'content', - ]); - } - $entity_form_display->save(); - - // Adding the field to display view. - $entity_view_display = Drupal::entityTypeManager() - ->getStorage('entity_view_display') - ->load('taxonomy_term.sites.default'); - if ($entity_view_display) { - $entity_view_display->setComponent('field_site_footer_main_menu', [ - 'weight' => 4, - 'label' => 'above', - 'settings' => [ - 'link' => TRUE, - ], - 'third_party_settings' => [], - 'region' => 'content', - 'type' => 'entity_reference_label', - ]); - } - $entity_view_display->save(); - $config_factory = \Drupal::configFactory(); - $config = $config_factory->getEditable('jsonapi_extras.jsonapi_resource_config.taxonomy_term--sites'); + // Adding the field to display form. + $entity_form_display = Drupal::entityTypeManager() + ->getStorage('entity_form_display') + ->load('taxonomy_term.sites.default'); + if ($entity_form_display) { + $entity_form_display->setComponent('field_site_footer_main_menu', [ + 'weight' => 5, + 'settings' => [ + 'match_operator' => 'CONTAINS', + 'size' => 60, + 'placeholder' => '', + ], + 'third_party_settings' => [], + 'type' => 'entity_reference_autocomplete', + 'region' => 'content', + ]); + } + $entity_form_display->save(); - $content = $config->get('resourceFields'); - if (!isset($content['field_site_footer_main_menu'])) { - $content['field_site_footer_main_menu'] = [ - 'fieldName' => 'field_site_footer_main_menu', - 'publicName' => 'field_site_footer_main_menu', - 'enhancer' => [ - 'id' => '', - ], - 'disabled' => FALSE, - ]; + // Adding the field to display view. + $entity_view_display = Drupal::entityTypeManager() + ->getStorage('entity_view_display') + ->load('taxonomy_term.sites.default'); + if ($entity_view_display) { + $entity_view_display->setComponent('field_site_footer_main_menu', [ + 'weight' => 4, + 'label' => 'above', + 'settings' => [ + 'link' => TRUE, + ], + 'third_party_settings' => [], + 'region' => 'content', + 'type' => 'entity_reference_label', + ]); + } + $entity_view_display->save(); - $config->set('resourceFields', $content); - } + $config_factory = \Drupal::configFactory(); + $config = $config_factory->getEditable('jsonapi_extras.jsonapi_resource_config.taxonomy_term--sites'); + + $content = $config->get('resourceFields'); + if (!isset($content['field_site_footer_main_menu'])) { + $content['field_site_footer_main_menu'] = [ + 'fieldName' => 'field_site_footer_main_menu', + 'publicName' => 'field_site_footer_main_menu', + 'enhancer' => [ + 'id' => '', + ], + 'disabled' => FALSE, + ]; - $config->save(); - } + $config->set('resourceFields', $content); } + $config->save(); + $query = \Drupal::entityQuery('taxonomy_term'); $query->condition('vid', "sites"); $tids = $query->execute(); From a3e9184c542afc2897733b06bd94c73b61d1aad3 Mon Sep 17 00:00:00 2001 From: Joshua Fernandes Date: Mon, 1 Nov 2021 16:14:23 +0530 Subject: [PATCH 7/8] Phpcs Fixes. On-behalf-of: @salsadigitalauorg joshua.fernandes@salsadigital.com.au --- tide_site.install | 1 - 1 file changed, 1 deletion(-) diff --git a/tide_site.install b/tide_site.install index 79fb9bd..2592ed1 100644 --- a/tide_site.install +++ b/tide_site.install @@ -438,7 +438,6 @@ function tide_site_update_8020() { $config_read = _tide_read_config($config, $config_location, TRUE); $storage = \Drupal::entityTypeManager()->getStorage($type); $id = $storage->getIDFromConfigName($config, $storage->getEntityType()->getConfigPrefix()); - var_dump($id); if ($storage->load($id) == NULL) { $config_entity = $storage->createFromStorageRecord($config_read); $config_entity->save(); From 555a6e6cb241b466b1e15921adf8f061991c41eb Mon Sep 17 00:00:00 2001 From: Joshua Fernandes Date: Mon, 1 Nov 2021 21:53:19 +0530 Subject: [PATCH 8/8] Implemented a post update functions for tide_site. On-behalf-of: @salsadigitalauorg joshua.fernandes@salsadigital.com.au --- tide_site.install | 12 ------------ tide_site.post_update.php | 24 ++++++++++++++++++++++++ 2 files changed, 24 insertions(+), 12 deletions(-) create mode 100644 tide_site.post_update.php diff --git a/tide_site.install b/tide_site.install index 2592ed1..c7a9687 100644 --- a/tide_site.install +++ b/tide_site.install @@ -500,16 +500,4 @@ function tide_site_update_8020() { $config->save(); - $query = \Drupal::entityQuery('taxonomy_term'); - $query->condition('vid', "sites"); - $tids = $query->execute(); - $terms = \Drupal::entityTypeManager()->getStorage('taxonomy_term')->loadMultiple($tids); - if (!empty($terms)) { - foreach ($terms as $term) { - if (isset($term->get('field_site_main_menu')->target_id)) { - $term->field_site_footer_main_menu->setValue($term->get('field_site_main_menu')->target_id); - $term->Save(); - } - } - } } diff --git a/tide_site.post_update.php b/tide_site.post_update.php new file mode 100644 index 0000000..92e8d26 --- /dev/null +++ b/tide_site.post_update.php @@ -0,0 +1,24 @@ +condition('vid', "sites"); + $tids = $query->execute(); + $terms = \Drupal::entityTypeManager()->getStorage('taxonomy_term')->loadMultiple($tids); + if (!empty($terms)) { + foreach ($terms as $term) { + if (isset($term->get('field_site_main_menu')->target_id)) { + $term->field_site_footer_main_menu->setValue($term->get('field_site_main_menu')->target_id); + $term->Save(); + } + } + } +}