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

Commit

Permalink
Signature of EventDispatcherInterface::dispatch() has changed
Browse files Browse the repository at this point in the history
In Drupal 9.1 the order of the arguments to this method has been changed.
Ref. https://www.drupal.org/node/3154407

Fixes #725.
  • Loading branch information
pfrenssen committed Dec 17, 2021
1 parent 6e48e1f commit ac9d2af
Show file tree
Hide file tree
Showing 15 changed files with 139 additions and 141 deletions.
4 changes: 2 additions & 2 deletions og.module
Original file line number Diff line number Diff line change
Expand Up @@ -235,10 +235,10 @@ function og_entity_create_access(AccountInterface $account, array $context, $bun
*
* Add a read only property to group entities as a group flag.
*/
function og_entity_bundle_field_info(EntityTypeInterface $entity_type, $bundle, array $base_field_definitions) {
function og_entity_bundle_field_info(EntityTypeInterface $entity_type, string $bundle, array $base_field_definitions): array {
if (!Og::isGroup($entity_type->id(), $bundle)) {
// Not a group type.
return NULL;
return [];
}

$fields = [];
Expand Down
8 changes: 4 additions & 4 deletions src/Controller/OgAdminRoutesController.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,14 +23,14 @@ class OgAdminRoutesController extends ControllerBase {
*
* @var \Drupal\Component\EventDispatcher\ContainerAwareEventDispatcher
*/
protected $eventDispatcher;
protected ContainerAwareEventDispatcher $eventDispatcher;

/**
* The access manager service.
*
* @var \Drupal\Core\Access\AccessManagerInterface
*/
protected $accessManager;
protected AccessManagerInterface $accessManager;

/**
* Constructs an OgAdminController object.
Expand Down Expand Up @@ -64,7 +64,7 @@ public static function create(ContainerInterface $container) {
* @return array
* List of available admin routes for the current group.
*/
public function overview(RouteMatchInterface $route_match) {
public function overview(RouteMatchInterface $route_match): array {
$parameter_name = $route_match->getRouteObject()->getOption('_og_entity_type_id');

/** @var \Drupal\Core\Entity\EntityInterface $group */
Expand All @@ -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
59 changes: 30 additions & 29 deletions src/GroupTypeManager.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
use Drupal\Core\Config\ConfigFactoryInterface;
use Drupal\Core\Entity\EntityTypeBundleInfoInterface;
use Drupal\Core\Entity\EntityTypeManagerInterface;
use Drupal\Core\Extension\ModuleHandlerInterface;
use Drupal\Core\Routing\RouteBuilderInterface;
use Drupal\og\Event\GroupCreationEvent;
use Drupal\og\Event\GroupCreationEventInterface;
Expand Down Expand Up @@ -42,35 +43,35 @@ class GroupTypeManager implements GroupTypeManagerInterface {
*
* @var \Drupal\Core\Config\ConfigFactoryInterface
*/
protected $configFactory;
protected ConfigFactoryInterface $configFactory;

/**
* The service providing information about bundles.
*
* @var \Drupal\Core\Entity\EntityTypeBundleInfoInterface
*/
protected $entityTypeBundleInfo;
protected EntityTypeBundleInfoInterface $entityTypeBundleInfo;

/**
* The event dispatcher.
*
* @var \Symfony\Component\EventDispatcher\EventDispatcherInterface
*/
protected $eventDispatcher;
protected EventDispatcherInterface $eventDispatcher;

/**
* The cache backend.
*
* @var \Drupal\Core\Cache\CacheBackendInterface
*/
protected $cache;
protected CacheBackendInterface $cache;

/**
* The OG permission manager.
*
* @var \Drupal\og\PermissionManagerInterface
*/
protected $permissionManager;
protected PermissionManagerInterface $permissionManager;

/**
* A map of entity types and bundles.
Expand All @@ -79,7 +80,7 @@ class GroupTypeManager implements GroupTypeManagerInterface {
*
* @var array
*/
protected $groupMap;
protected array $groupMap;

/**
* A map of group and group content relations.
Expand All @@ -103,42 +104,42 @@ class GroupTypeManager implements GroupTypeManagerInterface {
* ]
* @endcode
*/
protected $groupRelationMap = [];
protected array $groupRelationMap = [];

/**
* The module handler.
*
* @var \Drupal\Core\Extension\ModuleHandlerInterface
*/
protected $moduleHandler;
protected ModuleHandlerInterface $moduleHandler;

/**
* The OG role manager.
*
* @var \Drupal\og\OgRoleManagerInterface
*/
protected $ogRoleManager;
protected OgRoleManagerInterface $ogRoleManager;

/**
* The route builder service.
*
* @var \Drupal\Core\Routing\RouteBuilderInterface
*/
protected $routeBuilder;
protected RouteBuilderInterface $routeBuilder;

/**
* The OG group audience helper.
*
* @var \Drupal\og\OgGroupAudienceHelperInterface
*/
protected $groupAudienceHelper;
protected OgGroupAudienceHelperInterface $groupAudienceHelper;

/**
* The Entity type manager service.
*
* @var \Drupal\Core\Entity\EntityTypeManagerInterface
*/
protected $entityTypeManager;
protected EntityTypeManagerInterface $entityTypeManager;

/**
* Constructs a GroupTypeManager object.
Expand Down Expand Up @@ -177,30 +178,30 @@ public function __construct(ConfigFactoryInterface $config_factory, EntityTypeMa
/**
* {@inheritdoc}
*/
public function isGroup($entity_type_id, $bundle) {
public function isGroup(string $entity_type_id, string $bundle): bool {
$group_map = $this->getGroupMap();
return isset($group_map[$entity_type_id]) && in_array($bundle, $group_map[$entity_type_id]);
}

/**
* {@inheritdoc}
*/
public function isGroupContent($entity_type_id, $bundle) {
public function isGroupContent(string $entity_type_id, string $bundle): bool {
return $this->groupAudienceHelper->hasGroupAudienceField($entity_type_id, $bundle);
}

/**
* {@inheritdoc}
*/
public function getGroupBundleIdsByEntityType($entity_type_id) {
public function getGroupBundleIdsByEntityType(string $entity_type_id): array {
$group_map = $this->getGroupMap();
return isset($group_map[$entity_type_id]) ? $group_map[$entity_type_id] : [];
return $group_map[$entity_type_id] ?? [];
}

/**
* {@inheritdoc}
*/
public function getAllGroupContentBundleIds() {
public function getAllGroupContentBundleIds(): array {
$bundles = [];
foreach ($this->getGroupRelationMap() as $group_bundle_ids) {
foreach ($group_bundle_ids as $group_content_entity_type_ids) {
Expand All @@ -215,7 +216,7 @@ public function getAllGroupContentBundleIds() {
/**
* {@inheritdoc}
*/
public function getAllGroupContentBundlesByEntityType($entity_type_id) {
public function getAllGroupContentBundlesByEntityType(string $entity_type_id): array {
$bundles = $this->getAllGroupContentBundleIds();
if (!isset($bundles[$entity_type_id])) {
throw new \InvalidArgumentException("The '$entity_type_id' entity type has no group content bundles.");
Expand All @@ -226,7 +227,7 @@ public function getAllGroupContentBundlesByEntityType($entity_type_id) {
/**
* {@inheritdoc}
*/
public function getGroupBundleIdsByGroupContentBundle($group_content_entity_type_id, $group_content_bundle_id) {
public function getGroupBundleIdsByGroupContentBundle(string $group_content_entity_type_id, string $group_content_bundle_id): array {
$bundles = [];

foreach ($this->groupAudienceHelper->getAllGroupAudienceFields($group_content_entity_type_id, $group_content_bundle_id) as $field) {
Expand All @@ -251,15 +252,15 @@ public function getGroupBundleIdsByGroupContentBundle($group_content_entity_type
/**
* {@inheritdoc}
*/
public function getGroupContentBundleIdsByGroupBundle($group_entity_type_id, $group_bundle_id) {
public function getGroupContentBundleIdsByGroupBundle(string $group_entity_type_id, string $group_bundle_id): array {
$group_relation_map = $this->getGroupRelationMap();
return isset($group_relation_map[$group_entity_type_id][$group_bundle_id]) ? $group_relation_map[$group_entity_type_id][$group_bundle_id] : [];
return $group_relation_map[$group_entity_type_id][$group_bundle_id] ?? [];
}

/**
* {@inheritdoc}
*/
public function addGroup($entity_type_id, $bundle_id) {
public function addGroup(string $entity_type_id, string $bundle_id): void {
// Throw an error if the entity type is already defined as a group.
if ($this->isGroup($entity_type_id, $bundle_id)) {
throw new \InvalidArgumentException("The '$entity_type_id' of type '$bundle_id' is already a group.");
Expand All @@ -276,7 +277,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 All @@ -288,7 +289,7 @@ public function addGroup($entity_type_id, $bundle_id) {
/**
* {@inheritdoc}
*/
public function removeGroup($entity_type_id, $bundle_id) {
public function removeGroup(string $entity_type_id, string $bundle_id): void {
$editable = $this->configFactory->getEditable('og.settings');
$groups = $editable->get('groups');

Expand Down Expand Up @@ -316,30 +317,30 @@ public function removeGroup($entity_type_id, $bundle_id) {
/**
* {@inheritdoc}
*/
public function reset() {
public function reset(): void {
$this->resetGroupMap();
$this->resetGroupRelationMap();
}

/**
* {@inheritdoc}
*/
public function resetGroupMap() {
public function resetGroupMap(): void {
$this->groupMap = [];
}

/**
* {@inheritdoc}
*/
public function resetGroupRelationMap() {
public function resetGroupRelationMap(): void {
$this->groupRelationMap = [];
$this->cache->delete(self::GROUP_RELATION_MAP_CACHE_KEY);
}

/**
* {@inheritdoc}
*/
public function getGroupMap() {
public function getGroupMap(): array {
if (empty($this->groupMap)) {
$this->refreshGroupMap();
}
Expand All @@ -352,7 +353,7 @@ public function getGroupMap() {
* @return array
* The group relation map.
*/
protected function getGroupRelationMap() {
protected function getGroupRelationMap(): array {
if (empty($this->groupRelationMap)) {
$this->populateGroupRelationMap();
}
Expand Down
26 changes: 13 additions & 13 deletions src/GroupTypeManagerInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ interface GroupTypeManagerInterface {
* @return bool
* TRUE if a bundle is a group.
*/
public function isGroup($entity_type_id, $bundle);
public function isGroup(string $entity_type_id, string $bundle): bool;

/**
* Checks if the given entity bundle is group content.
Expand All @@ -36,7 +36,7 @@ public function isGroup($entity_type_id, $bundle);
* @return bool
* TRUE if the entity bundle is group content.
*/
public function isGroupContent($entity_type_id, $bundle);
public function isGroupContent(string $entity_type_id, string $bundle): bool;

/**
* Returns the group of an entity type.
Expand All @@ -47,7 +47,7 @@ public function isGroupContent($entity_type_id, $bundle);
* @return \Drupal\Core\Entity\EntityInterface[]
* Array of groups, or an empty array if none found
*/
public function getGroupBundleIdsByEntityType($entity_type_id);
public function getGroupBundleIdsByEntityType(string $entity_type_id): array;

/**
* Returns a list of all group content bundles IDs keyed by entity type.
Expand All @@ -62,7 +62,7 @@ public function getGroupBundleIdsByEntityType($entity_type_id);
*
* @see \Drupal\og\GroupTypeManagerInterface::getGroupRelationMap()
*/
public function getAllGroupContentBundleIds();
public function getAllGroupContentBundleIds(): array;

/**
* Returns a list of all group content bundles filtered by entity type.
Expand All @@ -83,7 +83,7 @@ public function getAllGroupContentBundleIds();
*
* @see \Drupal\og\GroupTypeManagerInterface::getGroupRelationMap()
*/
public function getAllGroupContentBundlesByEntityType($entity_type_id);
public function getAllGroupContentBundlesByEntityType(string $entity_type_id): array;

/**
* Returns all group bundles that are referenced by the given group content.
Expand All @@ -98,7 +98,7 @@ public function getAllGroupContentBundlesByEntityType($entity_type_id);
* @return string[][]
* An array of group bundle IDs, keyed by group entity type ID.
*/
public function getGroupBundleIdsByGroupContentBundle($group_content_entity_type_id, $group_content_bundle_id);
public function getGroupBundleIdsByGroupContentBundle(string $group_content_entity_type_id, string $group_content_bundle_id): array;

/**
* Returns group content bundles that are referencing the given group content.
Expand All @@ -114,7 +114,7 @@ public function getGroupBundleIdsByGroupContentBundle($group_content_entity_type
* An array of group content bundle IDs, keyed by group content entity type
* ID.
*/
public function getGroupContentBundleIdsByGroupBundle($group_entity_type_id, $group_bundle_id);
public function getGroupContentBundleIdsByGroupBundle(string $group_entity_type_id, string $group_bundle_id): array;

/**
* Declares a bundle of an entity type as being an OG group.
Expand All @@ -127,39 +127,39 @@ public function getGroupContentBundleIdsByGroupBundle($group_entity_type_id, $gr
* @throws \InvalidArgumentException
* Thrown when the given bundle is already a group.
*/
public function addGroup($entity_type_id, $bundle_id);
public function addGroup(string $entity_type_id, string $bundle_id): void;

/**
* Removes an entity type instance as being an OG group.
*/
public function removeGroup($entity_type_id, $bundle_id);
public function removeGroup(string $entity_type_id, string $bundle_id): void;

/**
* Resets all locally stored data.
*/
public function reset();
public function reset(): void;

/**
* Resets the cached group map.
*
* Call this after adding or removing a group type.
*/
public function resetGroupMap();
public function resetGroupMap(): void;

/**
* Resets the cached group relation map.
*
* Call this after making a change to the relationship between a group type
* and a group content type.
*/
public function resetGroupRelationMap();
public function resetGroupRelationMap(): void;

/**
* Returns the group map.
*
* @return string[][]
* The group map.
*/
public function getGroupMap();
public function getGroupMap(): array;

}
Loading

0 comments on commit ac9d2af

Please sign in to comment.