Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Issue #3471956 by joshua1234511, richardgaunt, fionamorrison23: Enhance Civictheme menu theming system #1303

Open
wants to merge 4 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
2 changes: 1 addition & 1 deletion tests/behat/features/theme.settings.vertical_tabs.feature
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ Feature: Correct vertical tab does not focus on form validation
And I scroll to an element with id "edit-components-footer"
Then I click on ".vertical-tabs__menu-item a[href='#edit-components-footer']" element
And I fill in "Footer background image path" with "dummy-text"
Then I click on ".vertical-tabs__menu-item a[href='#edit-components-navigation']" element
Then I click on ".vertical-tabs__menu-item a[href='#edit-components-skip-link']" element
And I press "Save configuration"

And I scroll to an element with id "edit-components-footer"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -125,6 +125,9 @@ civictheme.settings:
is_animated:
label: 'Animate transition'
type: boolean
default_menu:
label: 'Default Menu'
type: string
secondary_navigation:
type: mapping
label: 'Secondary navigation settings'
Expand All @@ -141,6 +144,9 @@ civictheme.settings:
is_animated:
label: 'Animate transition'
type: boolean
default_menu:
label: 'Default Menu'
type: string
footer:
type: mapping
label: 'Footer settings'
Expand All @@ -158,6 +164,9 @@ civictheme.settings:
path:
label: 'Footer background image path'
type: string
default_menu:
label: 'Default Menu'
type: string
link:
type: mapping
label: 'Link settings'
Expand Down
79 changes: 49 additions & 30 deletions web/themes/contrib/civictheme/includes/menu.inc
Original file line number Diff line number Diff line change
Expand Up @@ -19,14 +19,57 @@ function _civictheme_preprocess_block__civictheme_footer_menu(array &$variables)
}

$menu_name = strtr($variables['elements']['#derivative_plugin_id'], '-', '_');
if ($menu_name === 'civictheme_footer') {
// Set menu theme as per footer theme.
$variables['theme'] = civictheme_get_theme_config_manager()->load('components.footer.theme', CivicthemeConstants::FOOTER_THEME_DEFAULT);
$variables['items'] = $variables['content']['#items'] ?? [];
$variables['title'] = $variables['configuration']['label_display'] ? $variables['configuration']['label'] : '';
$default_menu = civictheme_get_theme_config_manager()->load('components.footer.default_menu', CivicthemeConstants::FOOTER_DEFAULT_MENU);
$default_menu = strtr($default_menu, '-', '_');
if ($menu_name === $default_menu) {
_civictheme_preprocess_footer_menu($variables);
}
}

_civictheme_preprocess_menu_items($variables['items']);
/**
* Preprocess for primary navigation menu block.
*/
function _civictheme_preprocess_block__navigation(array &$variables): void {
if (isset($variables['elements']['#base_plugin_id']) && $variables['base_plugin_id'] != 'menu_block') {
return;
}

$menu_name = strtr($variables['elements']['#derivative_plugin_id'], '-', '_');
$key = substr($menu_name, strlen('civictheme_'));
$variables['dropdown_columns'] = civictheme_get_theme_config_manager()->load(sprintf('components.navigation.%s.dropdown_columns', $key), 4);
$default_menu = civictheme_get_theme_config_manager()->load(sprintf('components.navigation.%s.default_menu', $key), CivicthemeConstants::PRIMARY_NAVIGATION_DEFAULT_MENU);
$default_menu = strtr($default_menu, '-', '_');
if ($menu_name === $default_menu) {
_civictheme_preprocess_header_navigation_menu($variables, $menu_name);
}
}

/**
* Helper function to preprocess footer menu.
*/
function _civictheme_preprocess_footer_menu(array &$variables): void {
// Set menu theme as per footer theme.
$variables['theme'] = civictheme_get_theme_config_manager()->load('components.footer.theme', CivicthemeConstants::FOOTER_THEME_DEFAULT);
$variables['items'] = $variables['content']['#items'] ?? [];
$variables['title'] = $variables['configuration']['label_display'] ? $variables['configuration']['label'] : '';

_civictheme_preprocess_menu_items($variables['items']);
}

/**
* Helper function to preprocess header navigation menu.
*/
function _civictheme_preprocess_header_navigation_menu(array &$variables, string $menu_name): void {
$key = substr($menu_name, strlen('civictheme_'));
// Set menu theme as per footer theme.
$variables['theme'] = civictheme_get_theme_config_manager()->load('components.header.theme', CivicthemeConstants::HEADER_THEME_DEFAULT);
$variables['items'] = $variables['content']['#items'] ?? [];
$variables['dropdown'] = civictheme_get_theme_config_manager()->load(sprintf('components.navigation.%s.dropdown', $key), $menu_name === 'civictheme_primary_navigation' ? CivicthemeConstants::NAVIGATION_DROPDOWN_DRAWER : CivicthemeConstants::NAVIGATION_DROPDOWN_DROPDOWN);
$variables['dropdown_columns'] = civictheme_get_theme_config_manager()->load(sprintf('components.navigation.%s.dropdown_columns', $key), 4);
$variables['dropdown_columns_fill'] = civictheme_get_theme_config_manager()->load(sprintf('components.navigation.%s.dropdown_columns_fill', $key), FALSE);
$variables['is_animated'] = civictheme_get_theme_config_manager()->load(sprintf('components.navigation.%s.is_animated', $key), FALSE);
$expand_all_items = $variables['elements']['#configuration']['expand_all_items'] ?? FALSE;
_civictheme_preprocess_menu_items($variables['items'], $expand_all_items);
}

/**
Expand All @@ -51,27 +94,3 @@ function _civictheme_preprocess_menu_items(array &$items, bool $expand_all = FAL
}
}
}

/**
* Preprocess for primary navigation menu block.
*/
function _civictheme_preprocess_block__navigation(array &$variables): void {
if (isset($variables['elements']['#base_plugin_id']) && $variables['base_plugin_id'] != 'menu_block') {
return;
}

$menu_name = strtr($variables['elements']['#derivative_plugin_id'], '-', '_');

if ($menu_name === 'civictheme_primary_navigation' || $menu_name === 'civictheme_secondary_navigation') {
$key = substr($menu_name, strlen('civictheme_'));
// Set menu theme as per footer theme.
$variables['theme'] = civictheme_get_theme_config_manager()->load('components.header.theme', CivicthemeConstants::HEADER_THEME_DEFAULT);
$variables['items'] = $variables['content']['#items'] ?? [];
$variables['dropdown'] = civictheme_get_theme_config_manager()->load(sprintf('components.navigation.%s.dropdown', $key), $menu_name === 'civictheme_primary_navigation' ? CivicthemeConstants::NAVIGATION_DROPDOWN_DRAWER : CivicthemeConstants::NAVIGATION_DROPDOWN_DROPDOWN);
$variables['dropdown_columns'] = civictheme_get_theme_config_manager()->load(sprintf('components.navigation.%s.dropdown_columns', $key), 4);
$variables['dropdown_columns_fill'] = civictheme_get_theme_config_manager()->load(sprintf('components.navigation.%s.dropdown_columns_fill', $key), FALSE);
$variables['is_animated'] = civictheme_get_theme_config_manager()->load(sprintf('components.navigation.%s.is_animated', $key), FALSE);
$expand_all_items = $variables['elements']['#configuration']['expand_all_items'] ?? FALSE;
_civictheme_preprocess_menu_items($variables['items'], $expand_all_items);
}
}
15 changes: 15 additions & 0 deletions web/themes/contrib/civictheme/src/CivicthemeConstants.php
Original file line number Diff line number Diff line change
Expand Up @@ -186,4 +186,19 @@ final class CivicthemeConstants {
*/
const OPTOUT_VIEWS_STYLE_TABLE = 'CivicThemeOptoutViewsStyleTable';

/**
* Defines Tooter Navigation Menu "default_menu" value.
*/
const FOOTER_DEFAULT_MENU = 'civictheme-footer';

/**
* Defines Primary Navigation Menu "default_menu" value.
*/
const PRIMARY_NAVIGATION_DEFAULT_MENU = 'civictheme-primary-navigation';

/**
* Defines Secondary Navigation Menu "default_menu" value.
*/
const SECONDARY_NAVIGATION_DEFAULT_MENU = 'civictheme-secondary-navigation';

}
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@
use Drupal\civictheme\CivicthemeUtility;
use Drupal\Component\Utility\UrlHelper;
use Drupal\Core\Form\FormStateInterface;
use Drupal\system\Entity\Menu;
use Drupal\system\MenuInterface;

/**
* CivicTheme settings section to display components.
Expand Down Expand Up @@ -175,6 +177,20 @@ public function form(array &$form, FormStateInterface $form_state): void {
'#default_value' => $this->themeConfigManager->load('components.footer.logo_type', CivicthemeConstants::LOGO_TYPE_DEFAULT),
];

$menu_options = array_map(function (MenuInterface $menu) {
return $menu->label();
}, Menu::loadMultiple());
asort($menu_options);

$form['components']['footer']['default_menu'] = [
'#title' => $this->t('Default Menu'),
'#description' => $this->t('Select the menu to use as the default for this navigation.'),
'#type' => 'select',
'#required' => TRUE,
'#options' => $menu_options,
'#default_value' => $this->themeConfigManager->load('components.footer.default_menu', CivicthemeConstants::FOOTER_DEFAULT_MENU),
];

$form['components']['footer']['background_image'] = [
'#type' => 'fieldset',
'#title' => $this->t('Footer background image'),
Expand Down Expand Up @@ -216,13 +232,15 @@ public function form(array &$form, FormStateInterface $form_state): void {
'dropdown_columns' => 4,
'dropdown_columns_fill' => FALSE,
'is_animated' => FALSE,
'default_menu' => CivicthemeConstants::PRIMARY_NAVIGATION_DEFAULT_MENU,
],
'secondary_navigation' => [
'title' => $this->t('Secondary navigation'),
'dropdown' => CivicthemeConstants::NAVIGATION_DROPDOWN_NONE,
'dropdown_columns' => 4,
'dropdown_columns_fill' => FALSE,
'is_animated' => FALSE,
'default_menu' => CivicthemeConstants::SECONDARY_NAVIGATION_DEFAULT_MENU,
],
];

Expand All @@ -234,6 +252,15 @@ public function form(array &$form, FormStateInterface $form_state): void {
'#open' => TRUE,
];

$form['components']['navigation'][$navigation_name]['default_menu'] = [
'#title' => $this->t('Default Menu'),
'#description' => $this->t('Select the menu to use as the default for this navigation.'),
'#type' => 'select',
'#required' => TRUE,
'#options' => $menu_options,
'#default_value' => $this->themeConfigManager->load(sprintf('components.navigation.%s.default_menu', $navigation_name), $navigation_defaults['default_menu']),
];

$form['components']['navigation'][$navigation_name]['dropdown'] = [
'#title' => $this->t('Dropdown type'),
'#description' => $this->t('Select how the menu sub-tree items would appear in the menu.'),
Expand Down
Loading