diff --git a/src/Controller/Frontend/TaxonomyController.php b/src/Controller/Frontend/TaxonomyController.php index 93fca45e..531679bc 100644 --- a/src/Controller/Frontend/TaxonomyController.php +++ b/src/Controller/Frontend/TaxonomyController.php @@ -39,9 +39,10 @@ class TaxonomyController extends TwigAwareController public function listing(ContentRepository $contentRepository, Request $request, string $taxonomyslug, string $slug): Response { $page = (int) $request->query->get('page', 1); + $amountPerPage = $this->config->get('general/listing_records'); /** @var Content[] $records */ - $records = $contentRepository->findForTaxonomy($page, $taxonomyslug, $slug, $this->config->get('listing_records')); + $records = $contentRepository->findForTaxonomy($page, $taxonomyslug, $slug, $amountPerPage); $templates = $this->templateChooser->forTaxonomy($taxonomyslug); diff --git a/src/DataFixtures/BaseFixture.php b/src/DataFixtures/BaseFixture.php index 4bcca59f..2f352642 100644 --- a/src/DataFixtures/BaseFixture.php +++ b/src/DataFixtures/BaseFixture.php @@ -11,23 +11,23 @@ abstract class BaseFixture extends Fixture private $referencesIndex = []; private $taxonomyIndex = []; - protected function getRandomReference(string $className) + protected function getRandomReference(string $entityName) { - if (! isset($this->referencesIndex[$className])) { - $this->referencesIndex[$className] = []; + if (! isset($this->referencesIndex[$entityName])) { + $this->referencesIndex[$entityName] = []; foreach (array_keys($this->referenceRepository->getReferences()) as $key) { - if (mb_strpos($key, $className.'_') === 0) { - $this->referencesIndex[$className][] = $key; + if (mb_strpos($key, $entityName.'_') === 0) { + $this->referencesIndex[$entityName][] = $key; } } } - if (empty($this->referencesIndex[$className])) { - throw new \Exception(sprintf('Cannot find any references for class "%s"', $className)); + if (empty($this->referencesIndex[$entityName])) { + throw new \Exception(sprintf('Cannot find any references for Entity "%s"', $entityName)); } - $randomReferenceKey = array_rand($this->referencesIndex[$className], 1); + $randomReferenceKey = array_rand($this->referencesIndex[$entityName], 1); - return $this->getReference($this->referencesIndex[$className][$randomReferenceKey]); + return $this->getReference($this->referencesIndex[$entityName][$randomReferenceKey]); } protected function getRandomTaxonomy(string $type) diff --git a/src/Repository/ContentRepository.php b/src/Repository/ContentRepository.php index e84e0e45..cf92b24f 100644 --- a/src/Repository/ContentRepository.php +++ b/src/Repository/ContentRepository.php @@ -48,10 +48,12 @@ class ContentRepository extends ServiceEntityRepository ->setParameter('status', Statuses::PUBLISHED); } - return $this->createPaginator($qb->getQuery(), $page, $contentType['listing_records']); + $amountPerPage = $contentType['listing_records']; + + return $this->createPaginator($qb->getQuery(), $page, $amountPerPage); } - public function findForTaxonomy(int $page, string $taxonomyslug, string $slug, ?int $amountPerPage = null, bool $onlyPublished = true): Pagerfanta + public function findForTaxonomy(int $page, string $taxonomyslug, string $slug, int $amountPerPage, bool $onlyPublished = true): Pagerfanta { $qb = $this->getQueryBuilder() ->addSelect('a') @@ -105,7 +107,7 @@ class ContentRepository extends ServiceEntityRepository private function createPaginator(Query $query, int $page, ?int $amountPerPage): Pagerfanta { $paginator = new Pagerfanta(new DoctrineORMAdapter($query)); - $paginator->setMaxPerPage($amountPerPage ?: 6); + $paginator->setMaxPerPage($amountPerPage); $paginator->setCurrentPage($page); return $paginator;