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

Signature of EventDispatcherInterface::dispatch() has changed #733

Closed
wants to merge 6 commits into from
Closed
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
4 changes: 2 additions & 2 deletions og.module
Original file line number Diff line number Diff line change
Expand Up @@ -253,10 +253,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
6 changes: 3 additions & 3 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 Down
54 changes: 28 additions & 26 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,34 +178,35 @@ 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 {
// To avoid insanity, a group membership cannot be a group or group content.
if ($entity_type_id === 'og_membership') {
return FALSE;
}

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 $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 @@ -219,7 +221,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 @@ -230,7 +232,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 @@ -255,15 +257,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 $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 {
// To avoid insanity, a group membership cannot be a group or group content.
if ($entity_type_id === 'og_membership') {
throw new \InvalidArgumentException("The '$entity_type_id' type cannot be a group.");
Expand Down Expand Up @@ -296,7 +298,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 @@ -324,30 +326,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 @@ -360,7 +362,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 or is invalid.
*/
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