Skip to content
Snippets Groups Projects
Commit b16d0446 authored by Mykola Antoshchuk's avatar Mykola Antoshchuk
Browse files

Issue #3443379 by Mykola Antoshchuk: Drupal 10 compatibility fixes

parent 86d67de6
No related branches found
No related tags found
No related merge requests found
......@@ -73,10 +73,8 @@ function bootstrapper_html_head_alter(&$header) {
* @param $hook
*/
function bootstrapper_theme_suggestions_alter(array &$suggestions, array &$variables, $hook) {
// Page suggestions.
if ($hook == 'page') {
// Page by route name.
$suggestions[] = $hook . '__' . str_replace('.', '_', \Drupal::routeMatch()->getRouteName());
......@@ -105,23 +103,38 @@ function bootstrapper_theme_suggestions_alter(array &$suggestions, array &$varia
array_splice($suggestions, 2, 0, $hook . '__' . 'taxonomy__term' . '__' . $term->bundle());
}
}
}
// Add page suggestions to regions to process them later in "region" suggestions.
$regions = \Drupal::theme()->getActiveTheme()->getRegions();
foreach ($regions as $region) {
if (isset($variables['page'][$region])) {
$variables['page'][$region]['#page_suggestions'] = $suggestions;
if ($hook == 'fieldset' ) {
$element_type = $variables["element"]["#type"] ?? '';
$page_suggestions = system_theme_suggestions_page([]);
if (isset($page_suggestions)) {
// Add region suggestions depending on page suggestions.
$fieldset_suggestions = [];
foreach ($page_suggestions as $page_suggestion) {
if ($suggestions) {
foreach ($suggestions as $region_suggestion) {
$fieldset_suggestions[] = 'fieldset__' . $page_suggestion . '__' . $fieldset_suggestions . '__' . $element_type;
}
}
else {
$fieldset_suggestions[] = 'fieldset__' . $page_suggestion . '__' . $element_type;
}
}
$suggestions = array_merge($suggestions, $fieldset_suggestions);
}
}
// Region suggestions.
if ($hook == 'region') {
if (isset($variables['elements']['#page_suggestions']) && $variables['elements']['#page_suggestions']) {
$page_suggestions = system_theme_suggestions_page([]);
bootstrapper_getThemeSuggestions($page_suggestions, $hook);
if (isset($page_suggestions)) {
// Add region suggestions depending on page suggestions.
$region_suggestions = [];
foreach ($variables['elements']['#page_suggestions'] as $page_suggestion) {
foreach ($page_suggestions as $page_suggestion) {
foreach ($suggestions as $region_suggestion) {
$region_suggestions[] = 'region__' . $page_suggestion . '__' . $region_suggestion;
}
......@@ -275,3 +288,35 @@ function bootstrapper_preprocess(&$variables, $hook, $info) {
}
}
function bootstrapper_getThemeSuggestions(&$suggestions, $hook) {
// Page by route name.
$suggestions[] = 'page__' . str_replace('.', '_', \Drupal::routeMatch()->getRouteName());
// Page by node type.
if ($node = \Drupal::request()->attributes->get('node')) {
// If the variable $node is string, suspecting it's a node ID,
// then load the node by ID.
if (is_string($node)) {
$node = \Drupal\node\Entity\Node::load($node);
}
if ($node) {
array_splice($suggestions, 1, 0, 'page__' . 'node' . '__' . $node->bundle());
}
}
// Page by taxonomy vocabulary type.
if ($term = \Drupal::request()->attributes->get('taxonomy_term')) {
// If the variable $taxonomy_term is string, suspecting it's a term ID,
// then load the term by ID.
if (is_string($term)) {
$term = \Drupal\taxonomy\Entity\Term::load($term);
}
if ($term) {
array_splice($suggestions, 2, 0, 'page__' . 'taxonomy__term' . '__' . $term->bundle());
}
}
}
......@@ -10,7 +10,7 @@
* @see template_preprocess_select()
*/
#}
{% spaceless %}
{% apply spaceless %}
<select{{ attributes }}>
{% for option in options %}
{% if option.type == 'optgroup' %}
......@@ -24,4 +24,4 @@
{% endif %}
{% endfor %}
</select>
{% endspaceless %}
{% endapply %}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment