Skip to content
This repository has been archived by the owner on Aug 18, 2024. It is now read-only.

Revert the fix from #709 #731

Merged
merged 4 commits into from
Jan 12, 2022
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
10 changes: 1 addition & 9 deletions src/OgRouteGroupResolverBase.php
Original file line number Diff line number Diff line change
Expand Up @@ -99,15 +99,7 @@ protected function getContentEntity() {
$paths = $this->getContentEntityPaths();
if (array_key_exists($path, $paths)) {
// Return the entity.
$entity = $this->routeMatch->getParameter($paths[$path]);
if ($this->routeMatch->getRouteName() === 'entity.node.revision' && is_string($entity)) {
// On the node revision route, the $entity will be a string ID of the
// node. Treat this case by loading the correct revision of the node
// instead from the node revision parameter.
$revision_id = $this->routeMatch->getParameter('node_revision');
$entity = $this->entityTypeManager->getStorage('node')->loadRevision($revision_id);
}
return $entity;
return $this->routeMatch->getParameter($paths[$path]);
}
return NULL;
}
Expand Down
19 changes: 3 additions & 16 deletions tests/modules/og_test/og_test.module
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ use Drupal\og\Og;
/**
* Implements hook_module_implements_alter().
*/
function og_test_module_implements_alter(&$implementations, $hook) : void {
function og_test_module_implements_alter(&$implementations, $hook): void {
if ($hook == 'entity_insert') {
// Move our implementation of hook_entity_insert() to the top of the list so
// that it will run before og_entity_insert().
Expand All @@ -30,7 +30,7 @@ function og_test_module_implements_alter(&$implementations, $hook) : void {
/**
* Implements hook_entity_insert().
*/
function og_test_entity_insert(EntityInterface $entity) : void {
function og_test_entity_insert(EntityInterface $entity): void {
// In order to test if it is possible to use an hook_entity_insert()
// implementation to override the user membership that is automatically
// created in og_entity_insert() we will create our own membership here, if
Expand All @@ -48,7 +48,7 @@ function og_test_entity_insert(EntityInterface $entity) : void {
/**
* Implements hook_og_user_access_entity_operation_alter().
*/
function og_test_og_user_access_entity_operation_alter(AccessResultInterface &$access_result, CacheableMetadata $cacheable_metadata, $context) : void {
function og_test_og_user_access_entity_operation_alter(AccessResultInterface &$access_result, CacheableMetadata $cacheable_metadata, $context): void {
if (\Drupal::state()->get('og_test_group_content_entity_operation_access_alter', FALSE)) {
// Moderators should have access to edit and delete all comments in all
// groups.
Expand All @@ -64,16 +64,3 @@ function og_test_og_user_access_entity_operation_alter(AccessResultInterface &$a
}
}
}

/**
* Implements hook_preprocess_node().
*/
function og_test_preprocess_node(&$variables) : void {
// Add the og_membership_state cache context to all node output so we can
// test the context correctly resolves the groups.
// @see Drupal\Tests\og\Functional\OgMembershipStateCacheContextTest
$content = &$variables['content'];
CacheableMetadata::createFromRenderArray($content)
->addCacheContexts(['og_membership_state'])
->applyTo($content);
}
112 changes: 0 additions & 112 deletions tests/src/Functional/OgMembershipStateCacheContextTest.php

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -89,9 +89,6 @@ public function testResolve($path = NULL, $route_object_id = NULL, array $expect
// If a route object is returned the plugin will need to inspect it to
// check if it is a group.
$this->mightCheckIfRouteObjectIsGroup($route_object_id);
// If an entity path is being accessed, the plugin will need to inspect
// the route name, to check if a node revision route is being accessed.
$this->mightRetrieveRouteName($route_object_id);
}

// Add expectations for the groups that are added and removed by the plugin.
Expand Down Expand Up @@ -243,26 +240,4 @@ protected function mightCheckIfRouteObjectIsGroup($route_object_id) {
->willReturn(!empty($properties[$route_object_id]['group']));
}

/**
* Adds an expectation that the plugin will retrieve the route name.
*
* If the current path is an entity path, the plugin should retrieve the
* route name from the route to check if the route is a node revision route.
* If we are not, then it should not attempt to retrieve it.
*
* @param string|null $route_object_id
* The ID of the entity that is present on the current route, or NULL if we
* are not on a content entity path. The ID may be any of the ones created
* in the test setup, e.g. 'group', 'group_content', 'non_group'.
*/
protected function mightRetrieveRouteName(?string $route_object_id) {
// The route name should only be retrieved if we are on a content entity
// path.
if ($route_object_id) {
$this->routeMatch
->getRouteName()
->willReturn("entity.{$this->getTestEntityProperties()[$route_object_id]['type']}.canonical");
}
}

}