From 84e67572112734c45ad5e3ccfd386fb2870210b9 Mon Sep 17 00:00:00 2001 From: rdrew Date: Wed, 6 May 2026 11:04:24 -0300 Subject: [PATCH] facet decimal removal --- .php-cs-fixer.cache | 1 + .php-cs-fixer.dist.php | 28 + Untitled | 3 - js/nouislider-year-format.js | 45 ++ olivesnews.libraries.yml | 8 +- olivesnews.theme | 953 ++++++++++++++++++----------------- 6 files changed, 560 insertions(+), 478 deletions(-) create mode 100644 .php-cs-fixer.cache create mode 100644 .php-cs-fixer.dist.php delete mode 100644 Untitled create mode 100644 js/nouislider-year-format.js diff --git a/.php-cs-fixer.cache b/.php-cs-fixer.cache new file mode 100644 index 0000000..4f0d5d8 --- /dev/null +++ b/.php-cs-fixer.cache @@ -0,0 +1 @@ +{"php":"8.5.4","version":"3.94.2","indent":" ","lineEnding":"\n","rules":{"nullable_type_declaration":true,"operator_linebreak":true,"ordered_types":{"null_adjustment":"always_last","sort_algorithm":"none"},"single_class_element_per_statement":true,"types_spaces":true,"array_indentation":true,"array_syntax":true,"attribute_block_no_spaces":true,"cast_spaces":true,"concat_space":{"spacing":"one"},"function_declaration":{"closure_fn_spacing":"none"},"method_argument_space":{"after_heredoc":false},"new_with_parentheses":{"anonymous_class":false},"single_line_empty_body":true,"single_space_around_construct":{"constructs_followed_by_a_single_space":["abstract","as","case","catch","class","const","const_import","do","else","elseif","enum","final","finally","for","foreach","function","function_import","if","insteadof","interface","match","named_argument","namespace","new","private","protected","public","readonly","static","switch","trait","try","type_colon","use","use_lambda","while"],"constructs_preceded_by_a_single_space":["as","else","elseif","use_lambda"]},"trailing_comma_in_multiline":{"after_heredoc":true,"elements":["arguments","array_destructuring","arrays","match","parameters"]},"binary_operator_spaces":{"default":"at_least_single_space"},"blank_line_after_opening_tag":true,"blank_line_between_import_groups":true,"blank_lines_before_namespace":true,"braces_position":{"allow_single_line_anonymous_functions":false,"allow_single_line_empty_anonymous_classes":true},"class_definition":{"inline_constructor_arguments":false,"space_before_parenthesis":true},"compact_nullable_type_declaration":true,"declare_equal_normalize":true,"lowercase_cast":true,"lowercase_static_reference":true,"modifier_keywords":true,"no_blank_lines_after_class_opening":true,"no_extra_blank_lines":{"tokens":["use"]},"no_leading_import_slash":true,"no_whitespace_in_blank_line":true,"ordered_class_elements":{"order":["use_trait"]},"ordered_imports":{"imports_order":["class","function","const"],"sort_algorithm":"none"},"return_type_declaration":true,"short_scalar_cast":true,"single_import_per_statement":{"group_to_single_imports":false},"single_trait_insert_per_statement":true,"ternary_operator_spaces":true,"unary_operator_spaces":{"only_dec_inc":true},"blank_line_after_namespace":true,"constant_case":true,"control_structure_braces":true,"control_structure_continuation_position":true,"elseif":true,"indentation_type":true,"line_ending":true,"lowercase_keywords":true,"no_break_comment":true,"no_closing_tag":true,"no_multiple_statements_per_line":true,"no_space_around_double_colon":true,"no_spaces_after_function_name":true,"no_trailing_whitespace":true,"no_trailing_whitespace_in_comment":true,"single_blank_line_at_eof":true,"single_line_after_imports":true,"spaces_inside_parentheses":true,"statement_indentation":true,"switch_case_semicolon_to_colon":true,"switch_case_space":true,"encoding":true,"full_opening_tag":true},"ruleCustomisationPolicyVersion":"null-policy","hashes":{".conform.8290495.olivesnews.theme":"ba279df37643b4e7b3b1d36edca92d5a",".conform.9049921.olivesnews.theme":"ba279df37643b4e7b3b1d36edca92d5a",".conform.4231873.olivesnews.theme":"e576b2c4cb832ca7a39815102ad561ab"}} \ No newline at end of file diff --git a/.php-cs-fixer.dist.php b/.php-cs-fixer.dist.php new file mode 100644 index 0000000..4324ce9 --- /dev/null +++ b/.php-cs-fixer.dist.php @@ -0,0 +1,28 @@ +setRiskyAllowed(false) + ->setRules([ + '@auto' => true + ]) + // 💡 by default, Fixer looks for `*.php` files excluding `./vendor/` - here, you can groom this config + ->setFinder( + (new Finder()) + // 💡 root folder to check + ->in(__DIR__) + // 💡 additional files, eg bin entry file + // ->append([__DIR__.'/bin-entry-file']) + // 💡 folders to exclude, if any + // ->exclude([/* ... */]) + // 💡 path patterns to exclude, if any + // ->notPath([/* ... */]) + // 💡 extra configs + // ->ignoreDotFiles(false) // true by default in v3, false in v4 or future mode + // ->ignoreVCS(true) // true by default + ) +; diff --git a/Untitled b/Untitled deleted file mode 100644 index f69dd9f..0000000 --- a/Untitled +++ /dev/null @@ -1,3 +0,0 @@ -:q -:q - diff --git a/js/nouislider-year-format.js b/js/nouislider-year-format.js new file mode 100644 index 0000000..98d0577 --- /dev/null +++ b/js/nouislider-year-format.js @@ -0,0 +1,45 @@ +(function (Drupal) { + "use strict"; + + Drupal.behaviors.nouisliderYearFormat = { + attach: function (context, settings) { + // Target the slider directly by its rendered ID. + // Your facet renders the slider as
+ const sliderEl = context.querySelector("#year.noUi-target"); + + if (!sliderEl || !sliderEl.noUiSlider) return; + + const integerFormat = { + to: function (value) { + return String(Math.round(value)); + }, + from: function (value) { + return Math.round(Number(value)); + }, + }; + + // Override format and tooltips together + sliderEl.noUiSlider.updateOptions({ + format: integerFormat, + tooltips: [integerFormat, integerFormat], + }); + + // Also fix the input fields — they get their initial value from the slider's + // 'update' event, but that fires before our override. Re-trigger manually: + const inputFrom = document.getElementById("nouislider-input-from"); + const inputTo = document.getElementById("nouislider-input-to"); + + if (inputFrom && inputTo) { + const values = sliderEl.noUiSlider.get(); + inputFrom.value = Math.round(Number(values[0])); + inputTo.value = Math.round(Number(values[1])); + + // Keep inputs in sync going forward + sliderEl.noUiSlider.on("update", function (values) { + inputFrom.value = Math.round(Number(values[0])); + inputTo.value = Math.round(Number(values[1])); + }); + } + }, + }; +})(Drupal); diff --git a/olivesnews.libraries.yml b/olivesnews.libraries.yml index 3db1dce..88fe3ae 100755 --- a/olivesnews.libraries.yml +++ b/olivesnews.libraries.yml @@ -67,6 +67,12 @@ global-styling: - core/tabbable - olivesnews/navigation-base +nouislider-year-format: + js: + js/nouislider-year-format.js: {} + dependencies: + - core/drupal + book: version: VERSION css: @@ -83,7 +89,7 @@ mirador-mods: version: VERSION js: js/mirador-mods.js: {} - + color-picker: version: VERSION css: diff --git a/olivesnews.theme b/olivesnews.theme index e772581..39f6b3a 100755 --- a/olivesnews.theme +++ b/olivesnews.theme @@ -17,561 +17,588 @@ use Drupal\user\UserInterface; * * Adds body classes if certain regions have content. */ -function olivesnews_preprocess_html(&$variables) { - if (theme_get_setting('mobile_menu_all_widths') === 1) { - $variables['attributes']['class'][] = 'is-always-mobile-nav'; - } +function olivesnews_preprocess_html(&$variables) +{ + if (theme_get_setting('mobile_menu_all_widths') === 1) { + $variables['attributes']['class'][] = 'is-always-mobile-nav'; + } - // Convert custom hex to hsl so we can use the hue value - $brand_color_hex = theme_get_setting('base_primary_color') ?? '#1b9ae4'; - [$h, $s, $l] = _olivesnews_hex_to_hsl($brand_color_hex); + // Convert custom hex to hsl so we can use the hue value + $brand_color_hex = theme_get_setting('base_primary_color') ?? '#1b9ae4'; + [$h, $s, $l] = _olivesnews_hex_to_hsl($brand_color_hex); - $variables['html_attributes']->setAttribute('style', "--color--primary-hue:$h;--color--primary-saturation:$s%;--color--primary-lightness:$l"); + $variables['html_attributes']->setAttribute('style', "--color--primary-hue:$h;--color--primary-saturation:$s%;--color--primary-lightness:$l"); - // So fonts can be preloaded from base theme in the event Olivesnews is used as a subtheme. - $variables['olivesnews_path'] = \Drupal::request()->getBasePath() . '/' . \Drupal::service('extension.list.theme')->getPath('olivesnews'); + // So fonts can be preloaded from base theme in the event Olivesnews is used as a subtheme. + $variables['olivesnews_path'] = \Drupal::request()->getBasePath() . '/' . \Drupal::service('extension.list.theme')->getPath('olivesnews'); - $query_string = \Drupal::state()->get('system.css_js_query_string') ?: '0'; + $query_string = \Drupal::state()->get('system.css_js_query_string') ?: '0'; - // Create render array with noscript tag to output non-JavaScript - // stylesheet for primary menu. - $variables['noscript_styles'] = [ - '#type' => 'html_tag', - '#noscript' => TRUE, - '#tag' => 'link', - '#attributes' => [ - 'rel' => 'stylesheet', - 'href' => $variables['olivesnews_path'] . '/css/components/navigation/nav-primary-no-js.css?' . $query_string, - ], - ]; -// Use routeMatch — this is the modern, preferred way. - $node = \Drupal::routeMatch()->getParameter('node'); + // Create render array with noscript tag to output non-JavaScript + // stylesheet for primary menu. + $variables['noscript_styles'] = [ + '#type' => 'html_tag', + '#noscript' => true, + '#tag' => 'link', + '#attributes' => [ + 'rel' => 'stylesheet', + 'href' => $variables['olivesnews_path'] . '/css/components/navigation/nav-primary-no-js.css?' . $query_string, + ], + ]; + // Use routeMatch — this is the modern, preferred way. + $node = \Drupal::routeMatch()->getParameter('node'); - if ($node instanceof \Drupal\node\NodeInterface) { - // Add a simple node-ID class (most common format today). - $variables['attributes']['class'][] = 'node-' . $node->id(); + if ($node instanceof \Drupal\node\NodeInterface) { + // Add a simple node-ID class (most common format today). + $variables['attributes']['class'][] = 'node-' . $node->id(); - // Optional: Add the classic Drupal 7-style class if you prefer / need it for legacy CSS. - // $variables['attributes']['class'][] = 'page-node-' . $node->id(); + // Optional: Add the classic Drupal 7-style class if you prefer / need it for legacy CSS. + // $variables['attributes']['class'][] = 'page-node-' . $node->id(); - // Optional extras people often add at the same time: - // $variables['attributes']['class'][] = 'node-type-' . $node->bundle(); - // $variables['attributes']['class'][] = 'node-' . $node->bundle(); - } + // Optional extras people often add at the same time: + // $variables['attributes']['class'][] = 'node-type-' . $node->bundle(); + // $variables['attributes']['class'][] = 'node-' . $node->bundle(); + } } /** * Implements hook_preprocess_HOOK() for page title templates. */ -function olivesnews_preprocess_page_title(&$variables) { - // Since the title and the shortcut link are both block level elements, - // positioning them next to each other is much simpler with a wrapper div. - if (!empty($variables['title_suffix']['add_or_remove_shortcut']) && $variables['title']) { - // Add a wrapper div using the title_prefix and title_suffix render - // elements. - $variables['title_prefix']['shortcut_wrapper'] = [ - '#markup' => '
', - '#weight' => 100, - ]; - $variables['title_suffix']['shortcut_wrapper'] = [ - '#markup' => '
', - '#weight' => -99, - ]; - - // Make sure the shortcut link is the first item in title_suffix. - $variables['title_suffix']['add_or_remove_shortcut']['#weight'] = -100; - } +function olivesnews_preprocess_page_title(&$variables) +{ + // Since the title and the shortcut link are both block level elements, + // positioning them next to each other is much simpler with a wrapper div. + if (!empty($variables['title_suffix']['add_or_remove_shortcut']) && $variables['title']) { + // Add a wrapper div using the title_prefix and title_suffix render + // elements. + $variables['title_prefix']['shortcut_wrapper'] = [ + '#markup' => '
', + '#weight' => 100, + ]; + $variables['title_suffix']['shortcut_wrapper'] = [ + '#markup' => '
', + '#weight' => -99, + ]; + + // Make sure the shortcut link is the first item in title_suffix. + $variables['title_suffix']['add_or_remove_shortcut']['#weight'] = -100; + } - // Unset shortcut link on front page. - $variables['is_front'] = \Drupal::service('path.matcher')->isFrontPage(); - if ($variables['is_front'] === TRUE) { - unset($variables['title_suffix']['add_or_remove_shortcut']); - } + // Unset shortcut link on front page. + $variables['is_front'] = \Drupal::service('path.matcher')->isFrontPage(); + if ($variables['is_front'] === true) { + unset($variables['title_suffix']['add_or_remove_shortcut']); + } } /** * Implements hook_preprocess_HOOK() for maintenance-page.html.twig. */ -function olivesnews_preprocess_maintenance_page(&$variables) { - // By default, site_name is set to Drupal if no db connection is available - // or during site installation. Setting site_name to an empty string makes - // the site and update pages look cleaner. - // @see template_preprocess_maintenance_page - if (!$variables['db_is_active']) { - $variables['site_name'] = ''; - } +function olivesnews_preprocess_maintenance_page(&$variables) +{ + // By default, site_name is set to Drupal if no db connection is available + // or during site installation. Setting site_name to an empty string makes + // the site and update pages look cleaner. + // @see template_preprocess_maintenance_page + if (!$variables['db_is_active']) { + $variables['site_name'] = ''; + } - // Olivesnews has custom styling for the maintenance page. - $variables['#attached']['library'][] = 'olivesnews/maintenance-page'; + // Olivesnews has custom styling for the maintenance page. + $variables['#attached']['library'][] = 'olivesnews/maintenance-page'; } /** * Implements hook_preprocess_HOOK() for node.html.twig. */ -function olivesnews_preprocess_node(&$variables) { - // Remove the "Add new comment" link on teasers or when the comment form is - // displayed on the page. - if ($variables['teaser'] || !empty($variables['content']['comments']['comment_form'])) { - unset($variables['content']['links']['comment']['#links']['comment-add']); - } +function olivesnews_preprocess_node(&$variables) +{ + // Remove the "Add new comment" link on teasers or when the comment form is + // displayed on the page. + if ($variables['teaser'] || !empty($variables['content']['comments']['comment_form'])) { + unset($variables['content']['links']['comment']['#links']['comment-add']); + } - // Apply custom date formatter to "date" field. - if (!empty($variables['date']) && !empty($variables['display_submitted']) && $variables['display_submitted'] === TRUE) { - $variables['date'] = \Drupal::service('date.formatter')->format($variables['node']->getCreatedTime(), 'olivesnews_medium'); - } + // Apply custom date formatter to "date" field. + if (!empty($variables['date']) && !empty($variables['display_submitted']) && $variables['display_submitted'] === true) { + $variables['date'] = \Drupal::service('date.formatter')->format($variables['node']->getCreatedTime(), 'olivesnews_medium'); + } - // Pass layout variable to template if content type is article in full view - // mode. This is then used in the template to create a BEM style CSS class to - // control the layout. - if ($variables['node']->bundle() === 'article' && $variables['view_mode'] === 'full') { - $variables['layout'] = 'content-narrow'; - } + // Pass layout variable to template if content type is article in full view + // mode. This is then used in the template to create a BEM style CSS class to + // control the layout. + if ($variables['node']->bundle() === 'article' && $variables['view_mode'] === 'full') { + $variables['layout'] = 'content-narrow'; + } } /** * Implements hook_preprocess_HOOK() for block.html.twig. */ -function olivesnews_preprocess_block(&$variables) { - if (!empty($variables['elements']['#id'])) { - /** @var \Drupal\block\BlockInterface $block */ - $block = \Drupal::entityTypeManager() - ->getStorage('block') - ->load($variables['elements']['#id']); - if ($block) { - $region = $block->getRegion(); - - if ($variables['base_plugin_id'] === 'system_menu_block') { - $variables['content']['#attributes']['region'] = $region; - if ($region === 'sidebar') { - $variables['#attached']['library'][] = 'olivesnews/menu-sidebar'; +function olivesnews_preprocess_block(&$variables) +{ + if (!empty($variables['elements']['#id'])) { + /** @var \Drupal\block\BlockInterface $block */ + $block = \Drupal::entityTypeManager() + ->getStorage('block') + ->load($variables['elements']['#id']); + if ($block) { + $region = $block->getRegion(); + + if ($variables['base_plugin_id'] === 'system_menu_block') { + $variables['content']['#attributes']['region'] = $region; + if ($region === 'sidebar') { + $variables['#attached']['library'][] = 'olivesnews/menu-sidebar'; + } + } + + if ($variables['base_plugin_id'] === 'search_form_block') { + if ($region === 'primary_menu') { + $variables['#attached']['library'][] = 'olivesnews/search-narrow'; + $variables['content']['actions']['submit']['#theme_wrappers'] = ['input__submit__header_search']; + } elseif ($region === 'secondary_menu') { + $variables['#attached']['library'][] = 'olivesnews/search-wide'; + $variables['content']['actions']['submit']['#theme_wrappers'] = ['input__submit__header_search']; + } + } } - } + } - if ($variables['base_plugin_id'] === 'search_form_block') { - if ($region === 'primary_menu') { - $variables['#attached']['library'][] = 'olivesnews/search-narrow'; - $variables['content']['actions']['submit']['#theme_wrappers'] = ['input__submit__header_search']; - } - elseif ($region === 'secondary_menu') { - $variables['#attached']['library'][] = 'olivesnews/search-wide'; - $variables['content']['actions']['submit']['#theme_wrappers'] = ['input__submit__header_search']; + if ($variables['plugin_id'] === 'system_branding_block') { + $site_branding_color = theme_get_setting('site_branding_bg_color'); + if ($site_branding_color && $site_branding_color !== 'default') { + $variables['attributes']['class'][] = 'site-branding--bg-' . $site_branding_color; } - } } - } - if ($variables['plugin_id'] === 'system_branding_block') { - $site_branding_color = theme_get_setting('site_branding_bg_color'); - if ($site_branding_color && $site_branding_color !== 'default') { - $variables['attributes']['class'][] = 'site-branding--bg-' . $site_branding_color; + // Add a primary-nav class to main menu navigation block. + if ($variables['plugin_id'] === 'system_menu_block:main') { + $variables['attributes']['class'][] = 'primary-nav'; } - } - - // Add a primary-nav class to main menu navigation block. - if ($variables['plugin_id'] === 'system_menu_block:main') { - $variables['attributes']['class'][] = 'primary-nav'; - } - if ($variables['plugin_id'] === 'mirador_block') { + if ($variables['plugin_id'] === 'mirador_block') { - } + } } /** * Implements hook_theme_suggestions_HOOK_alter() for menu. */ -function olivesnews_theme_suggestions_menu_alter(&$suggestions, array $variables) { - if (isset($variables['attributes']['region'])) { - $suggestions[] = 'menu__' . $variables['attributes']['region']; - } +function olivesnews_theme_suggestions_menu_alter(&$suggestions, array $variables) +{ + if (isset($variables['attributes']['region'])) { + $suggestions[] = 'menu__' . $variables['attributes']['region']; + } } /** * Implements hook_preprocess_HOOK(). */ -function olivesnews_preprocess_menu(&$variables) { - if (isset($variables['attributes']['region'])) { - if ($variables['attributes']['region'] === 'sidebar') { - $variables['attributes']['class'][] = 'menu--sidebar'; +function olivesnews_preprocess_menu(&$variables) +{ + if (isset($variables['attributes']['region'])) { + if ($variables['attributes']['region'] === 'sidebar') { + $variables['attributes']['class'][] = 'menu--sidebar'; + } + unset($variables['attributes']['region']); } - unset($variables['attributes']['region']); - } } /** * Implements hook_theme_suggestions_HOOK_alter() for form templates. */ -function olivesnews_theme_suggestions_form_alter(array &$suggestions, array $variables) { - if ($variables['element']['#form_id'] === 'search_block_form') { - $suggestions[] = 'form__search_block_form'; - } +function olivesnews_theme_suggestions_form_alter(array &$suggestions, array $variables) +{ + if ($variables['element']['#form_id'] === 'search_block_form') { + $suggestions[] = 'form__search_block_form'; + } } /** * Implements hook_form_alter() for adding classes and placeholder text to the search forms. */ -function olivesnews_form_alter(&$form, FormStateInterface $form_state, $form_id) { - if (isset($form['actions']['submit']) && (count($form['actions'])) <= 2) { - $form['actions']['submit']['#attributes']['class'][] = 'button--primary'; - } +function olivesnews_form_alter(&$form, FormStateInterface $form_state, $form_id) +{ + if (isset($form['actions']['submit']) && (count($form['actions'])) <= 2) { + $form['actions']['submit']['#attributes']['class'][] = 'button--primary'; + } - switch ($form_id) { - case 'search_block_form': - // Add placeholder text to keys input. - $form['keys']['#attributes']['placeholder'] = t('Search by keyword or phrase.'); + switch ($form_id) { + case 'search_block_form': + // Add placeholder text to keys input. + $form['keys']['#attributes']['placeholder'] = t('Search by keyword or phrase.'); - // Add classes to the search form submit input. - $form['actions']['submit']['#attributes']['class'][] = 'search-form__submit'; - break; + // Add classes to the search form submit input. + $form['actions']['submit']['#attributes']['class'][] = 'search-form__submit'; + break; - case 'search_form': - $form['basic']['keys']['#attributes']['placeholder'] = t('Search by keyword or phrase.'); - $form['basic']['submit']['#attributes']['class'][] = 'button--primary'; - $form['advanced']['submit']['#attributes']['class'][] = 'button--primary'; - break; - } + case 'search_form': + $form['basic']['keys']['#attributes']['placeholder'] = t('Search by keyword or phrase.'); + $form['basic']['submit']['#attributes']['class'][] = 'button--primary'; + $form['advanced']['submit']['#attributes']['class'][] = 'button--primary'; + break; + } } /** * Implements hook_theme_suggestions_HOOK_alter() for block(). */ -function olivesnews_theme_suggestions_block_alter(&$suggestions, array $variables) { - if (!empty($variables['elements']['#id'])) { +function olivesnews_theme_suggestions_block_alter(&$suggestions, array $variables) +{ + if (!empty($variables['elements']['#id'])) { - /** @var \Drupal\block\BlockInterface $block */ - $block = \Drupal::entityTypeManager() - ->getStorage('block') - ->load($variables['elements']['#id']); - if ($block) { + /** @var \Drupal\block\BlockInterface $block */ + $block = \Drupal::entityTypeManager() + ->getStorage('block') + ->load($variables['elements']['#id']); + if ($block) { - // Add region-specific block theme suggestions. - $region = $block - ->getRegion(); + // Add region-specific block theme suggestions. + $region = $block + ->getRegion(); - $suggestions[] = 'block__' . $region; - $suggestions[] = 'block__' . $region . '__' . 'plugin_id' . '__' . $variables['elements']['#plugin_id']; - $suggestions[] = 'block__' . $region . '__' . 'id' . '__' . $variables['elements']['#id']; + $suggestions[] = 'block__' . $region; + $suggestions[] = 'block__' . $region . '__' . 'plugin_id' . '__' . $variables['elements']['#plugin_id']; + $suggestions[] = 'block__' . $region . '__' . 'id' . '__' . $variables['elements']['#id']; + } } - } } /** * Implements hook_preprocess_HOOK() for menu-local-tasks templates. */ -function olivesnews_preprocess_menu_local_tasks(&$variables) { - foreach (Element::children($variables['primary']) as $key) { - $variables['primary'][$key]['#level'] = 'primary'; - } - foreach (Element::children($variables['secondary']) as $key) { - $variables['secondary'][$key]['#level'] = 'secondary'; - } +function olivesnews_preprocess_menu_local_tasks(&$variables) +{ + foreach (Element::children($variables['primary']) as $key) { + $variables['primary'][$key]['#level'] = 'primary'; + } + foreach (Element::children($variables['secondary']) as $key) { + $variables['secondary'][$key]['#level'] = 'secondary'; + } } /** * Implements hook_preprocess_form_element(). */ -function olivesnews_preprocess_form_element(&$variables) { - if (in_array($variables['element']['#type'] ?? FALSE, ['checkbox', 'radio'], TRUE)) { - $variables['attributes']['class'][] = 'form-type-boolean'; - } +function olivesnews_preprocess_form_element(&$variables) +{ + if (in_array($variables['element']['#type'] ?? false, ['checkbox', 'radio'], true)) { + $variables['attributes']['class'][] = 'form-type-boolean'; + } - if (!empty($variables['description']['attributes'])) { - $variables['description']['attributes']->addClass('form-item__description'); - } + if (!empty($variables['description']['attributes'])) { + $variables['description']['attributes']->addClass('form-item__description'); + } - if ($variables['disabled']) { - $variables['label']['#attributes']['class'][] = 'is-disabled'; - } + if ($variables['disabled']) { + $variables['label']['#attributes']['class'][] = 'is-disabled'; + } } /** * Implements hook_preprocess_HOOK(). */ -function olivesnews_preprocess_form_element_label(&$variables) { - $variables['attributes']['class'][] = 'form-item__label'; +function olivesnews_preprocess_form_element_label(&$variables) +{ + $variables['attributes']['class'][] = 'form-item__label'; } /** * Implements hook_preprocess_HOOK(). */ -function olivesnews_preprocess_input(&$variables) { - if ( - !empty($variables['element']['#title_display']) && - $variables['element']['#title_display'] === 'attribute' && - !empty((string) $variables['element']['#title']) - ) { - $variables['attributes']['title'] = (string) $variables['element']['#title']; - } - - $type_api = $variables['element']['#type']; - $type_html = $variables['attributes']['type']; - $text_types_html = [ - 'text', - 'email', - 'tel', - 'number', - 'search', - 'password', - 'date', - 'time', - 'file', - 'color', - 'datetime-local', - 'url', - 'month', - 'week', - ]; - - if (in_array($type_html, $text_types_html, TRUE)) { - $variables['attributes']['class'][] = 'form-element'; - $variables['attributes']['class'][] = Html::getClass('form-element--type-' . $type_html); - $variables['attributes']['class'][] = Html::getClass('form-element--api-' . $type_api); +function olivesnews_preprocess_input(&$variables) +{ + if ( + !empty($variables['element']['#title_display']) + && $variables['element']['#title_display'] === 'attribute' + && !empty((string) $variables['element']['#title']) + ) { + $variables['attributes']['title'] = (string) $variables['element']['#title']; + } - // This logic is functioning as expected, but there is nothing in the theme that renders the result. - // As a result it can't currently be covered by a functional test. - if (!empty($variables['element']['#autocomplete_route_name'])) { - $variables['autocomplete_message'] = t('Loading…'); + $type_api = $variables['element']['#type']; + $type_html = $variables['attributes']['type']; + $text_types_html = [ + 'text', + 'email', + 'tel', + 'number', + 'search', + 'password', + 'date', + 'time', + 'file', + 'color', + 'datetime-local', + 'url', + 'month', + 'week', + ]; + + if (in_array($type_html, $text_types_html, true)) { + $variables['attributes']['class'][] = 'form-element'; + $variables['attributes']['class'][] = Html::getClass('form-element--type-' . $type_html); + $variables['attributes']['class'][] = Html::getClass('form-element--api-' . $type_api); + + // This logic is functioning as expected, but there is nothing in the theme that renders the result. + // As a result it can't currently be covered by a functional test. + if (!empty($variables['element']['#autocomplete_route_name'])) { + $variables['autocomplete_message'] = t('Loading…'); + } } - } - if (in_array($type_html, ['checkbox', 'radio'], TRUE)) { - $variables['attributes']['class'][] = 'form-boolean'; - $variables['attributes']['class'][] = Html::getClass('form-boolean--type-' . $type_html); - } + if (in_array($type_html, ['checkbox', 'radio'], true)) { + $variables['attributes']['class'][] = 'form-boolean'; + $variables['attributes']['class'][] = Html::getClass('form-boolean--type-' . $type_html); + } } /** * Implements hook_preprocess_HOOK(). */ -function olivesnews_preprocess_textarea(&$variables) { - $variables['attributes']['class'][] = 'form-element'; - $variables['attributes']['class'][] = 'form-element--type-textarea'; - $variables['attributes']['class'][] = 'form-element--api-textarea'; +function olivesnews_preprocess_textarea(&$variables) +{ + $variables['attributes']['class'][] = 'form-element'; + $variables['attributes']['class'][] = 'form-element--type-textarea'; + $variables['attributes']['class'][] = 'form-element--api-textarea'; } /** * Implements hook_preprocess_HOOK(). */ -function olivesnews_preprocess_select(&$variables) { - $variables['attributes']['class'][] = 'form-element'; - $variables['attributes']['class'][] = $variables['element']['#multiple'] ? - 'form-element--type-select-multiple' : - 'form-element--type-select'; +function olivesnews_preprocess_select(&$variables) +{ + $variables['attributes']['class'][] = 'form-element'; + $variables['attributes']['class'][] = $variables['element']['#multiple'] + ? 'form-element--type-select-multiple' + : 'form-element--type-select'; } /** * Implements hook_preprocess_HOOK(). */ -function olivesnews_preprocess_checkboxes(&$variables) { - $variables['attributes']['class'][] = 'form-boolean-group'; +function olivesnews_preprocess_checkboxes(&$variables) +{ + $variables['attributes']['class'][] = 'form-boolean-group'; } /** * Implements hook_preprocess_HOOK(). */ -function olivesnews_preprocess_radios(&$variables) { - $variables['attributes']['class'][] = 'form-boolean-group'; +function olivesnews_preprocess_radios(&$variables) +{ + $variables['attributes']['class'][] = 'form-boolean-group'; } /** * Implements hook_preprocess_HOOK(). */ -function olivesnews_preprocess_field(&$variables) { - $rich_field_types = ['text_with_summary', 'text', 'text_long']; +function olivesnews_preprocess_field(&$variables) +{ + $rich_field_types = ['text_with_summary', 'text', 'text_long']; - if (in_array($variables['field_type'], $rich_field_types, TRUE)) { - $variables['attributes']['class'][] = 'text-content'; - } + if (in_array($variables['field_type'], $rich_field_types, true)) { + $variables['attributes']['class'][] = 'text-content'; + } - if ($variables['field_type'] == 'image' && $variables['element']['#view_mode'] == 'full' && !$variables["element"]["#is_multiple"] && $variables['field_name'] !== 'user_picture') { - $variables['attributes']['class'][] = 'wide-image'; - } + if ($variables['field_type'] == 'image' && $variables['element']['#view_mode'] == 'full' && !$variables["element"]["#is_multiple"] && $variables['field_name'] !== 'user_picture') { + $variables['attributes']['class'][] = 'wide-image'; + } } /** * Implements hook_preprocess_HOOK(). */ -function olivesnews_preprocess_field_multiple_value_form(&$variables) { - // Make disabled available for the template. - $variables['disabled'] = !empty($variables['element']['#disabled']); - - if (!empty($variables['multiple'])) { - // Add an additional CSS class for the field label table cell. - // This repeats the logic of template_preprocess_field_multiple_value_form() - // without using '#prefix' and '#suffix' for the wrapper element. - // - // If the field is multiple, we don't have to check the existence of the - // table header cell. - // - // @see template_preprocess_field_multiple_value_form(). - $header_attributes = ['class' => ['form-item__label', 'form-item__label--multiple-value-form']]; - if (!empty($variables['element']['#required'])) { - $header_attributes['class'][] = 'js-form-required'; - $header_attributes['class'][] = 'form-required'; - } - // Using array_key_first() for addressing the first header cell would be - // more elegant here, but we can rely on the related theme.inc preprocess. - // @todo change this after https://www.drupal.org/node/3099026 has landed. - $variables['table']['#header'][0]['data'] = [ - '#type' => 'html_tag', - '#tag' => 'h4', - '#value' => $variables['element']['#title'], - '#attributes' => $header_attributes, - ]; - - if ($variables['disabled']) { - $variables['table']['#attributes']['class'][] = 'tabledrag-disabled'; - $variables['table']['#attributes']['class'][] = 'js-tabledrag-disabled'; - - // We will add the 'is-disabled' CSS class to the disabled table header - // cells. - $header_attributes['class'][] = 'is-disabled'; - foreach ($variables['table']['#header'] as &$cell) { - if (is_array($cell) && isset($cell['data'])) { - $cell = $cell + ['class' => []]; - $cell['class'][] = 'is-disabled'; +function olivesnews_preprocess_field_multiple_value_form(&$variables) +{ + // Make disabled available for the template. + $variables['disabled'] = !empty($variables['element']['#disabled']); + + if (!empty($variables['multiple'])) { + // Add an additional CSS class for the field label table cell. + // This repeats the logic of template_preprocess_field_multiple_value_form() + // without using '#prefix' and '#suffix' for the wrapper element. + // + // If the field is multiple, we don't have to check the existence of the + // table header cell. + // + // @see template_preprocess_field_multiple_value_form(). + $header_attributes = ['class' => ['form-item__label', 'form-item__label--multiple-value-form']]; + if (!empty($variables['element']['#required'])) { + $header_attributes['class'][] = 'js-form-required'; + $header_attributes['class'][] = 'form-required'; } - else { - // We have to modify the structure of this header cell. - $cell = [ - 'data' => $cell, - 'class' => ['is-disabled'], - ]; + // Using array_key_first() for addressing the first header cell would be + // more elegant here, but we can rely on the related theme.inc preprocess. + // @todo change this after https://www.drupal.org/node/3099026 has landed. + $variables['table']['#header'][0]['data'] = [ + '#type' => 'html_tag', + '#tag' => 'h4', + '#value' => $variables['element']['#title'], + '#attributes' => $header_attributes, + ]; + + if ($variables['disabled']) { + $variables['table']['#attributes']['class'][] = 'tabledrag-disabled'; + $variables['table']['#attributes']['class'][] = 'js-tabledrag-disabled'; + + // We will add the 'is-disabled' CSS class to the disabled table header + // cells. + $header_attributes['class'][] = 'is-disabled'; + foreach ($variables['table']['#header'] as &$cell) { + if (is_array($cell) && isset($cell['data'])) { + $cell = $cell + ['class' => []]; + $cell['class'][] = 'is-disabled'; + } else { + // We have to modify the structure of this header cell. + $cell = [ + 'data' => $cell, + 'class' => ['is-disabled'], + ]; + } + } } - } } - } } /** * Implements hook_preprocess_HOOK() for menu-local-task templates. */ -function olivesnews_preprocess_menu_local_task(&$variables) { - $variables['link']['#options']['attributes']['class'][] = 'tabs__link'; - $variables['link']['#options']['attributes']['class'][] = 'js-tabs-link'; +function olivesnews_preprocess_menu_local_task(&$variables) +{ + $variables['link']['#options']['attributes']['class'][] = 'tabs__link'; + $variables['link']['#options']['attributes']['class'][] = 'js-tabs-link'; - // Ensure is-active class is set when the tab is active. The generic active - // link handler applies stricter comparison rules than what is necessary for - // tabs. - if (isset($variables['is_active']) && $variables['is_active'] === TRUE) { - $variables['link']['#options']['attributes']['class'][] = 'is-active'; - } + // Ensure is-active class is set when the tab is active. The generic active + // link handler applies stricter comparison rules than what is necessary for + // tabs. + if (isset($variables['is_active']) && $variables['is_active'] === true) { + $variables['link']['#options']['attributes']['class'][] = 'is-active'; + } - if (isset($variables['element']['#level'])) { - $variables['level'] = $variables['element']['#level']; - } + if (isset($variables['element']['#level'])) { + $variables['level'] = $variables['element']['#level']; + } } /** * Implements template_preprocess_HOOK() for fieldset. */ -function olivesnews_preprocess_fieldset(&$variables) { - $element = $variables['element']; - $composite_types = ['checkboxes', 'radios']; +function olivesnews_preprocess_fieldset(&$variables) +{ + $element = $variables['element']; + $composite_types = ['checkboxes', 'radios']; - if (!empty($element['#type']) && in_array($element['#type'], $composite_types) && !empty($variables['element']['#children_errors'])) { - $variables['legend_span']['attributes']->addClass('has-error'); - } + if (!empty($element['#type']) && in_array($element['#type'], $composite_types) && !empty($variables['element']['#children_errors'])) { + $variables['legend_span']['attributes']->addClass('has-error'); + } - if (!empty($element['#disabled'])) { - $variables['legend_span']['attributes']->addClass('is-disabled'); + if (!empty($element['#disabled'])) { + $variables['legend_span']['attributes']->addClass('is-disabled'); - if (!empty($variables['description']) && !empty($variables['description']['attributes'])) { - $variables['description']['attributes']->addClass('is-disabled'); + if (!empty($variables['description']) && !empty($variables['description']['attributes'])) { + $variables['description']['attributes']->addClass('is-disabled'); + } } - } - // Remove 'container-inline' class from the main attributes and add a flag - // instead. - // @todo remove this after https://www.drupal.org/node/3059593 has been - // resolved. - if (!empty($variables['attributes']['class'])) { - $container_inline_key = array_search('container-inline', $variables['attributes']['class']); + // Remove 'container-inline' class from the main attributes and add a flag + // instead. + // @todo remove this after https://www.drupal.org/node/3059593 has been + // resolved. + if (!empty($variables['attributes']['class'])) { + $container_inline_key = array_search('container-inline', $variables['attributes']['class']); - if ($container_inline_key !== FALSE) { - unset($variables['attributes']['class'][$container_inline_key]); - $variables['inline_items'] = TRUE; + if ($container_inline_key !== false) { + unset($variables['attributes']['class'][$container_inline_key]); + $variables['inline_items'] = true; + } } - } } /** * Implements hook_theme_suggestions_HOOK_alter(). */ -function olivesnews_theme_suggestions_user_alter(&$suggestions, $variables) { - $suggestions[] = 'user__' . $variables['elements']['#view_mode']; +function olivesnews_theme_suggestions_user_alter(&$suggestions, $variables) +{ + $suggestions[] = 'user__' . $variables['elements']['#view_mode']; } /** * Implements hook_preprocess_HOOK(). */ -function olivesnews_preprocess_field__node__created(&$variables) { - foreach (Element::children($variables['items']) as $item) { - unset($variables['items'][$item]['content']['#prefix']); - } +function olivesnews_preprocess_field__node__created(&$variables) +{ + foreach (Element::children($variables['items']) as $item) { + unset($variables['items'][$item]['content']['#prefix']); + } } /** * Implements hook_preprocess_HOOK() for setting classes. */ -function olivesnews_preprocess_filter_caption(&$variables) { - $variables['classes'] = isset($variables['classes']) && !empty($variables['classes']) ? $variables['classes'] . ' caption' : 'caption'; +function olivesnews_preprocess_filter_caption(&$variables) +{ + $variables['classes'] = isset($variables['classes']) && !empty($variables['classes']) ? $variables['classes'] . ' caption' : 'caption'; } /** * Implements hook_form_FORM_ID_alter(). */ -function olivesnews_form_node_preview_form_select_alter(&$form, FormStateInterface $form_state, $form_id) { - $form['backlink']['#options']['attributes']['class'][] = 'button'; - $form['backlink']['#options']['attributes']['class'][] = 'button--small'; - $form['backlink']['#options']['attributes']['class'][] = 'button--icon-back'; - $form['backlink']['#options']['attributes']['class'][] = 'button--primary'; - $form['view_mode']['#attributes']['class'][] = 'form-element--small'; +function olivesnews_form_node_preview_form_select_alter(&$form, FormStateInterface $form_state, $form_id) +{ + $form['backlink']['#options']['attributes']['class'][] = 'button'; + $form['backlink']['#options']['attributes']['class'][] = 'button--small'; + $form['backlink']['#options']['attributes']['class'][] = 'button--icon-back'; + $form['backlink']['#options']['attributes']['class'][] = 'button--primary'; + $form['view_mode']['#attributes']['class'][] = 'form-element--small'; } /** * Implements hook_preprocess_HOOK() for comment.html.twig. */ -function olivesnews_preprocess_comment(&$variables) { - // Getting the node creation time stamp from the comment object. - $date = $variables['comment']->getCreatedTime(); - // Formatting "created" as "X days ago". - $variables['created'] = t('@time ago', ['@time' => \Drupal::service('date.formatter')->formatInterval(\Drupal::time()->getRequestTime() - $date)]); +function olivesnews_preprocess_comment(&$variables) +{ + // Getting the node creation time stamp from the comment object. + $date = $variables['comment']->getCreatedTime(); + // Formatting "created" as "X days ago". + $variables['created'] = t('@time ago', ['@time' => \Drupal::service('date.formatter')->formatInterval(\Drupal::time()->getRequestTime() - $date)]); } /** * Implements hook_preprocess_HOOK() for field--comment.html.twig. */ -function olivesnews_preprocess_field__comment(&$variables) { - // Add a comment_count. - $variables['comment_count'] = count(array_filter($variables['comments'], 'is_numeric', ARRAY_FILTER_USE_KEY)); +function olivesnews_preprocess_field__comment(&$variables) +{ + // Add a comment_count. + $variables['comment_count'] = count(array_filter($variables['comments'], 'is_numeric', ARRAY_FILTER_USE_KEY)); + + // Add user.compact to field-comment if profile's avatar of current user + // exist. + $user = \Drupal::currentUser(); + if ($user->isAuthenticated() && $user instanceof UserInterface) { + if ($user->hasField('user_picture') && !$user->get('user_picture')->isEmpty()) { + $variables['user_picture'] = \Drupal::entityTypeManager() + ->getViewBuilder('user') + ->view($user, 'compact'); + } - // Add user.compact to field-comment if profile's avatar of current user - // exist. - $user = \Drupal::currentUser(); - if ($user->isAuthenticated() && $user instanceof UserInterface) { - if ($user->hasField('user_picture') && !$user->get('user_picture')->isEmpty()) { - $variables['user_picture'] = \Drupal::entityTypeManager() - ->getViewBuilder('user') - ->view($user, 'compact'); + $variables['#cache']['contexts'][] = 'user'; } - - $variables['#cache']['contexts'][] = 'user'; - } } /** * Implements hook_element_info_alter(). */ -function olivesnews_element_info_alter(&$info) { - if (array_key_exists('text_format', $info)) { - $info['text_format']['#pre_render'][] = [OlivesnewsPreRender::class, 'textFormat']; - } +function olivesnews_element_info_alter(&$info) +{ + if (array_key_exists('text_format', $info)) { + $info['text_format']['#pre_render'][] = [OlivesnewsPreRender::class, 'textFormat']; + } - if (isset($info['status_messages'])) { - $info['status_messages']['#pre_render'][] = [OlivesnewsPreRender::class, 'messagePlaceholder']; - } + if (isset($info['status_messages'])) { + $info['status_messages']['#pre_render'][] = [OlivesnewsPreRender::class, 'messagePlaceholder']; + } } /** @@ -579,58 +606,63 @@ function olivesnews_element_info_alter(&$info) { * * @todo Remove when https://www.drupal.org/node/3016343 is fixed. */ -function olivesnews_preprocess_text_format_wrapper(&$variables) { - $description_attributes = []; - if (!empty($variables['attributes']['id'])) { - $description_attributes['id'] = $variables['attributes']['aria-describedby'] = $variables['attributes']['id']; - unset($variables['attributes']['id']); - } - $variables['description_attributes'] = new Attribute($description_attributes); +function olivesnews_preprocess_text_format_wrapper(&$variables) +{ + $description_attributes = []; + if (!empty($variables['attributes']['id'])) { + $description_attributes['id'] = $variables['attributes']['aria-describedby'] = $variables['attributes']['id']; + unset($variables['attributes']['id']); + } + $variables['description_attributes'] = new Attribute($description_attributes); } /** * Implements hook_preprocess_search_result(). */ -function olivesnews_preprocess_search_result(&$variables) { - // Apply custom date formatter to "date" field. - if (!empty($variables['result']['date'])) { - $variables['info_date'] = \Drupal::service('date.formatter')->format($variables['result']['node']->getCreatedTime(), 'olivesnews_medium'); - } +function olivesnews_preprocess_search_result(&$variables) +{ + // Apply custom date formatter to "date" field. + if (!empty($variables['result']['date'])) { + $variables['info_date'] = \Drupal::service('date.formatter')->format($variables['result']['node']->getCreatedTime(), 'olivesnews_medium'); + } } /** * Implements hook_preprocess_links__comment(). */ -function olivesnews_preprocess_links__comment(&$variables) { - foreach ($variables['links'] as &$link) { - $link['link']['#options']['attributes']['class'][] = 'comment__links-link'; - } +function olivesnews_preprocess_links__comment(&$variables) +{ + foreach ($variables['links'] as &$link) { + $link['link']['#options']['attributes']['class'][] = 'comment__links-link'; + } } /** * Implements hook_preprocess_table(). */ -function olivesnews_preprocess_table(&$variables) { - // Mark the whole table and the first cells if rows are draggable. - if (!empty($variables['rows'])) { - $draggable_row_found = FALSE; - foreach ($variables['rows'] as &$row) { - /** @var \Drupal\Core\Template\Attribute $row['attributes'] */ - if (!empty($row['attributes']) && $row['attributes']->hasClass('draggable')) { - if (!$draggable_row_found) { - $variables['attributes']['class'][] = 'draggable-table'; - $draggable_row_found = TRUE; +function olivesnews_preprocess_table(&$variables) +{ + // Mark the whole table and the first cells if rows are draggable. + if (!empty($variables['rows'])) { + $draggable_row_found = false; + foreach ($variables['rows'] as &$row) { + /** @var \Drupal\Core\Template\Attribute $row['attributes'] */ + if (!empty($row['attributes']) && $row['attributes']->hasClass('draggable')) { + if (!$draggable_row_found) { + $variables['attributes']['class'][] = 'draggable-table'; + $draggable_row_found = true; + } + } } - } } - } } /** * Implements hook_form_views_exposed_form_alter(). */ -function olivesnews_form_views_exposed_form_alter(&$form) { - $form['#attributes']['class'][] = 'form--inline'; +function olivesnews_form_views_exposed_form_alter(&$form) +{ + $form['#attributes']['class'][] = 'form--inline'; } /** @@ -652,94 +684,67 @@ function olivesnews_form_views_exposed_form_alter(&$form) { * * @internal */ -function _olivesnews_hex_to_hsl(string $hex_string) { - // Convert hexcode pairs to rgb values (0-255). - $hex_val = trim($hex_string, '#'); - $r0 = hexdec($hex_val[0] . $hex_val[1]); - $g0 = hexdec($hex_val[2] . $hex_val[3]); - $b0 = hexdec($hex_val[4] . $hex_val[5]); - - // Convert rgb's 0-255 to decimal values. - $r = fdiv($r0, 255); - $g = fdiv($g0, 255); - $b = fdiv($b0, 255); - - // Calculate Hue. - $c_min = min($r, $g, $b); - $c_max = max($r, $g, $b); - $delta = $c_max - $c_min; - - if ($delta == 0) { - $h = 0; - } - else { - switch ($c_max) { - case $r: - $h = fmod((($g - $b) / $delta), 6); - break; - - case $g: - $h = (($b - $r) / $delta) + 2; - break; - - case $b: - $h = (($r - $g) / $delta) + 4; - break; - - default: +function _olivesnews_hex_to_hsl(string $hex_string) +{ + // Convert hexcode pairs to rgb values (0-255). + $hex_val = trim($hex_string, '#'); + $r0 = hexdec($hex_val[0] . $hex_val[1]); + $g0 = hexdec($hex_val[2] . $hex_val[3]); + $b0 = hexdec($hex_val[4] . $hex_val[5]); + + // Convert rgb's 0-255 to decimal values. + $r = fdiv($r0, 255); + $g = fdiv($g0, 255); + $b = fdiv($b0, 255); + + // Calculate Hue. + $c_min = min($r, $g, $b); + $c_max = max($r, $g, $b); + $delta = $c_max - $c_min; + + if ($delta == 0) { $h = 0; - break; + } else { + switch ($c_max) { + case $r: + $h = fmod((($g - $b) / $delta), 6); + break; + + case $g: + $h = (($b - $r) / $delta) + 2; + break; + + case $b: + $h = (($r - $g) / $delta) + 4; + break; + + default: + $h = 0; + break; + } } - } - $h = round($h * 60); + $h = round($h * 60); - // Shift hue range from [-60 - 300] to [0 - 360]. - if ($h < 0) { - $h += 360; - } + // Shift hue range from [-60 - 300] to [0 - 360]. + if ($h < 0) { + $h += 360; + } - // Calculate Lightness. - $l = ($c_max + $c_min) / 2; + // Calculate Lightness. + $l = ($c_max + $c_min) / 2; - // Calculate Saturation. - $s = $delta == 0 ? 0 : $delta / (1 - abs((2 * $l) - 1)); + // Calculate Saturation. + $s = $delta == 0 ? 0 : $delta / (1 - abs((2 * $l) - 1)); - // Convert Saturation and Lightness to percentages. - $s = round($s * 100); - $l = round($l * 100); + // Convert Saturation and Lightness to percentages. + $s = round($s * 100); + $l = round($l * 100); - return [$h, $s, $l]; + return [$h, $s, $l]; } -/* -function olivesnews_preprocess_mirador(&$variables) { - $block = \Drupal::service('plugin.manager.block')->createInstance($viewer . 'mirador_block', [ - 'iiif_manifest_url' => "/node/$manifest_nid/manifest-single", - 'thumbnail_navigation_position' => 'hidden', - 'window_config' => [ - 'allowClose' => FALSE, - 'allowMaximize' => FALSE, - 'allowTopMenuButton' => FALSE, - 'allowWindowSideBar' => FALSE, - 'hideWindowTitle' => TRUE, - 'panels' => [ - 'info' => FALSE, - 'attribution' => FALSE, - ' canvas' => FALSE, - 'annotations' => FALSE, - 'search' => FALSE, - ], - ], - 'workspace_config' => [ - 'allowNewWindows' => FALSE, - 'isWorkspaceAddVisible' => FALSE, - 'workspaceControlPanel' => [ - 'enable' => FALSE, - ], - - ], - ]); +function olivesnews_preprocess_page(&$variables) +{ + $variables['#attached']['library'][] = 'olivesnews/nouislider-year-format'; } - */ -