Skip to content

Commit

Permalink
Merge branch feature/explorers-refactor into develop
Browse files Browse the repository at this point in the history
  • Loading branch information
roadiz-ci committed Aug 28, 2024
1 parent 426cfed commit 57eddd0
Show file tree
Hide file tree
Showing 5 changed files with 49 additions and 18 deletions.
12 changes: 6 additions & 6 deletions src/Console/CustomFormAnswerPurgeCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -92,12 +92,12 @@ protected function purgeCustomFormAnswers(CustomForm $customForm, InputInterface
if (
!$input->getOption('dry-run') &&
(!$input->isInteractive() || $io->confirm(\sprintf(
'Are you sure you want to delete %d custom-form answer(s) and %d document(s) from “%s” before %s',
$count,
$documentsCount,
$customForm->getName(),
$purgeBefore->format('Y-m-d H:i')
), false))
'Are you sure you want to delete %d custom-form answer(s) and %d document(s) from “%s” before %s',
$count,
$documentsCount,
$customForm->getName(),
$purgeBefore->format('Y-m-d H:i')
), false))
) {
$this->managerRegistry
->getRepository(CustomFormAnswer::class)
Expand Down
20 changes: 10 additions & 10 deletions src/Explorer/AbstractDoctrineExplorerProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,18 +14,12 @@

abstract class AbstractDoctrineExplorerProvider extends AbstractExplorerProvider
{
protected ManagerRegistry $managerRegistry;
protected RequestStack $requestStack;
protected UrlGeneratorInterface $urlGenerator;

public function __construct(
ManagerRegistry $managerRegistry,
RequestStack $requestStack,
UrlGeneratorInterface $urlGenerator
protected ExplorerItemFactoryInterface $explorerItemFactory,
protected ManagerRegistry $managerRegistry,
protected RequestStack $requestStack,
protected UrlGeneratorInterface $urlGenerator
) {
$this->managerRegistry = $managerRegistry;
$this->requestStack = $requestStack;
$this->urlGenerator = $urlGenerator;
}

/**
Expand All @@ -47,6 +41,7 @@ abstract protected function getDefaultOrdering(): array;
* @param array $options
*
* @return EntityListManagerInterface
* @throws \ReflectionException
*/
protected function doFetchItems(array $options = []): EntityListManagerInterface
{
Expand Down Expand Up @@ -121,4 +116,9 @@ public function getItemsById(array $ids = []): array

return [];
}

public function toExplorerItem(mixed $item): ExplorerItemInterface
{
return $this->explorerItemFactory->createForEntity($item);
}
}
18 changes: 16 additions & 2 deletions src/Explorer/AbstractExplorerItem.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,26 @@

namespace RZ\Roadiz\CoreBundle\Explorer;

use RZ\Roadiz\Documents\Models\DocumentInterface;

abstract class AbstractExplorerItem implements ExplorerItemInterface
{
protected function getEditItemPath(): ?string
{
return null;
}

protected function getThumbnail(): ?array
protected function getThumbnail(): DocumentInterface|array|null
{
return null;
}

protected function isPublished(): bool
{
return true;
}

protected function getColor(): ?string
{
return null;
}
Expand All @@ -26,7 +38,9 @@ public function toArray(): array
'classname' => $this->getAlternativeDisplayable() ?? '',
'displayable' => $this->getDisplayable(),
'editItem' => $this->getEditItemPath(),
'thumbnail' => $this->getThumbnail()
'thumbnail' => $this->getThumbnail(),
'published' => $this->isPublished(),
'color' => $this->getColor(),
];
}
}
7 changes: 7 additions & 0 deletions src/Explorer/AbstractExplorerProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,15 @@
abstract class AbstractExplorerProvider implements ExplorerProviderInterface
{
protected array $options;

/**
* @deprecated
*/
protected ContainerInterface $container;

/**
* @deprecated
*/
public function setContainer(ContainerInterface $container): self
{
$this->container = $container;
Expand Down
10 changes: 10 additions & 0 deletions src/Explorer/ExplorerItemFactoryInterface.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
<?php

declare(strict_types=1);

namespace RZ\Roadiz\CoreBundle\Explorer;

interface ExplorerItemFactoryInterface
{
public function createForEntity(mixed $entity, array $configuration = []): ExplorerItemInterface;
}

0 comments on commit 57eddd0

Please sign in to comment.