Commit d2589a1e authored by stBorchert's avatar stBorchert Committed by e0ipso
Browse files

Issue #3111290 by stBorchert, e0ipso: Allow fetching repository by entity type and bundle

parent c7bf9f5a
......@@ -41,9 +41,28 @@ final class RepositoryManager implements EntityWrapperInterface {
* @todo: The variant negotiation is still missing.
*/
public function repositoryFromEntity(EntityInterface $entity): TypedEntityRepositoryInterface {
return $this->repository($entity->getEntityTypeId(), $entity->bundle());
}
/**
* Gets the entity repository based on the entity information and the variant.
*
* @param \Drupal\Core\Entity\EntityInterface $entity
* The entity to extract info for.
*
* @return \Drupal\typed_entity\TypedRepositories\TypedEntityRepositoryInterface
* The repository for the entity.
*
* @throws \Drupal\typed_entity\RepositoryNotFoundException
* When the repository was not found.
*
* @todo: The variant negotiation is still missing.
*/
public function repository(string $entity_type_id, string $bundle = ''): TypedEntityRepositoryInterface {
$bundle = $bundle ?: $entity_type_id;
$identifier = implode(
TypedEntityRepositoryBase::SEPARATOR,
array_filter([$entity->getEntityTypeId(), $entity->bundle()])
array_filter([$entity_type_id, $bundle])
);
$repository = $this->collector->get($identifier);
if (empty($repository)) {
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment