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

Commit

Permalink
Merge pull request #754 from claudiu-cristea/d10
Browse files Browse the repository at this point in the history
D10 compatibility
  • Loading branch information
MPParsley authored Nov 21, 2022
2 parents a808daa + 4303a9b commit 213a9c1
Show file tree
Hide file tree
Showing 83 changed files with 258 additions and 147 deletions.
10 changes: 7 additions & 3 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,23 +5,27 @@ language: php
php:
- '7.4'
- '8.0'
- nightly
- '8.1'

env:
global:
- COMPOSER_MEMORY_LIMIT=2G
matrix:
- TEST_SUITE=9.3.x
- TEST_SUITE=9.4.x
- TEST_SUITE=10.0.x
- TEST_SUITE=PHP_CodeSniffer

# Only run the coding standards check once.
matrix:
exclude:
- php: 7.4
env: TEST_SUITE=PHP_CodeSniffer
- php: 7.4
env: TEST_SUITE=10.0.x
- php: 8.0
env: TEST_SUITE=PHP_CodeSniffer
- php: 8.0
env: TEST_SUITE=10.0.x

mysql:
database: og
Expand Down Expand Up @@ -65,7 +69,7 @@ before_script:

# Install Composer dependencies for core. Skip this for the coding standards test.
- test ${TEST_SUITE} == "PHP_CodeSniffer" || composer install --working-dir=$DRUPAL_DIR

# Start a web server on port 8888 in the background.
- test ${TEST_SUITE} == "PHP_CodeSniffer" || nohup php -S localhost:8888 --docroot $DRUPAL_DIR > /dev/null 2>&1 &

Expand Down
6 changes: 1 addition & 5 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -24,13 +24,9 @@
"homepage": "https://www.drupal.org/u/pfrenssen"
}
],
"require": {
"php": "^7.4 || ^8",
"drupal/core": "^9.3"
},
"require-dev": {
"drupal/coder": "^8.3.16",
"phpunit/phpunit": "^7 || ^8"
"phpunit/phpunit": "^7 || ^8 || ^9"
},
"minimum-stability": "RC",
"config": {
Expand Down
3 changes: 1 addition & 2 deletions og.info.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,8 @@ name: Organic Groups
description: API to allow associating content with groups.
package: Organic Groups

core_version_requirement: ^9
core_version_requirement: ^9 || ^10
type: module
php: 7.1

dependencies:
- drupal:options
Expand Down
4 changes: 2 additions & 2 deletions og_ui/og_ui.info.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,9 @@ description: User interface for Organic Groups.
package: Organic Groups

type: module
core_version_requirement: ^9
core_version_requirement: ^9 || ^10

dependencies:
- og
- og:og

configure: og_ui.admin_index
2 changes: 1 addition & 1 deletion og_ui/src/BundleFormAlter.php
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ protected function prepare(array &$form, FormStateInterface $form_state) {
// Example: article.
$this->bundle = $this->entity->id();
// Example: Article.
$this->bundleLabel = Unicode::lcfirst($this->entity->label());
$this->bundleLabel = Unicode::lcfirst((string) $this->entity->label());
$this->definition = $this->entity->getEntityType();
// Example: node.
$this->entityTypeId = $this->definition->getBundleOf();
Expand Down
2 changes: 1 addition & 1 deletion og_ui/tests/src/Functional/BundleFormAlterTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ class BundleFormAlterTest extends BrowserTestBase {
/**
* {@inheritdoc}
*/
public static $modules = ['block_content', 'entity_test', 'node', 'og_ui'];
protected static $modules = ['block_content', 'entity_test', 'node', 'og_ui'];

/**
* {@inheritdoc}
Expand Down
2 changes: 1 addition & 1 deletion src/Controller/OgAdminRoutesController.php
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ public function overview(RouteMatchInterface $route_match) {
$content = [];

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

foreach ($event->getRoutes($entity_type_id) as $name => $info) {
$route_name = "entity.$entity_type_id.og_admin_routes.$name";
Expand Down
4 changes: 2 additions & 2 deletions src/Entity/OgMembership.php
Original file line number Diff line number Diff line change
Expand Up @@ -544,8 +544,8 @@ public function preSave(EntityStorageInterface $storage) {
}

// Check for an existing membership.
$query = \Drupal::entityQuery('og_membership');
$query
$query = \Drupal::entityQuery('og_membership')
->accessCheck()
->condition('uid', $uid)
->condition('entity_id', $entity_id)
->condition('entity_type', $this->get('entity_type')->value);
Expand Down
9 changes: 9 additions & 0 deletions src/Entity/OgRole.php
Original file line number Diff line number Diff line change
Expand Up @@ -323,7 +323,16 @@ protected function ogAccess() {
* {@inheritdoc}
*/
public function calculateDependencies() {
// The parent method is checking for the existence of each role-assigned
// permission. But in OG this isn't mandatory. Backup the permissions before
// calling the parent method and avoid performing the check.
// @see https://www.drupal.org/node/3193348
// @todo Consider decoupling 'og_role' from 'role' entity config and
// implementing the missing methods in 'og_role'.
$permissions = $this->permissions;
$this->permissions = [];
parent::calculateDependencies();
$this->permissions = $permissions;

// Create a dependency on the group bundle.
$bundle_config_dependency = \Drupal::entityTypeManager()->getDefinition($this->getGroupType())->getBundleConfigDependency($this->getGroupBundle());
Expand Down
2 changes: 1 addition & 1 deletion src/Event/AccessEventBase.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
use Drupal\Core\Cache\RefinableCacheableDependencyTrait;
use Drupal\Core\Entity\ContentEntityInterface;
use Drupal\Core\Session\AccountInterface;
use Symfony\Component\EventDispatcher\Event;
use Symfony\Contracts\EventDispatcher\Event;

/**
* Base class for OG access events.
Expand Down
11 changes: 6 additions & 5 deletions src/Event/DefaultRoleEvent.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
namespace Drupal\og\Event;

use Drupal\og\Entity\OgRole;
use Symfony\Component\EventDispatcher\Event;
use Symfony\Contracts\EventDispatcher\Event;

/**
* Event that is fired when default roles are compiled.
Expand Down Expand Up @@ -97,14 +97,15 @@ public function hasRole($name) {
/**
* {@inheritdoc}
*/
#[\ReturnTypeWillChange]
public function offsetGet($key) {
return $this->getRole($key);
}

/**
* {@inheritdoc}
*/
public function offsetSet($key, $role) {
public function offsetSet($key, $role): void {
$this->validate($role);
if ($role->getName() !== $key) {
throw new \InvalidArgumentException('The key and the "name" property of the role should be identical.');
Expand All @@ -115,21 +116,21 @@ public function offsetSet($key, $role) {
/**
* {@inheritdoc}
*/
public function offsetUnset($key) {
public function offsetUnset($key): void {
$this->deleteRole($key);
}

/**
* {@inheritdoc}
*/
public function offsetExists($key) {
public function offsetExists($key): bool {
return $this->hasRole($key);
}

/**
* {@inheritdoc}
*/
public function getIterator() {
public function getIterator(): \Traversable {
return new \ArrayIterator($this->roles);
}

Expand Down
2 changes: 1 addition & 1 deletion src/Event/GroupCreationEvent.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

namespace Drupal\og\Event;

use Symfony\Component\EventDispatcher\Event;
use Symfony\Contracts\EventDispatcher\Event;

/**
* The group creation event.
Expand Down
2 changes: 1 addition & 1 deletion src/Event/OgAdminRoutesEvent.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

use Drupal\Component\Utility\NestedArray;
use Drupal\og\OgAccess;
use Symfony\Component\EventDispatcher\Event;
use Symfony\Contracts\EventDispatcher\Event;

/**
* Event that is fired when OG admin routes are being compiled.
Expand Down
2 changes: 1 addition & 1 deletion src/Event/PermissionEvent.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

use Drupal\og\GroupContentOperationPermission;
use Drupal\og\PermissionInterface;
use Symfony\Component\EventDispatcher\Event;
use Symfony\Contracts\EventDispatcher\Event;

/**
* Event that is fired when OG permissions are compiled.
Expand Down
2 changes: 1 addition & 1 deletion src/GroupTypeManager.php
Original file line number Diff line number Diff line change
Expand Up @@ -284,7 +284,7 @@ public function addGroup($entity_type_id, $bundle_id) {

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

$this->ogRoleManager->createPerBundleRoles($entity_type_id, $bundle_id);
$this->refreshGroupMap();
Expand Down
4 changes: 4 additions & 0 deletions src/MembershipManager.php
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,7 @@ public function getMemberships($user_id, array $states = [OgMembershipInterface:
$query = $this->entityTypeManager
->getStorage('og_membership')
->getQuery()
->accessCheck()
->condition('uid', $user_id)
->condition('state', $states, 'IN');

Expand Down Expand Up @@ -185,6 +186,7 @@ public function getGroupMembershipCount(EntityInterface $group, array $states =
$query = $this->entityTypeManager
->getStorage('og_membership')
->getQuery()
->accessCheck()
->condition('entity_id', $group->id());

if ($states) {
Expand Down Expand Up @@ -231,6 +233,7 @@ public function getGroupMembershipIdsByRoleNames(EntityInterface $group, array $
$query = $this->entityTypeManager
->getStorage('og_membership')
->getQuery()
->accessCheck()
->condition('entity_type', $entity_type_id)
->condition('entity_id', $group->id())
->condition('state', $states, 'IN');
Expand Down Expand Up @@ -418,6 +421,7 @@ public function getGroupContentIds(EntityInterface $entity, array $entity_types
$results = $this->entityTypeManager
->getStorage($group_content_entity_type)
->getQuery()
->accessCheck()
->condition($field->getName() . '.target_id', $entity->id())
->execute();

Expand Down
2 changes: 1 addition & 1 deletion src/OgAccess.php
Original file line number Diff line number Diff line change
Expand Up @@ -323,7 +323,7 @@ public function userAccessGroupContentEntityOperation(string $operation, EntityI
$event->addCacheContexts(['user']);
}

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

return $event->getAccessResult();
}
Expand Down
1 change: 1 addition & 0 deletions src/OgDeleteOrphansBase.php
Original file line number Diff line number Diff line change
Expand Up @@ -120,6 +120,7 @@ protected function query(EntityInterface $entity) {
// Register orphaned user memberships.
$membership_ids = $this->entityTypeManager->getStorage('og_membership')
->getQuery()
->accessCheck()
->condition('entity_type', $entity->getEntityTypeId())
->condition('entity_id', $entity->id())
->execute();
Expand Down
2 changes: 1 addition & 1 deletion src/OgRoleManager.php
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ public function getDefaultRoles() {
$roles = $this->getRequiredDefaultRoles();

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

// Use the array union operator '+=' to ensure the default roles cannot be
// altered by event subscribers.
Expand Down
2 changes: 1 addition & 1 deletion src/PermissionManager.php
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ public function __construct(EventDispatcherInterface $event_dispatcher) {
*/
public function getDefaultPermissions($group_entity_type_id, $group_bundle_id, array $group_content_bundle_ids, $role_name = NULL) {
$event = new PermissionEvent($group_entity_type_id, $group_bundle_id, $group_content_bundle_ids);
$this->eventDispatcher->dispatch(PermissionEventInterface::EVENT_NAME, $event);
$this->eventDispatcher->dispatch($event, PermissionEventInterface::EVENT_NAME);
return $event->getPermissions();
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,7 @@ public function validate($value, Constraint $constraint) {
$query = $this->entityTypeManager
->getStorage('og_membership')
->getQuery()
->accessCheck()
->condition('entity_type', $entity->getGroupEntityType())
->condition('entity_id', $entity->getGroupId())
->condition('uid', $new_member_uid);
Expand Down
4 changes: 2 additions & 2 deletions src/Routing/RouteSubscriber.php
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,7 @@ protected function alterRoutes(RouteCollection $collection) {
*/
protected function createRoutesFromEventSubscribers($og_admin_path, $entity_type_id, RouteCollection $collection) {
$event = new OgAdminRoutesEvent();
$this->eventDispatcher->dispatch(OgAdminRoutesEventInterface::EVENT_NAME, $event);
$this->eventDispatcher->dispatch($event, OgAdminRoutesEventInterface::EVENT_NAME);

foreach ($event->getRoutes($entity_type_id) as $name => $route_info) {
// Add the parent route.
Expand Down Expand Up @@ -165,7 +165,7 @@ protected function addRoute(RouteCollection $collection, $route_name, $path, arr
* We have such a case with the "members" OG admin route, that requires Views
* module to be enabled.
*/
public static function getSubscribedEvents() {
public static function getSubscribedEvents(): array {
$events[RoutingEvents::ALTER] = ['onAlterRoutes', 100];
return $events;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,6 @@ name: 'OG standard reference test views'
type: module
description: 'Provides default views for views OG standard reference tests.'
package: Testing
core_version_requirement: ^9
core_version_requirement: ^9 || ^10
dependencies:
- drupal:views
2 changes: 1 addition & 1 deletion tests/modules/og_test/og_test.info.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,6 @@ name: 'Organic Groups test'
type: module
description: 'Support module for Organic Groups testing.'
package: Testing
core_version_requirement: ^9
core_version_requirement: ^9 || ^10
dependencies:
- drupal:options
2 changes: 1 addition & 1 deletion tests/src/Functional/GroupSubscribeFormatterTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ class GroupSubscribeFormatterTest extends BrowserTestBase {
/**
* {@inheritdoc}
*/
public static $modules = ['node', 'og', 'options'];
protected static $modules = ['node', 'og', 'options'];

/**
* {@inheritdoc}
Expand Down
2 changes: 1 addition & 1 deletion tests/src/Functional/GroupSubscribeTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ class GroupSubscribeTest extends BrowserTestBase {
/**
* {@inheritdoc}
*/
public static $modules = ['node', 'og'];
protected static $modules = ['node', 'og'];

/**
* {@inheritdoc}
Expand Down
Loading

0 comments on commit 213a9c1

Please sign in to comment.