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

Commit 213a9c1

Browse files
authored
Merge pull request #754 from claudiu-cristea/d10
D10 compatibility
2 parents a808daa + 4303a9b commit 213a9c1

File tree

83 files changed

+258
-147
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

83 files changed

+258
-147
lines changed

.travis.yml

+7-3
Original file line numberDiff line numberDiff line change
@@ -5,23 +5,27 @@ language: php
55
php:
66
- '7.4'
77
- '8.0'
8-
- nightly
8+
- '8.1'
99

1010
env:
1111
global:
1212
- COMPOSER_MEMORY_LIMIT=2G
1313
matrix:
14-
- TEST_SUITE=9.3.x
1514
- TEST_SUITE=9.4.x
15+
- TEST_SUITE=10.0.x
1616
- TEST_SUITE=PHP_CodeSniffer
1717

1818
# Only run the coding standards check once.
1919
matrix:
2020
exclude:
2121
- php: 7.4
2222
env: TEST_SUITE=PHP_CodeSniffer
23+
- php: 7.4
24+
env: TEST_SUITE=10.0.x
2325
- php: 8.0
2426
env: TEST_SUITE=PHP_CodeSniffer
27+
- php: 8.0
28+
env: TEST_SUITE=10.0.x
2529

2630
mysql:
2731
database: og
@@ -65,7 +69,7 @@ before_script:
6569

6670
# Install Composer dependencies for core. Skip this for the coding standards test.
6771
- test ${TEST_SUITE} == "PHP_CodeSniffer" || composer install --working-dir=$DRUPAL_DIR
68-
72+
6973
# Start a web server on port 8888 in the background.
7074
- test ${TEST_SUITE} == "PHP_CodeSniffer" || nohup php -S localhost:8888 --docroot $DRUPAL_DIR > /dev/null 2>&1 &
7175

composer.json

+1-5
Original file line numberDiff line numberDiff line change
@@ -24,13 +24,9 @@
2424
"homepage": "https://www.drupal.org/u/pfrenssen"
2525
}
2626
],
27-
"require": {
28-
"php": "^7.4 || ^8",
29-
"drupal/core": "^9.3"
30-
},
3127
"require-dev": {
3228
"drupal/coder": "^8.3.16",
33-
"phpunit/phpunit": "^7 || ^8"
29+
"phpunit/phpunit": "^7 || ^8 || ^9"
3430
},
3531
"minimum-stability": "RC",
3632
"config": {

og.info.yml

+1-2
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,8 @@ name: Organic Groups
22
description: API to allow associating content with groups.
33
package: Organic Groups
44

5-
core_version_requirement: ^9
5+
core_version_requirement: ^9 || ^10
66
type: module
7-
php: 7.1
87

98
dependencies:
109
- drupal:options

og_ui/og_ui.info.yml

+2-2
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,9 @@ description: User interface for Organic Groups.
33
package: Organic Groups
44

55
type: module
6-
core_version_requirement: ^9
6+
core_version_requirement: ^9 || ^10
77

88
dependencies:
9-
- og
9+
- og:og
1010

1111
configure: og_ui.admin_index

og_ui/src/BundleFormAlter.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -95,7 +95,7 @@ protected function prepare(array &$form, FormStateInterface $form_state) {
9595
// Example: article.
9696
$this->bundle = $this->entity->id();
9797
// Example: Article.
98-
$this->bundleLabel = Unicode::lcfirst($this->entity->label());
98+
$this->bundleLabel = Unicode::lcfirst((string) $this->entity->label());
9999
$this->definition = $this->entity->getEntityType();
100100
// Example: node.
101101
$this->entityTypeId = $this->definition->getBundleOf();

og_ui/tests/src/Functional/BundleFormAlterTest.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ class BundleFormAlterTest extends BrowserTestBase {
2121
/**
2222
* {@inheritdoc}
2323
*/
24-
public static $modules = ['block_content', 'entity_test', 'node', 'og_ui'];
24+
protected static $modules = ['block_content', 'entity_test', 'node', 'og_ui'];
2525

2626
/**
2727
* {@inheritdoc}

src/Controller/OgAdminRoutesController.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,7 @@ public function overview(RouteMatchInterface $route_match) {
7676
$content = [];
7777

7878
$event = new OgAdminRoutesEvent();
79-
$event = $this->eventDispatcher->dispatch(OgAdminRoutesEventInterface::EVENT_NAME, $event);
79+
$event = $this->eventDispatcher->dispatch($event, OgAdminRoutesEventInterface::EVENT_NAME);
8080

8181
foreach ($event->getRoutes($entity_type_id) as $name => $info) {
8282
$route_name = "entity.$entity_type_id.og_admin_routes.$name";

src/Entity/OgMembership.php

+2-2
Original file line numberDiff line numberDiff line change
@@ -544,8 +544,8 @@ public function preSave(EntityStorageInterface $storage) {
544544
}
545545

546546
// Check for an existing membership.
547-
$query = \Drupal::entityQuery('og_membership');
548-
$query
547+
$query = \Drupal::entityQuery('og_membership')
548+
->accessCheck()
549549
->condition('uid', $uid)
550550
->condition('entity_id', $entity_id)
551551
->condition('entity_type', $this->get('entity_type')->value);

src/Entity/OgRole.php

+9
Original file line numberDiff line numberDiff line change
@@ -323,7 +323,16 @@ protected function ogAccess() {
323323
* {@inheritdoc}
324324
*/
325325
public function calculateDependencies() {
326+
// The parent method is checking for the existence of each role-assigned
327+
// permission. But in OG this isn't mandatory. Backup the permissions before
328+
// calling the parent method and avoid performing the check.
329+
// @see https://www.drupal.org/node/3193348
330+
// @todo Consider decoupling 'og_role' from 'role' entity config and
331+
// implementing the missing methods in 'og_role'.
332+
$permissions = $this->permissions;
333+
$this->permissions = [];
326334
parent::calculateDependencies();
335+
$this->permissions = $permissions;
327336

328337
// Create a dependency on the group bundle.
329338
$bundle_config_dependency = \Drupal::entityTypeManager()->getDefinition($this->getGroupType())->getBundleConfigDependency($this->getGroupBundle());

src/Event/AccessEventBase.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
use Drupal\Core\Cache\RefinableCacheableDependencyTrait;
1111
use Drupal\Core\Entity\ContentEntityInterface;
1212
use Drupal\Core\Session\AccountInterface;
13-
use Symfony\Component\EventDispatcher\Event;
13+
use Symfony\Contracts\EventDispatcher\Event;
1414

1515
/**
1616
* Base class for OG access events.

src/Event/DefaultRoleEvent.php

+6-5
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
namespace Drupal\og\Event;
66

77
use Drupal\og\Entity\OgRole;
8-
use Symfony\Component\EventDispatcher\Event;
8+
use Symfony\Contracts\EventDispatcher\Event;
99

1010
/**
1111
* Event that is fired when default roles are compiled.
@@ -97,14 +97,15 @@ public function hasRole($name) {
9797
/**
9898
* {@inheritdoc}
9999
*/
100+
#[\ReturnTypeWillChange]
100101
public function offsetGet($key) {
101102
return $this->getRole($key);
102103
}
103104

104105
/**
105106
* {@inheritdoc}
106107
*/
107-
public function offsetSet($key, $role) {
108+
public function offsetSet($key, $role): void {
108109
$this->validate($role);
109110
if ($role->getName() !== $key) {
110111
throw new \InvalidArgumentException('The key and the "name" property of the role should be identical.');
@@ -115,21 +116,21 @@ public function offsetSet($key, $role) {
115116
/**
116117
* {@inheritdoc}
117118
*/
118-
public function offsetUnset($key) {
119+
public function offsetUnset($key): void {
119120
$this->deleteRole($key);
120121
}
121122

122123
/**
123124
* {@inheritdoc}
124125
*/
125-
public function offsetExists($key) {
126+
public function offsetExists($key): bool {
126127
return $this->hasRole($key);
127128
}
128129

129130
/**
130131
* {@inheritdoc}
131132
*/
132-
public function getIterator() {
133+
public function getIterator(): \Traversable {
133134
return new \ArrayIterator($this->roles);
134135
}
135136

src/Event/GroupCreationEvent.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44

55
namespace Drupal\og\Event;
66

7-
use Symfony\Component\EventDispatcher\Event;
7+
use Symfony\Contracts\EventDispatcher\Event;
88

99
/**
1010
* The group creation event.

src/Event/OgAdminRoutesEvent.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66

77
use Drupal\Component\Utility\NestedArray;
88
use Drupal\og\OgAccess;
9-
use Symfony\Component\EventDispatcher\Event;
9+
use Symfony\Contracts\EventDispatcher\Event;
1010

1111
/**
1212
* Event that is fired when OG admin routes are being compiled.

src/Event/PermissionEvent.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66

77
use Drupal\og\GroupContentOperationPermission;
88
use Drupal\og\PermissionInterface;
9-
use Symfony\Component\EventDispatcher\Event;
9+
use Symfony\Contracts\EventDispatcher\Event;
1010

1111
/**
1212
* Event that is fired when OG permissions are compiled.

src/GroupTypeManager.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -284,7 +284,7 @@ public function addGroup($entity_type_id, $bundle_id) {
284284

285285
// Trigger an event upon the new group creation.
286286
$event = new GroupCreationEvent($entity_type_id, $bundle_id);
287-
$this->eventDispatcher->dispatch(GroupCreationEventInterface::EVENT_NAME, $event);
287+
$this->eventDispatcher->dispatch($event, GroupCreationEventInterface::EVENT_NAME);
288288

289289
$this->ogRoleManager->createPerBundleRoles($entity_type_id, $bundle_id);
290290
$this->refreshGroupMap();

src/MembershipManager.php

+4
Original file line numberDiff line numberDiff line change
@@ -113,6 +113,7 @@ public function getMemberships($user_id, array $states = [OgMembershipInterface:
113113
$query = $this->entityTypeManager
114114
->getStorage('og_membership')
115115
->getQuery()
116+
->accessCheck()
116117
->condition('uid', $user_id)
117118
->condition('state', $states, 'IN');
118119

@@ -185,6 +186,7 @@ public function getGroupMembershipCount(EntityInterface $group, array $states =
185186
$query = $this->entityTypeManager
186187
->getStorage('og_membership')
187188
->getQuery()
189+
->accessCheck()
188190
->condition('entity_id', $group->id());
189191

190192
if ($states) {
@@ -231,6 +233,7 @@ public function getGroupMembershipIdsByRoleNames(EntityInterface $group, array $
231233
$query = $this->entityTypeManager
232234
->getStorage('og_membership')
233235
->getQuery()
236+
->accessCheck()
234237
->condition('entity_type', $entity_type_id)
235238
->condition('entity_id', $group->id())
236239
->condition('state', $states, 'IN');
@@ -418,6 +421,7 @@ public function getGroupContentIds(EntityInterface $entity, array $entity_types
418421
$results = $this->entityTypeManager
419422
->getStorage($group_content_entity_type)
420423
->getQuery()
424+
->accessCheck()
421425
->condition($field->getName() . '.target_id', $entity->id())
422426
->execute();
423427

src/OgAccess.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -323,7 +323,7 @@ public function userAccessGroupContentEntityOperation(string $operation, EntityI
323323
$event->addCacheContexts(['user']);
324324
}
325325

326-
$this->dispatcher->dispatch(GroupContentEntityOperationAccessEvent::EVENT_NAME, $event);
326+
$this->dispatcher->dispatch($event, GroupContentEntityOperationAccessEvent::EVENT_NAME);
327327

328328
return $event->getAccessResult();
329329
}

src/OgDeleteOrphansBase.php

+1
Original file line numberDiff line numberDiff line change
@@ -120,6 +120,7 @@ protected function query(EntityInterface $entity) {
120120
// Register orphaned user memberships.
121121
$membership_ids = $this->entityTypeManager->getStorage('og_membership')
122122
->getQuery()
123+
->accessCheck()
123124
->condition('entity_type', $entity->getEntityTypeId())
124125
->condition('entity_id', $entity->id())
125126
->execute();

src/OgRoleManager.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,7 @@ public function getDefaultRoles() {
8888
$roles = $this->getRequiredDefaultRoles();
8989

9090
$event = new DefaultRoleEvent();
91-
$this->eventDispatcher->dispatch(DefaultRoleEventInterface::EVENT_NAME, $event);
91+
$this->eventDispatcher->dispatch($event, DefaultRoleEventInterface::EVENT_NAME);
9292

9393
// Use the array union operator '+=' to ensure the default roles cannot be
9494
// altered by event subscribers.

src/PermissionManager.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ public function __construct(EventDispatcherInterface $event_dispatcher) {
3535
*/
3636
public function getDefaultPermissions($group_entity_type_id, $group_bundle_id, array $group_content_bundle_ids, $role_name = NULL) {
3737
$event = new PermissionEvent($group_entity_type_id, $group_bundle_id, $group_content_bundle_ids);
38-
$this->eventDispatcher->dispatch(PermissionEventInterface::EVENT_NAME, $event);
38+
$this->eventDispatcher->dispatch($event, PermissionEventInterface::EVENT_NAME);
3939
return $event->getPermissions();
4040
}
4141

src/Plugin/Validation/Constraint/UniqueOgMembershipConstraintValidator.php

+1
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,7 @@ public function validate($value, Constraint $constraint) {
7676
$query = $this->entityTypeManager
7777
->getStorage('og_membership')
7878
->getQuery()
79+
->accessCheck()
7980
->condition('entity_type', $entity->getGroupEntityType())
8081
->condition('entity_id', $entity->getGroupId())
8182
->condition('uid', $new_member_uid);

src/Routing/RouteSubscriber.php

+2-2
Original file line numberDiff line numberDiff line change
@@ -120,7 +120,7 @@ protected function alterRoutes(RouteCollection $collection) {
120120
*/
121121
protected function createRoutesFromEventSubscribers($og_admin_path, $entity_type_id, RouteCollection $collection) {
122122
$event = new OgAdminRoutesEvent();
123-
$this->eventDispatcher->dispatch(OgAdminRoutesEventInterface::EVENT_NAME, $event);
123+
$this->eventDispatcher->dispatch($event, OgAdminRoutesEventInterface::EVENT_NAME);
124124

125125
foreach ($event->getRoutes($entity_type_id) as $name => $route_info) {
126126
// Add the parent route.
@@ -165,7 +165,7 @@ protected function addRoute(RouteCollection $collection, $route_name, $path, arr
165165
* We have such a case with the "members" OG admin route, that requires Views
166166
* module to be enabled.
167167
*/
168-
public static function getSubscribedEvents() {
168+
public static function getSubscribedEvents(): array {
169169
$events[RoutingEvents::ALTER] = ['onAlterRoutes', 100];
170170
return $events;
171171
}

tests/modules/og_standard_reference_test_views/og_standard_reference_test_views.info.yml

+1-1
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,6 @@ name: 'OG standard reference test views'
22
type: module
33
description: 'Provides default views for views OG standard reference tests.'
44
package: Testing
5-
core_version_requirement: ^9
5+
core_version_requirement: ^9 || ^10
66
dependencies:
77
- drupal:views

tests/modules/og_test/og_test.info.yml

+1-1
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,6 @@ name: 'Organic Groups test'
22
type: module
33
description: 'Support module for Organic Groups testing.'
44
package: Testing
5-
core_version_requirement: ^9
5+
core_version_requirement: ^9 || ^10
66
dependencies:
77
- drupal:options

tests/src/Functional/GroupSubscribeFormatterTest.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ class GroupSubscribeFormatterTest extends BrowserTestBase {
2121
/**
2222
* {@inheritdoc}
2323
*/
24-
public static $modules = ['node', 'og', 'options'];
24+
protected static $modules = ['node', 'og', 'options'];
2525

2626
/**
2727
* {@inheritdoc}

tests/src/Functional/GroupSubscribeTest.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ class GroupSubscribeTest extends BrowserTestBase {
2727
/**
2828
* {@inheritdoc}
2929
*/
30-
public static $modules = ['node', 'og'];
30+
protected static $modules = ['node', 'og'];
3131

3232
/**
3333
* {@inheritdoc}

0 commit comments

Comments
 (0)