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

Refactor domain group resolver to use new group context. #258

Merged
merged 3 commits into from
May 2, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
64 changes: 28 additions & 36 deletions .github/workflows/localgov_microsites.yml
Original file line number Diff line number Diff line change
Expand Up @@ -21,15 +21,13 @@ jobs:
strategy:
fail-fast: false
matrix:
include:
- profile-version: '2.1.x'
project-version: '2.x'
drupal-version: '~9.4'
php-version: '8.1'
- profile-version: '3.x'
project-version: '3.x'
drupal-version: '~10.0'
php-version: '8.1'
profile-version:
- '4.x'
drupal-version:
- '~10.0'
php-version:
- '8.1'
- '8.2'

steps:

Expand Down Expand Up @@ -107,15 +105,13 @@ jobs:
strategy:
fail-fast: false
matrix:
include:
- profile-version: '2.1.x'
project-version: '2.x'
drupal-version: '~9.4'
php-version: '8.1'
- profile-version: '3.x'
project-version: '3.x'
drupal-version: '~10.0'
php-version: '8.1'
profile-version:
- '4.x'
drupal-version:
- '~10.0'
php-version:
- '8.1'
- '8.2'

steps:

Expand Down Expand Up @@ -145,15 +141,13 @@ jobs:
strategy:
fail-fast: false
matrix:
include:
- profile-version: '2.1.x'
project-version: '2.x'
drupal-version: '~9.4'
php-version: '8.1'
- profile-version: '3.x'
project-version: '3.x'
drupal-version: '~10.0'
php-version: '8.1'
profile-version:
- '4.x'
drupal-version:
- '~10.0'
php-version:
- '8.1'
- '8.2'

steps:

Expand Down Expand Up @@ -182,15 +176,13 @@ jobs:
strategy:
fail-fast: false
matrix:
include:
- profile-version: '2.1.x'
project-version: '2.x'
drupal-version: '~9.4'
php-version: '8.1'
- profile-version: '3.x'
project-version: '3.x'
drupal-version: '~10.0'
php-version: '8.1'
profile-version:
- '4.x'
drupal-version:
- '~10.0'
php-version:
- '8.1'
- '8.2'

steps:

Expand Down
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,6 @@
"require": {
"drupal/twig_tweak": "^3.2",
"localgovdrupal/localgov_base": "^1.0.0",
"localgovdrupal/localgov_microsites_group": "^2.0.0@beta || ^3.0.0@alpha || ^4.0.0@alpha "
"localgovdrupal/localgov_microsites_group": "^4.0.0-alpha3"
}
}
40 changes: 10 additions & 30 deletions localgov_microsites_base.theme
Original file line number Diff line number Diff line change
Expand Up @@ -13,18 +13,13 @@ use Drupal\views\ViewExecutable;
*/
function localgov_microsites_base_preprocess_html(&$variables) {

$parent_group_id = \Drupal::service('domain_group_resolver')->getActiveDomainGroupId();
if ($parent_group_id) {
$group = \Drupal::entityTypeManager()->getStorage('group')->load($parent_group_id);
}
if (empty($group)) {
$group = \Drupal::request()->attributes->get('group');
}
// Load the group by context. See localgov_microsites_group.module.
$group = localgov_microsites_group_get_by_context();

if ($group instanceof MicrositeGroupInterface) {
// Adds classes that can be used to let CSS target specific microsites.
$variables['attributes']['class'][] = 'lgd-ms';
$variables['attributes']['class'][] = 'lgd-ms--' . $parent_group_id;
$variables['attributes']['class'][] = 'lgd-ms--' . $group->id();

// Styleguide primary colour.
if (!is_null($group->get('lgms_primary_colour')[0])) {
Expand Down Expand Up @@ -444,16 +439,11 @@ function localgov_microsites_base_preprocess_node(&$variables) {
$variables['content_type'] = $variables['node']->getType();
$variables['teaser'] = $variables['view_mode'] == 'teaser';

$parent_group_id = \Drupal::service('domain_group_resolver')->getActiveDomainGroupId();
if ($parent_group_id) {
$group = \Drupal::entityTypeManager()->getStorage('group')->load($parent_group_id);
}
if (empty($group)) {
$group = \Drupal::request()->attributes->get('group');
}
// Load the group by context. See localgov_microsites_group.module.
$group = localgov_microsites_group_get_by_context();

if ($group instanceof MicrositeGroupInterface) {
$front_page = \Drupal::config('domain.config.group_' . $parent_group_id . '.system.site')->get('page.front');
$front_page = \Drupal::config('domain.config.group_' . $group->id() . '.system.site')->get('page.front');
$current_path = \Drupal::service('path.current')->getPath();
$current_path_alias = \Drupal::service('path_alias.manager')->getAliasByPath($current_path);

Expand Down Expand Up @@ -527,13 +517,8 @@ function localgov_microsites_base_views_pre_render(ViewExecutable $view) {

$view->element['#attached']['library'][] = 'localgov_microsites_base/view-events';

$parent_group_id = \Drupal::service('domain_group_resolver')->getActiveDomainGroupId();
if ($parent_group_id) {
$group = \Drupal::entityTypeManager()->getStorage('group')->load($parent_group_id);
}
else {
$group = \Drupal::request()->attributes->get('group');
}
// Load the group by context. See localgov_microsites_group.module.
$group = localgov_microsites_group_get_by_context();

if (!is_null($group) && !empty($group->get('lgms_teaser_image_style')->getValue())) {

Expand Down Expand Up @@ -576,13 +561,8 @@ function localgov_microsites_base_preprocess_page(&$variables) {
$variables['site_name'] = $config->get('name');
$variables['site_slogan'] = $config->get('slogan');

$parent_group_id = \Drupal::service('domain_group_resolver')->getActiveDomainGroupId();
if ($parent_group_id) {
$group = \Drupal::entityTypeManager()->getStorage('group')->load($parent_group_id);
}
if (empty($group)) {
$group = \Drupal::request()->attributes->get('group');
}
// Load the group by context. See localgov_microsites_group.module.
$group = localgov_microsites_group_get_by_context();

if ($group instanceof MicrositeGroupInterface) {

Expand Down
Loading