diff --git a/src/GroupServiceProvider.php b/src/GroupServiceProvider.php index 5c504bb..95e6f1c 100644 --- a/src/GroupServiceProvider.php +++ b/src/GroupServiceProvider.php @@ -38,6 +38,7 @@ class GroupServiceProvider extends ServiceProviderBase { new Reference('content_moderation.moderation_information'), new Reference('current_route_match'), new Reference('entity_type.manager'), + new Reference('plugin.manager.group_content_enabler'), ]); $state_transition_definition->setPublic(TRUE); $state_transition_definition->setDecoratedService('content_moderation.state_transition_validation'); diff --git a/src/StateTransitionValidation.php b/src/StateTransitionValidation.php index 7ea7771..8364a9a 100644 --- a/src/StateTransitionValidation.php +++ b/src/StateTransitionValidation.php @@ -8,6 +8,7 @@ use Drupal\Core\Entity\ContentEntityInterface; use Drupal\Core\Entity\EntityTypeManagerInterface; use Drupal\Core\Routing\RouteMatchInterface; use Drupal\Core\Session\AccountInterface; +use Drupal\group\Plugin\GroupContentEnablerManagerInterface; use Drupal\workflows\Transition; /** @@ -43,6 +44,13 @@ class StateTransitionValidation implements StateTransitionValidationInterface { */ protected $routeMatch; + /** + * The group content enabler plugin manager. + * + * @var \Drupal\group\Plugin\GroupContentEnablerManager + */ + protected $groupContentEnablerManager; + /** * Constructs the group state transition validation object. * @@ -54,12 +62,15 @@ class StateTransitionValidation implements StateTransitionValidationInterface { * The current route match service. * @param \Drupal\Core\Entity\EntityTypeManagerInterface $entity_type_manager * The entity type manager service. + * @param \Drupal\group\Plugin\GroupContentEnablerManager $group_content_enabler_manager + * The group content enabler plugin manager. */ - public function __construct(StateTransitionValidationInterface $inner, ModerationInformationInterface $moderation_information, RouteMatchInterface $route_match, EntityTypeManagerInterface $entity_type_manager) { + public function __construct(StateTransitionValidationInterface $inner, ModerationInformationInterface $moderation_information, RouteMatchInterface $route_match, EntityTypeManagerInterface $entity_type_manager, GroupContentEnablerManagerInterface $group_content_enabler_manager) { $this->inner = $inner; $this->entityTypeManager = $entity_type_manager; $this->moderationInformation = $moderation_information; $this->routeMatch = $route_match; + $this->groupContentEnablerManager = $group_content_enabler_manager; } /** @@ -121,7 +132,18 @@ class StateTransitionValidation implements StateTransitionValidationInterface { * @return string */ protected function getPluginId(ContentEntityInterface $entity) { - return 'group_' . $entity->getEntityTypeId() . ':' . $entity->bundle(); + $generic = FALSE; + foreach ($this->groupContentEnablerManager->getDefinitions() as $id => $def) { + if ($def['entity_type_id'] == $entity->getEntityTypeId() + && $def['entity_bundle'] == $entity->bundle()) { + + return $id; + } + elseif ($def['entity_type_id'] === $entity->getEntityTypeId()) { + $generic = $id; + } + } + return $generic ?: FALSE; } /**