Skip to content

Commit

Permalink
Merge pull request #258 from localgovdrupal/feature/257-replace-domai…
Browse files Browse the repository at this point in the history
…n-group-resolver

Refactor domain group resolver to use new group context.
  • Loading branch information
finnlewis committed May 2, 2024
2 parents 308b9f8 + 941b892 commit db58419
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 31 deletions.
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

0 comments on commit db58419

Please sign in to comment.