Skip to content

Commit

Permalink
feat(LP-152): LGD Directories patch for facets order. Reorder facets …
Browse files Browse the repository at this point in the history
…on channel.
  • Loading branch information
Polynya committed Oct 4, 2024
1 parent 92f3bc8 commit 80e420c
Show file tree
Hide file tree
Showing 8 changed files with 99 additions and 39 deletions.
4 changes: 3 additions & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -124,6 +124,7 @@
"localgovdrupal/localgov": "^3",
"localgovdrupal/localgov_base": "^1.5",
"localgovdrupal/localgov_content_access_control": "^1.0",
"localgovdrupal/localgov_directories": "^3.2",
"localgovdrupal/localgov_eu_cookie_compliance": "^1.0",
"localgovdrupal/localgov_forms": "^1.0@beta",
"localgovdrupal/localgov_geo": "^2",
Expand Down Expand Up @@ -208,7 +209,8 @@
"Error when accessing a preview link if enabled_entity_types configuration is missing": "https://www.drupal.org/files/issues/2024-04-04/preview_link-3438117-enabled_entity_types.patch"
},
"localgovdrupal/localgov_directories": {
"Support facets form": "https://patch-diff.githubusercontent.com/raw/localgovdrupal/localgov_directories/pull/399.diff"
"Support facets form": "https://patch-diff.githubusercontent.com/raw/localgovdrupal/localgov_directories/pull/399.diff",
"Set order of facets on channel": "patches/localgov_directories_facets.patch"
},
"localgovdrupal/localgov_publications": {
"Declare permissions for LocalGov Publications": "patches/localgov_publications.patch"
Expand Down
2 changes: 1 addition & 1 deletion composer.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

25 changes: 25 additions & 0 deletions config/default/block.block.ecc_theme_gov_facets.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
uuid: e9914b02-a477-4220-8050-fdb944b13c28
langcode: en
status: true
dependencies:
config:
- facets.facet.localgov_directories_facets
module:
- block_classes
- facets
theme:
- ecc_theme_gov
id: ecc_theme_gov_facets
theme: ecc_theme_gov
region: sidebar_first
weight: 0
provider: null
plugin: 'facet_block:localgov_directories_facets'
settings:
id: 'facet_block:localgov_directories_facets'
label: Facets
label_display: visible
provider: facets
context_mapping: { }
block_id: ecc_theme_gov_facets
visibility: { }
Original file line number Diff line number Diff line change
Expand Up @@ -45,17 +45,31 @@ content:
settings: { }
third_party_settings: { }
localgov_directory_facets_enable:
type: options_buttons
type: entity_reference_autocomplete
weight: 13
region: content
settings: { }
settings:
match_operator: CONTAINS
match_limit: 10
size: 60
placeholder: ''
third_party_settings: { }
localgov_review_date:
type: review_date
weight: 1
region: content
settings: { }
third_party_settings: { }
localgov_service_contacts:
type: entity_reference_autocomplete
weight: 26
region: content
settings:
match_operator: CONTAINS
match_limit: 10
size: 60
placeholder: ''
third_party_settings: { }
localgov_services_parent:
type: entity_reference_autocomplete
weight: 9
Expand Down
12 changes: 0 additions & 12 deletions config/envs/ddev/devel.settings.yml

This file was deleted.

10 changes: 0 additions & 10 deletions config/envs/ddev/devel.toolbar.settings.yml

This file was deleted.

13 changes: 0 additions & 13 deletions config/envs/ddev/system.menu.devel.yml

This file was deleted.

54 changes: 54 additions & 0 deletions patches/localgov_directories_facets.patch
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
diff --git a/src/DirectoryExtraFieldDisplay.php b/src/DirectoryExtraFieldDisplay.php
index 3c36e36..ce1c066 100644
--- a/src/DirectoryExtraFieldDisplay.php
+++ b/src/DirectoryExtraFieldDisplay.php
@@ -342,11 +342,12 @@ class DirectoryExtraFieldDisplay implements ContainerInjectionInterface, Trusted
$facet_storage = $this->entityTypeManager
->getStorage(Directory::FACET_CONFIG_ENTITY_ID);
$group_items = [];
+ $all_group_items = [];
foreach ($facet_items as $key => $item) {
$facet_id = $item['value']['#attributes']['data-drupal-facet-item-value'] ?? $key;
if ($facet_entity = $facet_storage->load($facet_id)) {
assert($facet_entity instanceof LocalgovDirectoriesFacets);
- $group_items[$facet_entity->bundle()]['items'][$key] = $item;
+ $all_group_items[$facet_entity->bundle()]['items'][$key] = $item;
}
}

@@ -359,19 +360,31 @@ class DirectoryExtraFieldDisplay implements ContainerInjectionInterface, Trusted
) {
$active_facets = array_column($channel->localgov_directory_facets_enable->getValue(), 'target_id');
}
- if (!is_null($active_facets)) {
- $group_items = array_intersect_key($group_items, array_flip($active_facets));
+ $is_channel = !is_null($active_facets);
+
+ if ($is_channel) {
+ // Use only the groups set on the channel, keeping the order.
+ foreach ($active_facets as $active_facet) {
+ $group_items[$active_facet] = $all_group_items[$active_facet];
+ }
+ }
+ else {
+ // Use all groups if not on a channel.
+ $group_items = $all_group_items;
}

+ $weight = 0;
$type_storage = $this->entityTypeManager
->getStorage(Directory::FACET_TYPE_CONFIG_ENTITY_ID);
foreach ($group_items as $bundle => $items) {
$facet_type_entity = $type_storage->load($bundle);
assert($facet_type_entity instanceof LocalgovDirectoriesFacetsType);
$group_items[$bundle]['title'] = Html::escape($this->entityRepository->getTranslationFromContext($facet_type_entity)->label());
- $group_items[$bundle]['weight'] = $facet_type_entity->get('weight');
+ $group_items[$bundle]['weight'] = $is_channel ? $weight++ : $facet_type_entity->get('weight');
+ }
+ if (!$is_channel) {
+ uasort($group_items, static::compareFacetBundlesByWeight(...));
}
- uasort($group_items, static::compareFacetBundlesByWeight(...));

return $group_items;
}

0 comments on commit 80e420c

Please sign in to comment.