Skip to content
Snippets Groups Projects

Issue #3371070: Support user bundles

1 file
+ 21
4
Compare changes
  • Side-by-side
  • Inline
+ 21
4
@@ -5,6 +5,7 @@ declare(strict_types=1);
namespace Drupal\jsonapi_user_resources\Routing;
use Drupal\Core\DependencyInjection\ContainerInjectionInterface;
use Drupal\Core\Entity\EntityTypeBundleInfoInterface;
use Drupal\jsonapi\ResourceType\ResourceTypeRepositoryInterface;
use Drupal\jsonapi_user_resources\Resource\PasswordReset;
use Drupal\jsonapi_user_resources\Resource\PasswordUpdate;
@@ -25,6 +26,13 @@ class Routes implements ContainerInjectionInterface {
*/
protected $resourceTypeRepository;
/**
* The entity type bundle info service.
*
* @var \Drupal\Core\Entity\EntityTypeBundleInfoInterface
*/
protected $entityTypeBundleInfo;
/**
* The user resource type names.
*
@@ -37,9 +45,12 @@ class Routes implements ContainerInjectionInterface {
*
* @param \Drupal\jsonapi\ResourceType\ResourceTypeRepositoryInterface $resource_type_repository
* The JSON:API resource type repository.
* @param \Drupal\Core\Entity\EntityTypeBundleInfoInterface $entity_type_bundle_info
* The entity type bundle info service.
*/
public function __construct(ResourceTypeRepositoryInterface $resource_type_repository) {
public function __construct(ResourceTypeRepositoryInterface $resource_type_repository, EntityTypeBundleInfoInterface $entity_type_bundle_info) {
$this->resourceTypeRepository = $resource_type_repository;
$this->entityTypeBundleInfo = $entity_type_bundle_info;
}
/**
@@ -47,7 +58,8 @@ class Routes implements ContainerInjectionInterface {
*/
public static function create(ContainerInterface $container) {
return new static(
$container->get('jsonapi.resource_type.repository')
$container->get('jsonapi.resource_type.repository'),
$container->get('entity_type.bundle.info'),
);
}
@@ -137,8 +149,13 @@ class Routes implements ContainerInjectionInterface {
*/
protected function getResourceTypeNames(): array {
if (empty($this->resourceTypeNames)) {
$resource_type = $this->resourceTypeRepository->get('user', 'user');
$this->resourceTypeNames = [$resource_type->getTypeName()];
$user_bundle_types = $this->entityTypeBundleInfo->getBundleInfo('user');
if (!empty($user_bundle_types)) {
foreach (array_keys($user_bundle_types) as $bundle) {
$resource_type = $this->resourceTypeRepository->get('user', $bundle);
$this->resourceTypeNames[] = $resource_type->getTypeName();
}
}
}
return $this->resourceTypeNames;
}
Loading