Skip to content

Commit

Permalink
Merge pull request #455 from localgovdrupal/fix/4.x/tests-and-coding-…
Browse files Browse the repository at this point in the history
…standards

Fix/4.x/tests and coding standards
  • Loading branch information
finnlewis committed Apr 12, 2024
2 parents 849807f + 1e2167d commit 557dde6
Show file tree
Hide file tree
Showing 46 changed files with 152 additions and 119 deletions.
14 changes: 10 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,9 +1,15 @@
# LocalGov Drupal Microsites: Group

Provides a microsites group type that provides customisations for theme, which
work out of the box with `localgov_microsites_base` theme.

Adds integration with `domain_group` for a group on a seperate domain.
Provides a microsites group type that supports customisations for theme, which
works with `localgov_microsites_base` theme.

Includes `localgov_microsites_permissions` that extends `group_permissions` to
allow microsite group administrators to set their individual permissions.

## Maintainers

This project is currently maintained by:

- Ekes: https://www.drupal.org/u/ekes
- Finn Lewis: https://www.drupal.org/u/finn-lewis
- Stephen Cox: https://www.drupal.org/u/stephen-cox
1 change: 0 additions & 1 deletion config/optional/views.view.group_invitations.yml
Original file line number Diff line number Diff line change
Expand Up @@ -675,7 +675,6 @@ display:
default_argument_type: fixed
default_argument_options:
argument: ''
default_argument_skip_url: false
summary_options:
base_path: ''
count: true
Expand Down
1 change: 0 additions & 1 deletion config/optional/views.view.lgms_embed_views.yml
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,6 @@ display:
title: ''
default_argument_type: node
default_argument_options: { }
default_argument_skip_url: false
summary_options:
base_path: ''
count: true
Expand Down
1 change: 0 additions & 1 deletion config/optional/views.view.microsites_placeholder.yml
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,6 @@ display:
title: ''
default_argument_type: group_id_from_url
default_argument_options: { }
default_argument_skip_url: false
summary_options:
base_path: ''
count: true
Expand Down
1 change: 0 additions & 1 deletion config/optional/views.view.my_invitations.yml
Original file line number Diff line number Diff line change
Expand Up @@ -725,7 +725,6 @@ display:
default_argument_type: fixed
default_argument_options:
argument: ''
default_argument_skip_url: false
summary_options:
base_path: ''
count: true
Expand Down
1 change: 0 additions & 1 deletion config/overrides/views.view.group_members.yml
Original file line number Diff line number Diff line change
Expand Up @@ -569,7 +569,6 @@ display:
default_argument_type: fixed
default_argument_options:
argument: ''
default_argument_skip_url: false
summary_options:
base_path: ''
count: true
Expand Down
2 changes: 0 additions & 2 deletions config/overrides/views.view.group_nodes.yml
Original file line number Diff line number Diff line change
Expand Up @@ -623,7 +623,6 @@ display:
default_argument_type: fixed
default_argument_options:
argument: ''
default_argument_skip_url: false
summary_options:
base_path: ''
count: true
Expand Down Expand Up @@ -1629,7 +1628,6 @@ display:
default_argument_type: fixed
default_argument_options:
argument: ''
default_argument_skip_url: false
summary_options:
base_path: ''
count: true
Expand Down
1 change: 0 additions & 1 deletion config/overrides/views.view.my_invitations.yml
Original file line number Diff line number Diff line change
Expand Up @@ -580,7 +580,6 @@ display:
default_argument_type: fixed
default_argument_options:
argument: ''
default_argument_skip_url: false
summary_options:
base_path: ''
count: true
Expand Down
2 changes: 1 addition & 1 deletion localgov_microsites_group.info.yml
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ dependencies:
- groupmedia:groupmedia
- groupmedia_paragraphs:groupmedia_paragraphs
- group_sites:group_sites
- group_context_domain
- group_context_domain:group_context_domain
- group_content_menu:group_content_menu
- layout_paragraphs:layout_paragraphs_permissions
- media_library:media_library
Expand Down
2 changes: 1 addition & 1 deletion localgov_microsites_group.install
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ function localgov_microsites_group_update_9004() {
function localgov_microsites_group_update_9005() {
$config_manager = \Drupal::service('config.manager');
assert($config_manager instanceof ConfigManagerInterface);
#$config_manager->loadConfigEntityByName('')
// $config_manager->loadConfigEntityByName('')
$dependencies = $config_manager->findConfigEntityDependencies('module', ['domain_group']);
foreach ($dependencies as $name => $dependency) {
var_dump($name);
Expand Down
28 changes: 25 additions & 3 deletions localgov_microsites_group.module
Original file line number Diff line number Diff line change
Expand Up @@ -141,7 +141,7 @@ function localgov_microsites_group_entity_extra_field_info() {
function localgov_microsites_group_menu_link_content_presave(MenuLinkContentInterface $entity) {

// Find active group.
$group_id = \Drupal::service('domain_group_resolver')->getActiveDomainGroupId();
$group_id = localgov_microsites_group_get_group_id();
if (is_null($group_id)) {
$group = \Drupal::request()->attributes->get('group');
if ($group) {
Expand Down Expand Up @@ -288,7 +288,7 @@ function localgov_microsites_group_user_login_form_submit($form, FormStateInterf
$form_state->setRedirect('system.admin');
}
// Login to a domain group.
$group_id = \Drupal::service('domain_group_resolver')->getActiveDomainGroupId();
$group_id = localgov_microsites_group_get_group_id();
if ($group_id) {
$form_state->setRedirect('entity.group.canonical', ['group' => $group_id]);
}
Expand All @@ -298,7 +298,7 @@ function localgov_microsites_group_user_login_form_submit($form, FormStateInterf
* Additional submit handler to associate media with group when in domain group.
*/
function localgov_microsites_group_media_library_add_form_submit($form, FormStateInterface $form_state) {
if (($group_id = \Drupal::service('domain_group_resolver')->getActiveDomainGroupId()) &&
if (($group_id = localgov_microsites_group_get_group_id()) &&
($added_media = $form_state->get('media'))
) {
$groups[] = Group::load($group_id);
Expand Down Expand Up @@ -482,3 +482,25 @@ function localgov_microsites_group_localgov_microsites_roles_default() {
],
];
}

/**
* Get the current group id from the domain context.
*/
function localgov_microsites_group_get_group_id() {

$context_id = \Drupal::service('config.factory')->get('group_sites.settings')->get('context_provider');
if ($context_id === NULL) {
return NULL;
}

$contexts = \Drupal::service('context.repository')->getRuntimeContexts([$context_id]);

$context = count($contexts) ? reset($contexts) : NULL;

if ($group = $context?->getContextValue()) {
if (!$group instanceof GroupInterface) {
throw new \InvalidArgumentException('Context value is not a Group entity.');
}
return $group->id();
}
}
1 change: 0 additions & 1 deletion localgov_microsites_group.routing.yml
Original file line number Diff line number Diff line change
Expand Up @@ -25,4 +25,3 @@ domain_group.domain_group_settings_form:
_admin_route: TRUE
requirements:
_custom_access: '\Drupal\localgov_microsites_group\Form\DomainGroupSettingsForm::access'

Original file line number Diff line number Diff line change
Expand Up @@ -396,7 +396,6 @@ display:
default_argument_type: fixed
default_argument_options:
argument: ''
default_argument_skip_url: false
summary_options:
base_path: ''
count: true
Expand Down Expand Up @@ -433,7 +432,6 @@ display:
default_argument_type: fixed
default_argument_options:
argument: ''
default_argument_skip_url: false
summary_options:
base_path: ''
count: true
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -357,7 +357,6 @@ display:
title: ''
default_argument_type: node
default_argument_options: { }
default_argument_skip_url: false
summary_options:
base_path: ''
count: true
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
namespace Drupal\localgov_microsites_events\EventSubscriber;

use Drupal\Core\Entity\EntityRepositoryInterface;
use Drupal\Core\Entity\EntityTypeManagerInterface;
use Drupal\domain\DomainNegotiatorInterface;
use Drupal\group_context_domain\Context\GroupFromDomainContextTrait;
use Drupal\localgov_microsites_group\ContentTypeHelperInterface;
Expand All @@ -29,9 +28,11 @@ class EventsListingCheckEventSubscriber implements EventSubscriberInterface {
/**
* Returns an EventsListingCheckEventSubscriber instance.
*
* @param \Drupal\Core\Entity\EntityTypeManagerInterface $entity_type_manager
* The entity type manager.
* @param \Drupal\localgov_microsites_group\GroupPermissionsHelperInterface $content_type_helper
* @param \Drupal\Core\Entity\EntityRepositoryInterface $entity_repository
* The entity repository interface.
* @param \Drupal\domain\DomainNegotiatorInterface $domain_negotiator
* The domain negotiator interface.
* @param \Drupal\localgov_microsites_group\ContentTypeHelperInterface $content_type_helper
* The group content type helper.
*/
public function __construct(EntityRepositoryInterface $entity_repository, DomainNegotiatorInterface $domain_negotiator, ContentTypeHelperInterface $content_type_helper) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,6 @@ protected function setUp(): void {

$this->createMicrositeGroups([], 2);
$this->createMicrositeGroupsDomains($this->groups);
$domain_storage = \Drupal::entityTypeManager()->getStorage('domain');
$this->domain1 = $this->getDomainFromGroup($this->groups[0]);
$this->domain2 = $this->getDomainFromGroup($this->groups[1]);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -342,7 +342,6 @@ display:
default_argument_type: fixed
default_argument_options:
argument: ''
default_argument_skip_url: false
summary_options:
base_path: ''
count: true
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -432,7 +432,6 @@ display:
default_argument_type: fixed
default_argument_options:
argument: ''
default_argument_skip_url: false
summary_options:
base_path: ''
count: true
Expand Down Expand Up @@ -473,7 +472,6 @@ display:
default_argument_type: fixed
default_argument_options:
argument: ''
default_argument_skip_url: false
summary_options:
base_path: ''
count: true
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ function localgov_microsites_group_term_ui_form_alter(&$form, FormStateInterface
if (isset($form['relations']['parent']['#options'])) {

// Find group.
$group_id = \Drupal::service('domain_group_resolver')->getActiveDomainGroupId();
$group_id = localgov_microsites_group_get_group_id();
if (!is_null($group_id)) {
$group = \Drupal::entityTypeManager()->getStorage('group')->load($group_id);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ class GroupTermUiController extends ControllerBase {
*
* @var \Drupal\localgov_microsites_group\ContentTypeHelperInterface
*/
protected $contentTypeHelper;
protected $contentTypeHelper;

/**
* Constructs a new GroupNodeController.
Expand Down Expand Up @@ -121,8 +121,6 @@ public function addTermAccess(AccountInterface $account, GroupInterface $group,
/**
* Check access to create term in group.
*
* @see GroupRelationshipCreateEntityAccessCheck::access()
*
* @param \Drupal\Core\Session\AccountInterface $account
* Run access checks for this account.
* @param \Drupal\group\Entity\GroupInterface $group
Expand All @@ -132,6 +130,8 @@ public function addTermAccess(AccountInterface $account, GroupInterface $group,
*
* @return \Drupal\Core\Access\AccessResultInterface
* The access result.
*
* @see GroupRelationshipCreateEntityAccessCheck::access()
*/
protected function accessCreateGroupTerm(AccountInterface $account, GroupInterface $group, string $plugin_id) {
$access_handler = $this->pluginManager->getAccessControlHandler($plugin_id);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ class GroupTermEntityReferenceTest extends GroupKernelTestBase {
/**
* {@inheritdoc}
*/
public static $modules = [
protected static $modules = [
'localgov_microsites_group_term_ui',
'localgov_microsites_group_term_ui_test',
'domain',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ function localgov_microsites_group_webform_entity_insert($entity) {
if ($entity_type == 'webform_submission') {

// Find the active group.
$group_id = \Drupal::service('domain_group_resolver')->getActiveDomainGroupId();
$group_id = \Drupal::service('group_context_domain')->getActiveDomainGroupId();

// If we can't find it with the domain_group_resolver, try with the url.
// @todo check if this is actually necessary.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -157,7 +157,6 @@ display:
title: ''
default_argument_type: node
default_argument_options: { }
default_argument_skip_url: false
summary_options:
base_path: ''
count: true
Expand Down
10 changes: 6 additions & 4 deletions src/ContentTypeHelper.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,11 @@ class ContentTypeHelper implements ContentTypeHelperInterface {
/**
* Constructs a GroupPermissionsHelper instance.
*
* @param \Drupal\Core\Entity\EntityTypeManagerInterface $entity_type_manager
* @param \Drupal\Core\Entity\EntityTypeManagerInterface $entityTypeManager
* The entity type manager.
* @param \Drupal\Core\Extension\ModuleHandlerInterface $module_handler
* @param \Drupal\Core\Extension\ModuleHandlerInterface $moduleHandler
* The module handler.
* @param \Drupal\group\Plugin\Group\Relation\GroupRelationTypeManagerInterface $relationPluginManager
* The module handler.
*/
public function __construct(protected EntityTypeManagerInterface $entityTypeManager, protected ModuleHandlerInterface $moduleHandler, protected GroupRelationTypeManagerInterface $relationPluginManager) {
Expand All @@ -31,7 +33,7 @@ public function __construct(protected EntityTypeManagerInterface $entityTypeMana
public function modulesList(GroupInterface $group): array {
static $modules = [];

$this->moduleHandler->invokeAllWith('localgov_microsites_roles_default', function ($hook, $module) use (&$modules, $group) {
$this->moduleHandler->invokeAllWith('localgov_microsites_roles_default', function ($hook, $module) use (&$modules) {
$modules[$module] = self::ENABLED;
});
if ($group->hasField('lgms_modules_disabled')) {
Expand Down Expand Up @@ -96,7 +98,7 @@ public function enabledContentTypes(GroupInterface $group): array {
}
// All types controlled by modules that can be disabled.
if (empty($all_content_types)) {
$this->moduleHandler->invokeAllWith('localgov_microsites_roles_default', function ($hook, $module) use (&$all_content_types, $group) {
$this->moduleHandler->invokeAllWith('localgov_microsites_roles_default', function ($hook, $module) use (&$all_content_types) {
$permissions = $hook()['group'][RolesHelper::GROUP_ADMIN_ROLE] ?? [];
foreach ($permissions as $permission) {
$matches = [];
Expand Down
5 changes: 4 additions & 1 deletion src/ContextProvider/DomainGroupContext.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,10 @@
/**
* Sets the current group as a context on domains.
*
* @deprecated Use \Drupal\group_context_domain\Context\GroupFromDomainContext.
* @deprecated in localgov_microsites_group:4.0.0-alpha1 and is removed from
* localgov_microsites_group:5.0.0.
* Use \Drupal\group_context_domain\Context\GroupFromDomainContext.
* @see https://www.drupal.org/project/group_sites/issues/3402181
*/
class DomainGroupContext extends GroupFromDomainContext {

Expand Down
Loading

0 comments on commit 557dde6

Please sign in to comment.