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

UHF-8909 Preprocess function refactor #1028

Merged
merged 23 commits into from
Aug 30, 2024
Merged

UHF-8909 Preprocess function refactor #1028

merged 23 commits into from
Aug 30, 2024

Conversation

khalima
Copy link
Contributor

@khalima khalima commented Jul 23, 2024

UHF-8909

What was done

  • Removed theme_prefix variable from hdbt_preprocess() function as it's not used anywhere, and moved the active_theme variable to hdbt_preprocess_page() as its used only in page template.
  • Removed theme_path variable from hdbt_preprocess() function as it's not necessary to be added on every single preprocess. The theme_path is added via hdbt_preprocess_html(), hdbt_preprocess_page() and hdbt_preprocess_paragraph__calculator(), and the variable is used in html, page and calculator paragraph twig files.
  • As the helfi_instance_name variable is only needed in JS, let's move it away from hdbt_preprocess() function and set it once in hdbt_preprocess_html().
  • Removed use_global_navigation variable from hdbt_preprocess() and copied it to hdbt_preprocess_html(), hdbt_preprocess_page(), hdbt_preprocess_block() and hdbt_preprocess_menu().
  • Moved search_dropdown and global_menu variables away from hdbt_preprocess() function and set them in hdbt_preprocess_html() instead.
  • Removed the theme_color variable from hdbt_preprocess() and copied it to hdbt_preprocess_html() as its only used in html.html.twig.
  • Removed the image_placeholder variable from hdbt_preprocess() and moved it to the image-placeholder.twig template.
  • Removed the koro variable from hdbt_preprocess() and moved it to the koro.twig template. Also removed the koro mentions from paragraph--content-cards.html.twig, page.html.twig and hero.twig.
  • Removed the theme_color variable from hdbt_preprocess() and moved it to the html.html.twig template. Also moved the theme color override to hdbt_preprocess_html().
  • Optimized the checks for helfi_navigation existence.
  • Converted the current_language, navigation_enabled and alternative_language variables to be set only once in hdbt_preprocess() to optimize the call stack. Also further optimized the helfi_navigation module existence check.
  • Switched to the language object in twig files; {{ language.id}}.
  • Removed the language object intializations as it is done within helfi_api_base module.
  • Use the default language object instead of retrieving the language via service.

How to install

  • Make sure your instance is up and running on latest dev branch.
    • git pull origin dev
    • make fresh
  • Update the HDBT Admin theme
    • composer require drupal/hdbt:dev-UHF-8909 drupal/hdbt_admin:dev-UHF-8909 drupal/helfi_api_base:dev-UHF-8909
  • Run make drush-cr

How to test

  • Go to your site and go through the following elements. These elements can be found in various places. They should work exactly like before, so make sure to compare the site to a testing/production version when you're checking the elements for changes.
    • Check koro
    • Check theme_color
    • Check image_placeholder
      • This is the default icon which is still in use in various list elements.
    • Check language.id.
      • This is the old current_langcode variable, which has been changed to use language object. See the documentation.
      • The easiest way to check this is to go through the changed twig files and that the elements/functionalities works as before
    • Check language.name
      • This is the old current_language variable, which has been changed to use language object.
    • Check language.direction
      • This is the old current_language_dir variable, which has been changed to use language object.
    • Check alternative_language
      • This variable or its functionality hasn't changed, but it's initialisation has been moved to helfi_api_base. Try this functionality out in Etusivu -instance. Choose an "alternative" language from content list and check that the fallback attributes fallback_lang, fallback_dir still works the same way as before.
    • Check use_global_navigation
      • The use_global_navigation variable initialisation was moved to more precise preprocesses (hdbt_preprocess_html, hdbt_preprocess_page, hdbt_preprocess_input__submit, hdbt_preprocess_block). Check that the functionality works as before.
    • Check drupalSettings.hdbt.global_menu, drupalSettings.hdbt.search_dropdown and drupalSettings.helfi_instance_name javascript variables.
      • These variables initialisation has been moved to hdbt_preprocess_html as the attached javascript variables only need to be set once during page load. You can test the variables by copying the variable path to terminal window in your browser
    • Check theme_color override.
      • Change the colour scheme for a single page by editing the colour palette and check that the change will influence the hero and banner backgrounds
    • Check active_theme
      • The active_theme variable is used in page.html.twig to indicate the prefixes for block templates. It has been moved to hdbt_preprocess_page. Check that the blocks (like: site branding or language switcher) still works as before.
    • Check theme_prefix
    • Check theme_path
      • The theme_path variable initialisation was moved to hdbt_preprocess_html and copied to hdbt_preprocess_page and hdbt_preprocess_paragraph__calculator . Check that the theme paths work for html.html.twig favicons, page--404.html.twig illustrations and that the Calculator paragraphs works as before as the theme path is rather strangely used for loading different calculator JS files.
    • Double check the changes to twig templates and check that the code follows our standards

Continuous documentation

  • This feature has been documented/the documentation has been updated (in Helfi API Base)
  • This change doesn't require updates to the documentation

Translations

  • Translations have been added to .po -files and included in this PR

Other PRs

khalima added 6 commits July 23, 2024 13:59
…on as it's not used anywhere, and moved the active_theme variable to hdbt_preprocess_page() as its used only in page template. Also removed theme_path variable from hdbt_preprocess() function as it's not necessary to be added on every single preprocess. The theme_path is added via hdbt_preprocess_html(), hdbt_preprocess_page() and hdbt_preprocess_paragraph__calculator(), and the variable is used in html, page and calculator paragraph twig files.
…et's move it away from hdbt_preprocess() function and set it once in hdbt_preprocess_html().
…() and copied it to hdbt_preprocess_html(), hdbt_preprocess_page(), hdbt_preprocess_block() and hdbt_preprocess_menu(). Also moved search_dropdown and global_menu variables away from hdbt_preprocess() function and set them in hdbt_preprocess_html() instead.
… copied it to hdbt_preprocess_html() as its only used in html.html.twig.
…() and moved it to the image-placeholder.twig template.
…it to the koro.twig template. Also removed the koro mentions from paragraph--content-cards.html.twig, page.html.twig and hero.twig.
Copy link

github-actions bot commented Jul 23, 2024

⚠️ Visual regression found! Please check if this change is wanted or accidental. You can check the output here: https://city-of-helsinki.github.io/drupal-hdbt/pull/1028/html_report/

… moved it to the html.html.twig template. Also moved the theme color override to hdbt_preprocess_html().
@khalima khalima changed the title UHF-8909 Preprocess() cleaning UHF-8909 Preprocess function refactor Jul 23, 2024
tuutti
tuutti previously requested changes Jul 24, 2024
khalima added 7 commits July 24, 2024 10:53
…rnative_language variables to be set only once in hdbt_preprocess() to optimize the call stack. Also further optimized the helfi_navigation module existence check.
…rnative_language variables to be set only once in hdbt_preprocess() to optimize the call stack. Also further optimized the helfi_navigation module existence check.
khalima added 4 commits July 25, 2024 14:53
…ink and node--announcement--default templates/preprocesses.
…ocess was moved to helfi_paragraphs_hearings module.
…nk.twig and field--tpr-unit--provided-languages.html.twig, and added the language object to tpr-unit.html.twig. The preprocesses have been added to helfi_tpr_config module.
…age functions to be self-dependent and not depend of variables array.
@khalima
Copy link
Contributor Author

khalima commented Jul 25, 2024

Attach this to the release notes:
The hdbt_preprocess() has been removed to streamline the page rendering and thus all current_langcode variables have been assigned to more precise preprocessing functions, f.e. hdbt_preprocess_node(). Check that your subtheme has the current_langcode variables set, or switch to use the hdbt theme's hdbt_add_current_language() function. This function will set the language object to render array variables and the langcode can be called in a template with {{ language.id }}

Copy link
Contributor

@teroelonen teroelonen left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

These changes causes currently InvalidArgumentException: The URI '' is invalid. You must use a valid URI scheme. in Drupal\Core\Url::fromUri() (line 293 of core/lib/Drupal/Core/Url.php). on Finnish language front pages of KYMP and Strategia at least.

Copy link
Contributor

@teroelonen teroelonen left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Really great work with refactoring the hdbt.theme file - everything works as it should 🦖

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants