Skip to content

Commit 0462d36

Browse files
committed
Used new findContentTypes PAPI contract in content type list
1 parent ebfb9c6 commit 0462d36

File tree

2 files changed

+67
-11
lines changed

2 files changed

+67
-11
lines changed

src/bundle/Controller/ContentTypeController.php

Lines changed: 13 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
use Ibexa\AdminUi\Form\Factory\FormFactory;
1919
use Ibexa\AdminUi\Form\SubmitHandler;
2020
use Ibexa\AdminUi\Form\Type\ContentType\ContentTypeUpdateType;
21+
use Ibexa\AdminUi\Pagination\Pagerfanta\ContentTypeListAdapter;
2122
use Ibexa\AdminUi\Service\MetaFieldType\MetaFieldDefinitionServiceInterface;
2223
use Ibexa\AdminUi\Tab\ContentType\TranslationsTab;
2324
use Ibexa\AdminUi\UI\Module\FieldTypeToolbar\FieldTypeToolbarFactory;
@@ -36,10 +37,12 @@
3637
use Ibexa\Contracts\Core\Repository\Values\ContentType\ContentType;
3738
use Ibexa\Contracts\Core\Repository\Values\ContentType\ContentTypeDraft;
3839
use Ibexa\Contracts\Core\Repository\Values\ContentType\ContentTypeGroup;
40+
use Ibexa\Contracts\Core\Repository\Values\ContentType\Query\ContentTypeQuery;
41+
use Ibexa\Contracts\Core\Repository\Values\ContentType\Query\Criterion\ContentTypeGroupId;
42+
use Ibexa\Contracts\Core\Repository\Values\ContentType\Query\SortClause\Name;
3943
use Ibexa\Contracts\Core\SiteAccess\ConfigResolverInterface;
4044
use Ibexa\Core\MVC\Symfony\Security\Authorization\Attribute;
4145
use JMS\TranslationBundle\Annotation\Desc;
42-
use Pagerfanta\Adapter\ArrayAdapter;
4346
use Pagerfanta\Pagerfanta;
4447
use Symfony\Component\Form\FormInterface;
4548
use Symfony\Component\HttpFoundation\RedirectResponse;
@@ -132,32 +135,31 @@ public function __construct(
132135
public function listAction(ContentTypeGroup $group, string $routeName, int $page): Response
133136
{
134137
$deletableTypes = [];
135-
$contentTypes = $this->contentTypeService->loadContentTypes($group, $this->configResolver->getParameter('languages'));
136-
137-
usort($contentTypes, static function (ContentType $contentType1, ContentType $contentType2) {
138-
return strnatcasecmp($contentType1->getName(), $contentType2->getName());
139-
});
138+
$languages = $this->configResolver->getParameter('languages');
139+
$limit = $this->configResolver->getParameter('pagination.content_type_limit');
140+
$query = new ContentTypeQuery(new ContentTypeGroupId($group->id), [new Name()]);
140141

141142
$pagerfanta = new Pagerfanta(
142-
new ArrayAdapter($contentTypes)
143+
new ContentTypeListAdapter($this->contentTypeService, $languages, $query)
143144
);
144145

145-
$pagerfanta->setMaxPerPage($this->configResolver->getParameter('pagination.content_type_limit'));
146+
$pagerfanta->setMaxPerPage($limit);
146147
$pagerfanta->setCurrentPage(min($page, $pagerfanta->getNbPages()));
147148

148-
/** @var \Ibexa\Contracts\Core\Repository\Values\ContentType\ContentTypeGroup[] $contentTypeGroupList */
149149
$types = $pagerfanta->getCurrentPageResults();
150150

151151
$deleteContentTypesForm = $this->formFactory->deleteContentTypes(
152-
new ContentTypesDeleteData($this->getContentTypesNumbers($types))
152+
new ContentTypesDeleteData($this->getContentTypesNumbers(
153+
\Ibexa\PolyfillPhp82\iterator_to_array($types)
154+
))
153155
);
154156

155157
foreach ($types as $type) {
156158
$deletableTypes[$type->id] = !$this->contentTypeService->isContentTypeUsed($type);
157159
}
158160

159161
$copyData = new ContentTypeCopyData(null, $group);
160-
$contentTypeCopyForm = $this->contentTypeFormFactory->contentTypeCopy($copyData, null)->createView();
162+
$contentTypeCopyForm = $this->contentTypeFormFactory->contentTypeCopy($copyData)->createView();
161163

162164
return $this->render('@ibexadesign/content_type/list.html.twig', [
163165
'content_type_group' => $group,
Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
<?php
2+
3+
/**
4+
* @copyright Copyright (C) Ibexa AS. All rights reserved.
5+
* @license For full copyright and license information view LICENSE file distributed with this source code.
6+
*/
7+
declare(strict_types=1);
8+
9+
namespace Ibexa\AdminUi\Pagination\Pagerfanta;
10+
11+
use Ibexa\Contracts\Core\Repository\ContentTypeService;
12+
use Ibexa\Contracts\Core\Repository\Values\ContentType\Query\ContentTypeQuery;
13+
use Ibexa\Contracts\Core\Repository\Values\ContentType\Query\SortClause\Identifier;
14+
use Pagerfanta\Adapter\AdapterInterface;
15+
16+
final class ContentTypeListAdapter implements AdapterInterface
17+
{
18+
private ContentTypeService $contentTypeService;
19+
20+
private ContentTypeQuery $query;
21+
22+
/** @var list<string> */
23+
private array $languages;
24+
25+
/**
26+
* @param list<string> $languages
27+
*/
28+
public function __construct(
29+
ContentTypeService $contentTypeService,
30+
array $languages,
31+
?ContentTypeQuery $query = null
32+
) {
33+
$this->contentTypeService = $contentTypeService;
34+
$this->languages = $languages;
35+
$this->query = $query ?? new ContentTypeQuery(null, [new Identifier()]);
36+
}
37+
38+
public function getNbResults(): int
39+
{
40+
$query = clone $this->query;
41+
$query->setLimit(0);
42+
43+
return $this->contentTypeService->findContentTypes($query, $this->languages)->getTotalCount();
44+
}
45+
46+
public function getSlice($offset, $length): iterable
47+
{
48+
$query = clone $this->query;
49+
$query->setOffset($offset);
50+
$query->setLimit($length);
51+
52+
return $this->contentTypeService->findContentTypes($query, $this->languages)->getIterator();
53+
}
54+
}

0 commit comments

Comments
 (0)