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..071bf72 100644 --- a/tests/behat/features/menu.feature +++ b/tests/behat/features/menu.feature @@ -16,6 +16,8 @@ Feature: Sites menu autocreate | 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 @@ -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,6 +75,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" # Cleanup. Doing this manually since entities were created through UI. And no "sites" terms: @@ -75,6 +86,8 @@ Feature: Sites menu autocreate | 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 @@ -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-main-menu-test-1-11)" + 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 # 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,6 +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 I don't see field "autocreate_footer_main_menu" # Cleanup. Doing this manually since entities were created through UI. And no "sites" terms: @@ -146,3 +170,5 @@ Feature: Sites menu autocreate | 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 | 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..c7a9687 100644 --- a/tide_site.install +++ b/tide_site.install @@ -422,3 +422,82 @@ function tide_site_update_8019() { } } } + +/** + * Add a new Footer Main menu on the Site Taxonomy. + */ +function tide_site_update_8020() { + $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'); + $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'); + + $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)) { 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(); + } + } + } +}