Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 0 additions & 18 deletions phpstan-baseline.neon
Original file line number Diff line number Diff line change
Expand Up @@ -8088,24 +8088,6 @@ parameters:
count: 1
path: src/lib/Tab/TabGroup.php

-
message: '#^Method Ibexa\\AdminUi\\Tab\\URLManagement\\LinkManagerTab\:\:evaluate\(\) has parameter \$parameters with no value type specified in iterable type array\.$#'
identifier: missingType.iterableValue
count: 1
path: src/lib/Tab/URLManagement/LinkManagerTab.php

-
message: '#^Property Ibexa\\AdminUi\\Tab\\URLManagement\\LinkManagerTab\:\:\$notificationHandler is never read, only written\.$#'
identifier: property.onlyWritten
count: 1
path: src/lib/Tab/URLManagement/LinkManagerTab.php

-
message: '#^Property Ibexa\\AdminUi\\Tab\\URLManagement\\LinkManagerTab\:\:\$submitHandler is never read, only written\.$#'
identifier: property.onlyWritten
count: 1
path: src/lib/Tab/URLManagement/LinkManagerTab.php

-
message: '#^Cannot access property \$query on Symfony\\Component\\HttpFoundation\\Request\|null\.$#'
identifier: property.nonObject
Expand Down
42 changes: 6 additions & 36 deletions src/bundle/Controller/LinkManagerController.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,40 +25,17 @@

final class LinkManagerController extends Controller
{
public const DEFAULT_MAX_PER_PAGE = 10;
public const int DEFAULT_MAX_PER_PAGE = 10;

private URLService $urlService;

private FormFactory $formFactory;

private SubmitHandler $submitHandler;

private TranslatableNotificationHandlerInterface $notificationHandler;

/**
* @param \Ibexa\Contracts\Core\Repository\URLService $urlService
* @param \Ibexa\AdminUi\Form\Factory\FormFactory $formFactory
* @param \Ibexa\AdminUi\Form\SubmitHandler $submitHandler
* @param \Ibexa\Contracts\AdminUi\Notification\TranslatableNotificationHandlerInterface $notificationHandler
*/
public function __construct(
URLService $urlService,
FormFactory $formFactory,
SubmitHandler $submitHandler,
TranslatableNotificationHandlerInterface $notificationHandler
private readonly URLService $urlService,
private readonly FormFactory $formFactory,
private readonly SubmitHandler $submitHandler,
private readonly TranslatableNotificationHandlerInterface $notificationHandler
) {
$this->urlService = $urlService;
$this->formFactory = $formFactory;
$this->submitHandler = $submitHandler;
$this->notificationHandler = $notificationHandler;
}

/**
* @param \Symfony\Component\HttpFoundation\Request $request
* @param int $urlId
*
* @return \Symfony\Component\HttpFoundation\Response
*
* @throws \Ibexa\Contracts\Core\Repository\Exceptions\NotFoundException
* @throws \Ibexa\Contracts\Core\Repository\Exceptions\UnauthorizedException
*/
Expand Down Expand Up @@ -107,11 +84,6 @@ public function editAction(Request $request, int $urlId): Response
}

/**
* @param \Symfony\Component\HttpFoundation\Request $request
* @param int $urlId
*
* @return \Symfony\Component\HttpFoundation\Response
*
* @throws \Ibexa\Contracts\Core\Repository\Exceptions\NotFoundException
* @throws \Ibexa\Contracts\Core\Repository\Exceptions\UnauthorizedException
*/
Expand All @@ -123,9 +95,7 @@ public function viewAction(Request $request, int $urlId): Response
$usages->setCurrentPage($request->query->getInt('page', 1));
$usages->setMaxPerPage($request->query->getInt('limit', self::DEFAULT_MAX_PER_PAGE));

$editForm = $this->formFactory->contentEdit(
new ContentEditData()
);
$editForm = $this->formFactory->contentEdit(new ContentEditData());

return $this->render('@ibexadesign/link_manager/view.html.twig', [
'url' => $url,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@
{{ form_label(form.status) }}
{{ form_widget(form.status) }}
</div>
{{ form_widget(form.page, { attr: { value: '1' }}) }}
{{ form_end(form) }}
</section>

Expand Down Expand Up @@ -81,8 +80,7 @@

{% if urls.haveToPaginate %}
{% include '@ibexadesign/ui/pagination.html.twig' with {
'pager': urls,
'paginaton_params' : {'pageParameter': '[search_data][page]'}
'pager': urls
} %}
{% endif %}
</section>
Expand Down
20 changes: 10 additions & 10 deletions src/lib/Form/Data/URL/URLListData.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,17 +10,17 @@

use Ibexa\Contracts\Core\Repository\Values\ValueObject;

class URLListData extends ValueObject
final class URLListData extends ValueObject
{
/** @var string|null */
public $searchQuery;
public ?string $searchQuery;

/** @var bool|null */
public $status;
public ?bool $status;

/** @var int */
public $page = 1;

/** @var int */
public $limit = 10;
public function __construct(
?string $searchQuery = null,
?bool $status = null,
) {
$this->searchQuery = $searchQuery;
$this->status = $status;
}
}
5 changes: 2 additions & 3 deletions src/lib/Form/Data/URL/URLUpdateData.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,7 @@

use Ibexa\Contracts\Core\Repository\Values\URL\URLUpdateStruct;

class URLUpdateData extends URLUpdateStruct
final class URLUpdateData extends URLUpdateStruct
{
/** @var int */
public $id;
public int $id;
}
32 changes: 3 additions & 29 deletions src/lib/Form/Type/URL/URLListType.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,39 +4,25 @@
* @copyright Copyright (C) Ibexa AS. All rights reserved.
* @license For full copyright and license information view LICENSE file distributed with this source code.
*/
declare(strict_types=1);

namespace Ibexa\AdminUi\Form\Type\URL;

use Ibexa\AdminUi\Form\Data\URL\URLListData;
use JMS\TranslationBundle\Annotation\Desc;
use Symfony\Component\Form\AbstractType;
use Symfony\Component\Form\Extension\Core\Type\ChoiceType;
use Symfony\Component\Form\Extension\Core\Type\HiddenType;
use Symfony\Component\Form\Extension\Core\Type\SearchType;
use Symfony\Component\Form\FormBuilderInterface;
use Symfony\Component\OptionsResolver\OptionsResolver;
use Symfony\Contracts\Translation\TranslatorInterface;

/**
* URL list form.
*/
class URLListType extends AbstractType
final class URLListType extends AbstractType
{
private TranslatorInterface $translator;

/**
* URLListType constructor.
*
* @param \Symfony\Contracts\Translation\TranslatorInterface $translator
*/
public function __construct(TranslatorInterface $translator)
public function __construct(private readonly TranslatorInterface $translator)
{
$this->translator = $translator;
}

/**
* {@inheritdoc}
*/
public function buildForm(FormBuilderInterface $builder, array $options): void
{
$builder->add('status', ChoiceType::class, [
Expand Down Expand Up @@ -65,14 +51,8 @@ public function buildForm(FormBuilderInterface $builder, array $options): void
$builder->add('searchQuery', SearchType::class, [
'required' => false,
]);

$builder->add('limit', HiddenType::class);
$builder->add('page', HiddenType::class);
}

/**
* {@inheritdoc}
*/
public function configureOptions(OptionsResolver $resolver): void
{
$resolver->setDefaults([
Expand All @@ -81,17 +61,11 @@ public function configureOptions(OptionsResolver $resolver): void
]);
}

/**
* {@inheritdoc}
*/
public function getName(): string
{
return $this->getBlockPrefix();
}

/**
* {@inheritdoc}
*/
public function getBlockPrefix(): string
{
return 'ezplatform_content_forms_url_list';
Expand Down
21 changes: 6 additions & 15 deletions src/lib/Pagination/Pagerfanta/URLSearchAdapter.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
* @copyright Copyright (C) Ibexa AS. All rights reserved.
* @license For full copyright and license information view LICENSE file distributed with this source code.
*/
declare(strict_types=1);

namespace Ibexa\AdminUi\Pagination\Pagerfanta;

Expand All @@ -14,22 +15,12 @@
/**
* @implements \Pagerfanta\Adapter\AdapterInterface<\Ibexa\Contracts\Core\Repository\Values\URL\URL>
*/
class URLSearchAdapter implements AdapterInterface
final readonly class URLSearchAdapter implements AdapterInterface
{
private URLQuery $query;

private URLService $urlService;

/**
* UrlSearchAdapter constructor.
*
* @param \Ibexa\Contracts\Core\Repository\Values\URL\URLQuery $query
* @param \Ibexa\Contracts\Core\Repository\URLService $urlService
*/
public function __construct(URLQuery $query, URLService $urlService)
{
$this->query = $query;
$this->urlService = $urlService;
public function __construct(
private URLQuery $query,
private URLService $urlService
) {
}

/**
Expand Down
67 changes: 21 additions & 46 deletions src/lib/Tab/URLManagement/LinkManagerTab.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,7 @@

use Ibexa\AdminUi\Form\Data\URL\URLListData;
use Ibexa\AdminUi\Form\Factory\FormFactory;
use Ibexa\AdminUi\Form\SubmitHandler;
use Ibexa\AdminUi\Pagination\Pagerfanta\URLSearchAdapter;
use Ibexa\Contracts\AdminUi\Notification\TranslatableNotificationHandlerInterface;
use Ibexa\Contracts\AdminUi\Tab\AbstractTab;
use Ibexa\Contracts\AdminUi\Tab\ConditionalTabInterface;
use Ibexa\Contracts\AdminUi\Tab\OrderedTabInterface;
Expand All @@ -31,39 +29,18 @@

class LinkManagerTab extends AbstractTab implements OrderedTabInterface, ConditionalTabInterface
{
public const URI_FRAGMENT = 'ibexa-tab-link-manager-link-manager';
private const DEFAULT_MAX_PER_PAGE = 10;

private URLService $urlService;

private FormFactory $formFactory;

private SubmitHandler $submitHandler;

private TranslatableNotificationHandlerInterface $notificationHandler;

private RequestStack $requestStack;

private PermissionResolver $permissionResolver;
public const string URI_FRAGMENT = 'ibexa-tab-link-manager-link-manager';
private const int DEFAULT_MAX_PER_PAGE = 10;

public function __construct(
Environment $twig,
TranslatorInterface $translator,
URLService $urlService,
FormFactory $formFactory,
SubmitHandler $submitHandler,
TranslatableNotificationHandlerInterface $notificationHandler,
RequestStack $request,
PermissionResolver $permissionResolver
private readonly URLService $urlService,
private readonly FormFactory $formFactory,
private readonly RequestStack $requestStack,
private readonly PermissionResolver $permissionResolver
) {
parent::__construct($twig, $translator);

$this->urlService = $urlService;
$this->formFactory = $formFactory;
$this->submitHandler = $submitHandler;
$this->notificationHandler = $notificationHandler;
$this->requestStack = $request;
$this->permissionResolver = $permissionResolver;
}

public function getIdentifier(): string
Expand All @@ -83,9 +60,7 @@ public function getOrder(): int
}

/**
* @param array $parameters
*
* @return bool
* @param array<string, mixed> $parameters
*
* @throws \Ibexa\Contracts\Core\Repository\Exceptions\InvalidArgumentException
*/
Expand All @@ -103,19 +78,26 @@ public function renderView(array $parameters): string
'csrf_protection' => false,
]);

$form->handleRequest($this->requestStack->getCurrentRequest());
$request = $this->requestStack->getCurrentRequest();
$form->handleRequest($request);

if ($form->isSubmitted() && !$form->isValid()) {
throw new BadRequestHttpException();
}

$urls = new Pagerfanta(new URLSearchAdapter(
$this->buildListQuery($data),
$this->urlService
));
$urls = new Pagerfanta(
new URLSearchAdapter(
$this->buildListQuery($data),
$this->urlService
)
);

$page = $request !== null
? $request->query->getInt('page', 1)
: 1;

$urls->setCurrentPage($data->page);
$urls->setMaxPerPage($data->limit ? $data->limit : self::DEFAULT_MAX_PER_PAGE);
$urls->setCurrentPage($page);
$urls->setMaxPerPage(self::DEFAULT_MAX_PER_PAGE);

return $this->twig->render('@ibexadesign/link_manager/list.html.twig', [
'form' => $form->createView(),
Expand All @@ -124,13 +106,6 @@ public function renderView(array $parameters): string
]);
}

/**
* Builds URL criteria from list data.
*
* @param \Ibexa\AdminUi\Form\Data\URL\URLListData $data
*
* @return \Ibexa\Contracts\Core\Repository\Values\URL\URLQuery
*/
private function buildListQuery(URLListData $data): URLQuery
{
$query = new URLQuery();
Expand Down
Loading