Skip to content

Commit

Permalink
Merge pull request #964 from City-of-Helsinki/UHF-9978
Browse files Browse the repository at this point in the history
UHF-9978: Never process external menu blocks
  • Loading branch information
khalima authored Apr 18, 2024
2 parents 0d32687 + 8fab524 commit 847b61f
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 34 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ jobs:
runs-on: ubuntu-latest
strategy:
matrix:
php-versions: ['8.1']
php-versions: ['8.3']
container:
image: ghcr.io/city-of-helsinki/drupal-php-docker:${{ matrix.php-versions }}-alpine
steps:
Expand Down
18 changes: 9 additions & 9 deletions .github/workflows/visual.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
on:
pull_request:
types: [opened, reopened, synchronize]
branches-ignore:
- 'renovate/**'
push:
branches:
- main
Expand All @@ -13,7 +15,7 @@ jobs:
steps:
- uses: actions/checkout@v4
with:
fetch-depth: 1
fetch-depth: 0

- name: Set variables
run: echo "DRUPAL_ROOT=$HOME/drupal" >> $GITHUB_ENV
Expand Down Expand Up @@ -43,7 +45,7 @@ jobs:
COMPOSER_MIRROR_PATH_REPOS: 1
run: |
composer config repositories.5 path $GITHUB_WORKSPACE
composer require drupal/$THEME_NAME -W
composer require drupal/redis drupal/$THEME_NAME -W
# We use COMPOSER_MIRROR_PATH_REPOS=1 to mirror local repository
# instead of symlinking it to make sure the code is available inside
# the app container.
Expand Down Expand Up @@ -77,6 +79,7 @@ jobs:
if: steps.drupal-cache.outputs.cache-hit != 'true'
run: |
docker compose exec app bash -c "drush si minimal -y"
docker compose exec app bash -c "drush en redis -y"
docker compose exec app bash -c "drush en helfi_test_content -y"
docker compose exec app bash -c "drush sql-dump --result-file=/app/public/sites/default/files/latest.sql"
Expand Down Expand Up @@ -134,22 +137,19 @@ jobs:
run: docker compose logs app > /tmp/container.log

- name: Deploy to PR preview
uses: peaceiris/actions-gh-pages@v3
uses: peaceiris/actions-gh-pages@v4
if: github.ref != 'refs/heads/main'
with:
github_token: ${{ secrets.GITHUB_TOKEN }}
publish_dir: ${{ env.THEME_FOLDER }}/backstop_data/full/
destination_dir: pull/${{github.event.number}}

- name: Update comment
uses: hasura/[email protected]
if: github.ref != 'refs/heads/main'
uses: thollander/actions-comment-pull-request@v2
with:
github-token: ${{ secrets.GITHUB_TOKEN }}
repository: ${{ github.repository }}
number: ${{ github.event.number }}
id: deploy-preview
recreate: true
comment_tag: status
pr_number: ${{ github.event.number }}
message: "${{join(steps.run-tests.outputs.*, ' ')}}"

- name: Upload container logs
Expand Down
41 changes: 17 additions & 24 deletions hdbt.theme
Original file line number Diff line number Diff line change
Expand Up @@ -509,6 +509,15 @@ function hdbt_preprocess_input__submit(&$variables): void {
* Implements hook_preprocess_HOOK().
*/
function hdbt_preprocess_menu(&$variables): void {
// Menu, mobile menu, fallback menu and sidebar menu tree depth.
// Counting from "instance", "main level", "level 3", "level 4", "level 5"...
$menu_depth = 5;
$variables['menu_depth'] = $menu_depth;
$variables['#attached']['drupalSettings']['menu_depth'] = $menu_depth;

if (isset($variables['attributes']['block_id']) && str_starts_with('external_menu_', $variables['attributes']['block_id'])) {
return;
}
$apply_lang_attribute = array_key_exists('menu_type', $variables);

if (
Expand All @@ -521,12 +530,6 @@ function hdbt_preprocess_menu(&$variables): void {
foreach ($variables['items'] as &$item) {
_hdbt_menu_item_apply_attributes($item, $apply_lang_attribute);
}

// Menu, mobile menu, fallback menu and sidebar menu tree depth.
// Counting from "instance", "main level", "level 3", "level 4", "level 5"...
$menu_depth = 5;
$variables['menu_depth'] = $menu_depth;
$variables['#attached']['drupalSettings']['menu_depth'] = $menu_depth;
}

/**
Expand Down Expand Up @@ -569,25 +572,15 @@ function _hdbt_menu_item_apply_attributes(array &$item, bool $apply_lang_attribu
array_key_exists('original_link', $item) &&
$item['original_link'] instanceof MenuLinkContent
) {
// MenuLinkContent::getEntity() has protected visibility and cannot be used
// to directly fetch the entity.
$metadata = $item['original_link']->getMetaData();

if (!empty($metadata['entity_id'])) {
$entity_type_manager = Drupal::entityTypeManager();
$menu_link_content = $entity_type_manager
->getStorage('menu_link_content')
->load($metadata['entity_id']);
$menu_link_content = $item['original_link']->getEntity();

// Add the possible lang attribute to menu item attributes.
if (
!empty($menu_link_content) &&
$menu_link_content->hasField('lang_attribute') &&
!$menu_link_content->get('lang_attribute')->isEmpty()
) {
$lang_attribute = $menu_link_content->get('lang_attribute')->value;
$item['attributes']->setAttribute('lang', $lang_attribute);
}
// Add the possible lang attribute to menu item attributes.
if (
$menu_link_content->hasField('lang_attribute') &&
!$menu_link_content->get('lang_attribute')->isEmpty()
) {
$lang_attribute = $menu_link_content->get('lang_attribute')->value;
$item['attributes']->setAttribute('lang', $lang_attribute);
}
}
}
Expand Down

0 comments on commit 847b61f

Please sign in to comment.