clean install

This commit is contained in:
2024-12-10 15:08:16 +01:00
commit e14eb2d8fd
31193 changed files with 3555714 additions and 0 deletions

View File

@@ -0,0 +1,113 @@
<?php
/**
* @file
* breadcrumb.theme
*/
use Drupal\Core\Entity\ContentEntityInterface;
use Drupal\Core\Url;
use Drupal\node\NodeInterface;
/**
* Breadcrumb.
*/
function gin_preprocess_breadcrumb(&$variables) {
// Alter node breadcrumb.
if ($variables['breadcrumb']) {
$entity = _gin_get_route_entity();
$entity_id = $entity ? $entity->getEntityTypeId() : NULL;
$url = $entity ? $entity->toUrl() : NULL;
foreach ($variables['breadcrumb'] as $key => $item) {
// Back to site item.
if ($key === 0) {
$variables['breadcrumb'][$key]['text'] = t('Back to site');
$variables['breadcrumb'][$key]['attributes']['title'] = t('Return to site content');
// Media handling.
if ($entity_id === 'media' && !\Drupal::config('media.settings')->get('standalone_url')) {
$url = Url::fromRoute('<front>');
}
// Custom block handling (a custom block cannot be viewed standalone).
if ($entity_id === 'block_content') {
$url = Url::fromRoute('<front>');
}
// Check for entity $url.
if ($url && $url->access()) {
$variables['breadcrumb'][$key]['url'] = $url;
}
else {
// Let escapeAdmin override the return URL.
$variables['breadcrumb'][$key]['attributes']['data'] = 'data-gin-toolbar-escape-admin';
}
}
elseif (isset($item['url']) && $item['url'] === $url) {
// Remove as we already have the back to site link set.
unset($variables['breadcrumb'][$key]);
}
}
// Adjust breadcrumb for nodes.
if ($node = \Drupal::routeMatch()->getParameter('node')) {
if ($node instanceof NodeInterface) {
// Unset items, except home link.
foreach ($variables['breadcrumb'] as $key => $item) {
if ($key > 0) {
unset($variables['breadcrumb'][$key]);
}
}
// Add bundle info.
$variables['breadcrumb'][] = [
'text' => t('Edit') . ' ' . $node->type->entity->label(),
'url' => '',
];
}
}
// Adjust breadcrumb for other entities.
elseif ($entity) {
// Add bundle info.
$variables['breadcrumb'][] = [
'text' => t('Edit') . ' ' . $entity->getEntityType()->getLabel(),
'url' => '',
];
}
}
// Node add: Fix Drupal 9 issue.
if (\Drupal::routeMatch()->getRouteName() === 'node.add') {
foreach ($variables['breadcrumb'] as $key => $item) {
if ($variables['breadcrumb'][$key]['text'] == '') {
unset($variables['breadcrumb'][$key]);
}
}
}
}
/**
* Helper function to extract the entity for the supplied route.
*
* @return null|\Drupal\Core\Entity\ContentEntityInterface
* Returns the content entity.
*/
function _gin_get_route_entity() {
$route_match = \Drupal::routeMatch();
// Entity will be found in the route parameters.
if (($route = $route_match->getRouteObject()) && ($parameters = $route->getOption('parameters'))) {
// Determine if the current route represents an entity.
foreach ($parameters as $name => $options) {
if (isset($options['type']) && strpos($options['type'], 'entity:') === 0) {
$entity = $route_match->getParameter($name);
if ($entity instanceof ContentEntityInterface && $entity->hasLinkTemplate('canonical')) {
return $entity;
}
// Since entity was found, no need to iterate further.
return NULL;
}
}
}
}

View File

@@ -0,0 +1,181 @@
<?php
/**
* @file
* form.theme
*/
use Drupal\Core\Form\FormStateInterface;
use Drupal\gin\GinContentFormHelper;
use Drupal\gin\GinDescriptionToggle;
use Drupal\gin\GinPreRender;
use Drupal\gin\GinSettings;
/**
* Implements form_alter_HOOK() for some major form changes.
*/
function gin_form_alter(&$form, $form_state, $form_id) {
\Drupal::classResolver(GinContentFormHelper::class)->formAlter($form, $form_state, $form_id);
// User form (Login, Register or Forgot password).
if (strpos($form_id, 'user_login') !== FALSE || strpos($form_id, 'user_register') !== FALSE || strpos($form_id, 'user_pass') !== FALSE) {
$form['actions']['submit']['#attributes']['class'][] = 'button--primary';
}
// Bulk forms: update action & actions to small variants.
if (strpos($form_id, 'views_form') !== FALSE) {
if (isset($form['header'])) {
$bulk_form = current(preg_grep('/_bulk_form/', array_keys($form['header'])));
if (isset($form['header'][$bulk_form])) {
$form['header'][$bulk_form]['action']['#attributes']['class'][] = 'form-element--type-select--small';
$form['header'][$bulk_form]['actions']['submit']['#attributes']['class'][] = 'button--small';
// Remove double entry of submit button.
unset($form['actions']['submit']);
}
}
}
// Delete forms: alter buttons.
if (strpos($form_id, 'delete_form') !== FALSE) {
$form['actions']['submit']['#attributes']['class'][] = 'button--danger';
$form['actions']['cancel']['#attributes']['class'][] = 'button--secondary';
}
}
/**
* Implements form_user_form_alter().
*/
function gin_form_user_form_alter(&$form, FormStateInterface $form_state) {
// If new user account, don't show settings yet.
if ($form_state->getFormObject()->getEntity()->isNew()) {
return;
}
/** @var \Drupal\gin\GinSettings $settings */
$settings = \Drupal::classResolver(GinSettings::class);
if ($settings->allowUserOverrides()) {
// Inject the settings for the dark mode feature.
$form['gin_theme_settings'] = [
'#type' => 'details',
'#title' => t('Admin theme settings'),
'#open' => TRUE,
'#weight' => 90,
];
/** @var \Drupal\Core\Session\AccountInterface $account */
$account = $form_state->getBuildInfo()['callback_object']->getEntity();
$form['gin_theme_settings']['enable_user_settings'] = [
'#type' => 'checkbox',
'#title' => t('Enable overrides'),
'#description' => t("Enables default admin theme overrides."),
'#default_value' => $settings->userOverrideEnabled($account),
'#weight' => 0,
];
$form['gin_theme_settings']['user_settings'] = [
'#type' => 'container',
'#states' => [
// Show if met.
'visible' => [
':input[name="enable_user_settings"]' => ['checked' => TRUE],
],
],
] + $settings->getSettingsForm($account);
// Attach custom library.
$form['#attached']['library'][] = 'gin/settings';
array_unshift($form['actions']['submit']['#submit'], '_gin_user_form_submit');
}
}
/**
* Implements template_preprocess_HOOK() for select.
*/
function gin_preprocess_select(&$variables) {
if (in_array('block-weight', $variables['attributes']['class'], TRUE)) {
$variables['attributes']['class'][] = 'form-element--extrasmall';
}
}
/**
* Implements form_alter() for forms.
*/
function gin_theme_suggestions_form_alter(array &$suggestions, array $variables) {
$suggestions[] = 'form__' . str_replace('-', '_', $variables['element']['#id']);
}
/**
* Implements form_alter() for input.
*/
function gin_theme_suggestions_input_alter(array &$suggestions, array $variables) {
if ($variables['element']['#type'] === 'checkbox') {
// Way to identify if checkbox is in a checkboxes group
// as Drupal doesn't provide one yet (see #2643012)
if (!isset($variables['element']['#error_no_message'])) {
$suggestions[] = 'input__checkbox__toggle';
}
}
}
/**
* Implements template_preprocess_HOOK() for form_element.
*/
function gin_preprocess_form_element(&$variables) {
\Drupal::classResolver(GinDescriptionToggle::class)->preprocess($variables);
}
/**
* Implements template_preprocess_HOOK() for datetime_wrapper.
*/
function gin_preprocess_datetime_wrapper(&$variables) {
\Drupal::classResolver(GinDescriptionToggle::class)->preprocess($variables);
}
/**
* Implements template_preprocess_HOOK() for details.
*/
function gin_preprocess_details(&$variables) {
\Drupal::classResolver(GinDescriptionToggle::class)->preprocess($variables);
}
/**
* Implements template_preprocess_HOOK() for fieldset.
*/
function gin_preprocess_fieldset(&$variables) {
\Drupal::classResolver(GinDescriptionToggle::class)->preprocess($variables);
}
/**
* Implements hook_element_info_alter().
*/
function gin_element_info_alter(&$info) {
if (array_key_exists('text_format', $info)) {
$info['text_format']['#pre_render'][] = [
GinPreRender::class,
'textFormat',
];
}
}
/**
* Implements template_preprocess_HOOK() for text_format_wrapper.
*/
function gin_preprocess_text_format_wrapper(&$variables) {
/** @var \Drupal\gin\GinSettings $settings */
$settings = \Drupal::classResolver(GinSettings::class);
if ($settings->get('show_description_toggle') && !empty($variables['description'])) {
$variables['description_display'] = 'invisible';
$variables['description_toggle'] = TRUE;
}
}
/**
* Implements template_preprocess_inline_entity_form_entity_table() for forms.
*/
function gin_preprocess_inline_entity_form_entity_table(array &$variables) {
$variables['table']['#attached']['library'][] = 'gin/inline_entity_form';
}

View File

@@ -0,0 +1,102 @@
<?php
/**
* @file
* helper.theme
*/
use Drupal\Core\Form\FormStateInterface;
use Drupal\gin\GinSettings;
/**
* Accent color element.
*/
function _gin_accent_radios($element) {
$options = array_keys($element['#options']);
foreach ($options as $values) {
$element[$values]['#attributes']['data-gin-accent'] = $element[$values]['#return_value'];
}
return $element;
}
/**
* Toolbar element.
*/
function _gin_toolbar_radios($element) {
$options = array_keys($element['#options']);
$element['#attributes']['class'][] = 'toolbar-option';
foreach ($options as $values) {
$element[$values]['#attributes']['class'][] = 'toolbar-option__' . $element[$values]['#return_value'];
$element[$values]['#attributes']['data-gin-toolbar'] = $element[$values]['#return_value'];
}
return $element;
}
/**
* Implements helper function _gin_user_form_submit().
*/
function _gin_user_form_submit(&$form, FormStateInterface $form_state) {
/** @var \Drupal\Core\Session\AccountInterface $account */
$account = $form_state->getBuildInfo()['callback_object']->getEntity();
$enabledUserOverrides = $form_state->getValue('enable_user_settings');
/** @var \Drupal\gin\GinSettings $settings */
$settings = \Drupal::classResolver(GinSettings::class);
if ($enabledUserOverrides) {
$user_settings = [
'enable_darkmode' => $form_state->getValue('enable_darkmode'),
'preset_accent_color' => $form_state->getValue('preset_accent_color'),
'accent_color' => $form_state->getValue('accent_color'),
'classic_toolbar' => $form_state->getValue('classic_toolbar'),
'preset_focus_color' => $form_state->getValue('preset_focus_color'),
'focus_color' => $form_state->getValue('focus_color'),
'high_contrast_mode' => (bool) $form_state->getValue('high_contrast_mode'),
'layout_density' => $form_state->getValue('layout_density'),
'show_description_toggle' => $form_state->getValue('show_description_toggle'),
];
$settings->setAll($user_settings, $account);
}
else {
$settings->clear($account);
}
}
/**
* Helper function for check if Gin is active.
*/
function _gin_is_active() {
$theme_handler = \Drupal::service('theme_handler')->listInfo();
// Check if set as frontend theme.
$frontend_theme_name = \Drupal::config('system.theme')->get('default');
// Check if base themes are set.
if (isset($theme_handler[$frontend_theme_name]->base_themes)) {
$frontend_base_themes = $theme_handler[$frontend_theme_name]->base_themes;
}
// Add theme name to base theme array.
$frontend_base_themes[$frontend_theme_name] = $frontend_theme_name;
// Check if set as admin theme.
$admin_theme_name = \Drupal::config('system.theme')->get('admin');
// Admin theme will have no value if it is set to use the default theme.
if ($admin_theme_name && isset($theme_handler[$admin_theme_name]->base_themes)) {
$admin_base_themes = $theme_handler[$admin_theme_name]->base_themes;
$admin_base_themes[$admin_theme_name] = $admin_theme_name;
}
else {
$admin_base_themes = $frontend_base_themes;
}
$base_themes = array_merge($admin_base_themes, $frontend_base_themes);
$gin_activated = array_key_exists('gin', $base_themes);
return $gin_activated;
}

View File

@@ -0,0 +1,95 @@
<?php
/**
* @file
* html.theme
*/
use Drupal\gin\GinContentFormHelper;
use Drupal\gin\GinNavigation;
use Drupal\gin\GinSettings;
/**
* Implements hook_preprocess_HOOK() for html.
*/
function gin_preprocess_html(&$variables) {
// Are we relevant?
$gin_activated = _gin_is_active();
if ($gin_activated) {
// Get theme settings.
/** @var \Drupal\gin\GinSettings $settings */
$settings = \Drupal::classResolver(GinSettings::class);
$toolbar = $settings->get('classic_toolbar');
// Set accent color.
$variables['attributes']['data-gin-accent'] = $settings->get('preset_accent_color');
// Set focus color.
$variables['attributes']['data-gin-focus'] = $settings->get('preset_focus_color');
// High contrast mode.
if ($settings->get('high_contrast_mode')) {
$variables['attributes']['class'][] = 'gin--high-contrast-mode';
}
// Set layout density.
$variables['attributes']['data-gin-layout-density'] = $settings->get('layout_density');
// Edit form? Use the new Gin Edit form layout.
if (\Drupal::classResolver(GinContentFormHelper::class)->isContentForm()) {
$variables['attributes']['class'][] = 'gin--edit-form';
}
// Only add gin--classic-toolbar class if user has permission.
if (!\Drupal::currentUser()->hasPermission('access toolbar')) {
return;
}
// Check for new Drupal navigation.
if ($toolbar === 'new') {
/** @var \Drupal\gin\GinNavigaton $navigation */
$navigation = \Drupal::classResolver(GinNavigation::class);
// Get new navigation.
$variables['page_top']['navigation'] = $navigation->getNavigationStructure();
// Get active trail.
$variables['#attached']['drupalSettings']['active_trail_paths'] = $navigation->getNavigationActiveTrail();
// Set toolbar class.
$variables['attributes']['class'][] = 'gin--navigation';
}
else {
// Set toolbar class.
$variables['attributes']['class'][] = 'gin--' . $toolbar . '-toolbar';
}
// Gin secondary toolbar.
if ($toolbar !== 'classic') {
$variables['page']['gin_secondary_toolbar'] = [
'#type' => 'toolbar',
'#access' => \Drupal::currentUser()->hasPermission('access toolbar'),
'#cache' => [
'keys' => ['toolbar_secondary'],
'contexts' => ['user.permissions'],
],
'#attributes' => [
'id' => 'toolbar-administration-secondary',
],
];
}
}
}
/**
* Implements hook_preprocess_HOOK() for html__entity_browser__modal.
*/
function gin_preprocess_html__entity_browser__modal(&$variables) {
gin_preprocess_html($variables);
// Remove toolbar class in entity browser modal.
if (isset($variables['attributes']['class'])) {
$toolbar_class = preg_grep('/gin--(.*)-toolbar/', $variables['attributes']['class']);
foreach ($toolbar_class as $key => $class) {
unset($variables['attributes']['class'][$key]);
}
}
}

View File

@@ -0,0 +1,17 @@
<?php
/**
* @file
* node.theme
*/
/**
* Implements hook_preprocess_HOOK() for node_edit_form.
*/
function gin_preprocess_node_edit_form(&$variables) {
$module_handler = \Drupal::service('module_handler');
// Check if Layout Paragraphs is active.
$layout_paragraphs = $module_handler->moduleExists('layout_paragraphs');
$variables['gin_layout_paragraphs'] = $layout_paragraphs;
}

View File

@@ -0,0 +1,142 @@
<?php
/**
* @file
* page.theme
*/
use Drupal\Core\Entity\EntityInterface;
use Drupal\gin\GinContentFormHelper;
use Drupal\gin\GinSettings;
use Drupal\node\Entity\Node;
/**
* Implements hook_preprocess_HOOK() for page.
*/
function gin_preprocess_page(&$variables) {
// Required for allowing subtheming Gin.
$activeThemeName = \Drupal::theme()->getActiveTheme()->getName();
$variables['active_admin_theme'] = $activeThemeName;
/** @var \Drupal\gin\GinSettings $settings */
$settings = \Drupal::classResolver(GinSettings::class);
// Expose Toolbar variant.
$variables['toolbar_variant'] = $settings->get('classic_toolbar');
// Expose Route name.
$variables['route_name'] = \Drupal::routeMatch()->getRouteName();
if (preg_match('#entity\.(?<entity_type_id>.+)\.canonical#', $variables['route_name'], $matches)) {
$entity = \Drupal::request()->attributes->get($matches['entity_type_id']);
if ($entity instanceof EntityInterface && $entity->hasLinkTemplate('edit-form')) {
$variables['entity_title'] = $entity->label();
$variables['entity_edit_url'] = $entity->toUrl('edit-form');
}
}
}
/**
* Implements hook_preprocess_HOOK() for page_alter.
*/
function gin_theme_suggestions_page_alter(&$suggestions, $variables) {
$path = \Drupal::requestStack()->getCurrentRequest()->getPathInfo();
if ($path != '/') {
$path = trim($path, '/');
$arg = str_replace(["/", '-'], ['_', '_'], $path);
$suggestions[] = 'page__' . $arg;
}
// The node page template is required to use the node content form.
if (\Drupal::classResolver(GinContentFormHelper::class)->isContentForm()
&& !in_array('page__node', $suggestions)) {
$suggestions[] = 'page__node';
}
}
/**
* Implements hook_preprocess_HOOK() for page_attachments.
*/
function gin_page_attachments_alter(&$page) {
// Are we relevant?
$gin_activated = _gin_is_active();
if ($gin_activated) {
// Attach the init script.
$page['#attached']['library'][] = 'gin/gin_init';
// Attach breadcrumb styles.
$page['#attached']['library'][] = 'gin/breadcrumb';
// Attach accent library.
$page['#attached']['library'][] = 'gin/gin_accent';
// Attach sticky library.
$page['#attached']['library'][] = 'gin/sticky';
// Attach Drupal.once for older Drupal versions.
$drupal_version = (float) Drupal::VERSION;
if ($drupal_version < 9.3) {
$page['#attached']['library'][] = 'gin/once';
}
// Custom CSS file.
if (file_exists('public://gin-custom.css')) {
$page['#attached']['library'][] = 'gin/gin_custom_css';
}
// Expose settings to JS.
// Get theme settings.
$settings = \Drupal::classResolver(GinSettings::class);
$page['#attached']['drupalSettings']['gin']['darkmode'] = $settings->get('enable_darkmode');
$page['#attached']['drupalSettings']['gin']['darkmode_class'] = 'gin--dark-mode';
$page['#attached']['drupalSettings']['gin']['preset_accent_color'] = $settings->get('preset_accent_color');
$page['#attached']['drupalSettings']['gin']['accent_color'] = $settings->get('accent_color');
$page['#attached']['drupalSettings']['gin']['preset_focus_color'] = $settings->get('preset_focus_color');
$page['#attached']['drupalSettings']['gin']['focus_color'] = $settings->get('focus_color');
$page['#attached']['drupalSettings']['gin']['highcontrastmode'] = $settings->get('high_contrast_mode');
$page['#attached']['drupalSettings']['gin']['highcontrastmode_class'] = 'gin--high-contrast-mode';
$page['#attached']['drupalSettings']['gin']['toolbar_variant'] = $settings->get('classic_toolbar');
// Expose stylesheets to JS.
$basethemeurl = '/' . \Drupal::service('extension.list.theme')->getPath('gin');
$page['#attached']['drupalSettings']['gin']['variables_css_path'] = $basethemeurl . '/dist/css/theme/variables.css';
$page['#attached']['drupalSettings']['gin']['accent_css_path'] = $basethemeurl . '/dist/css/theme/accent.css';
$page['#attached']['drupalSettings']['gin']['ckeditor_css_path'] = $basethemeurl . '/dist/css/theme/ckeditor.css';
}
}
/**
* Page title.
*/
function gin_preprocess_page_title(&$variables) {
if (preg_match('/entity\.node\..*/', \Drupal::routeMatch()->getRouteName(), $matches)) {
$node = \Drupal::routeMatch()->getParameter('node');
if ($node instanceof Node) {
if ($node->isDefaultTranslation() && !in_array($matches[0], [
'entity.node.content_translation_add',
'entity.node.delete_form',
])) {
$variables['title'] = $node->getTitle();
}
elseif ($matches[0] === 'entity.node.edit_form') {
$variables['title_attributes']['class'][] = 'page-title--is-translation';
$args = [
'@title' => $node->getTitle(),
'@language' => $node->language()->getName(),
];
$variables['title'] = t('@title <span class="page-title__language">(@language translation)</span>', $args);
}
}
}
}
/**
* Node revisions.
*/
function gin_preprocess_page__node__revisions(&$page) {
// Attach the init script.
$page['#attached']['library'][] = 'gin/revisions';
}

View File

@@ -0,0 +1,13 @@
<?php
/**
* @file
* paragraphs.theme
*/
/**
* Implements hook_preprocess_HOOK() for paragraphs operations dropbutton.
*/
function gin_preprocess_links__dropbutton__operations__paragraphs(&$variables) {
$variables['attributes']['class'][] = 'dropbutton--small';
}

View File

@@ -0,0 +1,80 @@
<?php
/**
* @file
* settings.theme
*/
use Drupal\Core\Form\FormStateInterface;
use Drupal\gin\GinSettings;
/**
* Custom theme settings.
*/
function gin_form_system_theme_settings_alter(&$form, FormStateInterface $form_state, $form_id = NULL) {
// Work-around for a core bug affecting admin themes. See issue #943212.
if (isset($form_id)) {
return;
}
/*
* //////////////////////////
* Move default theme settings to bottom.
* * //////////////////////////
*/
$form['logo']['#weight'] = 97;
$form['favicon']['#open'] = FALSE;
$form['favicon']['#weight'] = 98;
$form['theme_settings']['#open'] = FALSE;
$form['theme_settings']['#weight'] = 99;
/*
* //////////////////////////
* General settings.
* * //////////////////////////
*/
/** @var \Drupal\gin\GinSettings $settings */
$settings = \Drupal::classResolver(GinSettings::class);
$form['custom_settings'] = [
'#type' => 'details',
'#open' => TRUE,
'#title' => t('Settings'),
] + $settings->getSettingsForm();
// Allow user settings.
$form['custom_settings']['show_user_theme_settings'] = [
'#type' => 'checkbox',
'#title' => t('Users can override Gin settings'),
'#description' => t('Expose the admin theme settings to users.'),
'#default_value' => $settings->getDefault('show_user_theme_settings'),
];
/*
* //////////////////////////
* Logo settings.
* * //////////////////////////
*/
$form['logo']['settings']['logo_upload']['#upload_validators'] = ['file_validate_extensions' => ['png gif jpg jpeg apng svg']];
// Upgrade path:
// Move settings to new fields.
if ($settings->getDefault('icon_default') === FALSE) {
$form['logo']['default_logo']['#default_value'] = FALSE;
$form['logo']['settings']['logo_path']['#default_value'] = $settings->getDefault('icon_path');
$form['#submit'][] = '_gin_form_system_theme_settings_form_submit';
}
// Attach custom library.
$form['#attached']['library'][] = 'gin/settings';
}
/**
* Cleanup settings.
*/
function _gin_form_system_theme_settings_form_submit(&$form, FormStateInterface $form_state) {
$config = \Drupal::configFactory()->getEditable('gin.settings');
$config->clear('icon_path')
->clear('icon_default')
->save();
}

View File

@@ -0,0 +1,19 @@
<?php
/**
* @file
* table.theme
*/
/**
* Implements form_alter() for table.
*/
function gin_theme_suggestions_table_alter(array &$suggestions, array $variables): void {
if (empty($variables['attributes']['class'])) {
return;
}
if (is_array($variables['attributes']['class']) && in_array('field-multiple-table', $variables['attributes']['class'])) {
$suggestions[] = 'table__simple';
}
}

View File

@@ -0,0 +1,70 @@
<?php
/**
* @file
* theme.theme
*/
use Drupal\gin\GinSettings;
/**
* Implements hook_theme().
*/
function gin_theme() {
// Get theme configs.
/** @var \Drupal\gin\GinSettings $settings */
$settings = \Drupal::classResolver(GinSettings::class);
$logo_default = $settings->getDefault('logo.use_default');
$icon_path = '';
if (!$logo_default) {
$icon_path = $settings->getDefault('logo.path');
}
// Check if help is enabled.
$help_enabled = FALSE;
$module_handler = \Drupal::service('module_handler');
if ($module_handler->moduleExists('help')) {
$help_enabled = TRUE;
}
$items['navigation'] = [
'variables' => [
'icon_path' => $icon_path,
'path' => \Drupal::service('extension.list.theme')->getPath('gin'),
'menu_middle' => [],
'menu_top' => [],
'menu_bottom' => [],
],
];
$items['menu_region__top'] = [
'variables' => [
'links' => [],
'title' => NULL,
'menu_name' => NULL,
],
];
$items['menu_region__middle'] = [
'base hook' => 'menu',
'variables' => [
'menu_name' => NULL,
'items' => [],
'attributes' => [],
'title' => NULL,
],
];
$items['menu_region__bottom'] = [
'variables' => [
'help_enabled' => $help_enabled,
'items' => [],
'title' => NULL,
'menu_name' => NULL,
'path' => \Drupal::service('extension.list.theme')->getPath('gin'),
],
];
return $items;
}

View File

@@ -0,0 +1,154 @@
<?php
/**
* @file
* toolbar.theme
*/
use Drupal\gin\GinSettings;
use Drupal\gin\GinUserPicture;
/**
* Implements hook_preprocess_menu().
*/
function gin_preprocess_menu(&$variables) {
if (isset($variables['theme_hook_original']) && $variables['theme_hook_original'] == 'menu__toolbar__admin') {
// Check if the admin_toolbar module is installed.
foreach ($variables['items'] as $key => $item) {
$gin_id = str_replace('.', '-', $key);
$variables['items'][$key]['gin_id'] = $gin_id;
}
// Move config & help menu items to end.
$to_move = ['system.admin_config', 'help.main'];
foreach ($to_move as $id) {
$index = array_search($id, array_keys($variables['items']));
if (is_numeric($index)) {
$variables['items'] += array_splice($variables['items'], $index, 1);
}
}
}
}
/**
* Implements hook_preprocess_menu__toolbar__gin().
*/
function gin_preprocess_menu__toolbar__gin(&$variables) {
// Get theme settings.
/** @var \Drupal\gin\GinSettings $settings */
$settings = \Drupal::classResolver(GinSettings::class);
$logo_path = $settings->getDefault('logo.path');
$logo_default = $settings->getDefault('logo.use_default');
$variables['icon_default'] = $logo_default;
if (!$logo_default) {
$variables['icon_path'] = $logo_path;
}
// Expose Toolbar variant.
$variables['toolbar_variant'] = $settings->get('classic_toolbar');
}
/**
* Implements toolbar preprocess.
*/
function gin_preprocess_toolbar(&$variables) {
// Use single `:` to make ControllerResolver get the class from definition.
// @see Drupal\Core\Controller\ControllerResolver->createController().
$variables['user_picture'] = [
'#lazy_builder' => [
GinUserPicture::class . ':build',
[],
],
'#create_placeholder' => TRUE,
];
// Expose Toolbar variant.
/** @var \Drupal\gin\GinSettings $settings */
$settings = \Drupal::classResolver(GinSettings::class);
$variables['toolbar_variant'] = $settings->get('classic_toolbar');
switch ($variables['toolbar_variant']) {
case 'classic':
// Attach the classic toolbar styles.
$variables['#attached']['library'][] = 'gin/gin_classic_toolbar';
break;
case 'horizontal':
// Attach the horizontal toolbar styles.
$variables['#attached']['library'][] = 'gin/gin_horizontal_toolbar';
break;
case 'new':
// Attach the new drupal navigation styles.
$variables['#attached']['library'][] = 'gin/navigation';
break;
default:
// Attach toolbar styles.
$variables['#attached']['library'][] = 'gin/gin_toolbar';
break;
}
}
/**
* Implements toolbar preprocess.
*/
function gin_preprocess_toolbar__gin__secondary(&$variables) {
// Expose Toolbar variant.
/** @var \Drupal\gin\GinSettings $settings */
$settings = \Drupal::classResolver(GinSettings::class);
$variables['toolbar_variant'] = $settings->get('classic_toolbar');
if ($variables['toolbar_variant'] !== 'classic') {
// Move Admin Toolbar Search to start.
$toolbar_search = array_search('administration_search', array_keys($variables['tabs']));
if (is_numeric($toolbar_search)) {
foreach ($variables['tabs'] as $key => $item) {
if ($key === 'administration_search') {
array_unshift($variables['tabs'], $variables['tabs'][$key]);
unset($variables['tabs'][$key]);
}
}
}
}
// Move user tab to end.
$toolbar_user = array_search('user', array_keys($variables['tabs']));
if (is_numeric($toolbar_user)) {
foreach ($variables['tabs'] as $key => $item) {
if ($key === 'user') {
$user_tab = $variables['tabs'][$key];
unset($variables['tabs'][$key]);
$variables['tabs'][$key] = $user_tab;
}
}
}
}
/**
* Toolbar alter().
*/
function gin_theme_suggestions_toolbar_alter(array &$suggestions, array $variables) {
/** @var \Drupal\gin\GinSettings $settings */
$settings = \Drupal::classResolver(GinSettings::class);
$toolbar = $settings->get('classic_toolbar');
$suggestions[] = 'toolbar__gin';
// Only if Classic Toolbar is disabled.
if ($toolbar !== 'classic') {
if ($variables['element']['#attributes']['id'] === 'toolbar-administration-secondary') {
$suggestions[] = 'toolbar__gin__secondary';
}
}
}
/**
* Toolbar menu alter().
*/
function gin_theme_suggestions_menu_alter(array &$suggestions, array $variables) {
if (isset($variables['theme_hook_original']) && $variables['theme_hook_original'] == 'menu__toolbar__admin') {
$suggestions[] = 'menu__toolbar__gin';
}
}