Skip to content
This repository has been archived by the owner on Sep 30, 2024. It is now read-only.

Added a new menu to sites taxonomy Main Footer Menu #93

Open
wants to merge 8 commits into
base: develop
Choose a base branch
from
Open
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
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
@@ -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
Original file line number Diff line number Diff line change
@@ -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
Original file line number Diff line number Diff line change
Expand Up @@ -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
1 change: 1 addition & 0 deletions tests/behat/features/jsonapi.feature
Original file line number Diff line number Diff line change
Expand Up @@ -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
50 changes: 38 additions & 12 deletions tests/behat/features/menu.feature
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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"
Expand All @@ -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"
Expand All @@ -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"
Expand All @@ -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:
Expand All @@ -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
Expand All @@ -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"
Expand All @@ -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. |
Expand All @@ -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:
Expand All @@ -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 |
1 change: 1 addition & 0 deletions tests/behat/features/sites.feature
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
2 changes: 2 additions & 0 deletions tide_site.info.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand Down
79 changes: 79 additions & 0 deletions tide_site.install
Original file line number Diff line number Diff line change
Expand Up @@ -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();

}
1 change: 1 addition & 0 deletions tide_site.module
Original file line number Diff line number Diff line change
Expand Up @@ -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)) {
Expand Down
24 changes: 24 additions & 0 deletions tide_site.post_update.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
<?php

/**
* @file
* Post update functions for tide_site.
*/

/**
* Set footer_main_menu to have same value as site_main_menu .
*/
function tide_site_post_update_sites_vocab_footer_main_menu() {
$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();
}
}
}
}