Skip to content

Commit

Permalink
revert
Browse files Browse the repository at this point in the history
  • Loading branch information
jordisala1991 committed Jul 22, 2022
1 parent 0f2d03d commit f561bf5
Show file tree
Hide file tree
Showing 8 changed files with 106 additions and 114 deletions.
6 changes: 3 additions & 3 deletions src/Admin/BlockAdmin.php
Original file line number Diff line number Diff line change
Expand Up @@ -148,9 +148,9 @@ protected function configureFormFields(FormMapper $form): void
return $repository->createQueryBuilder('a')
->andWhere('a.page = :page AND a.type IN (:types)')
->setParameters([
'page' => $page,
'types' => $containerBlockTypes,
]);
'page' => $page,
'types' => $containerBlockTypes,
]);
},
], [
'admin_code' => $this->getCode(),
Expand Down
14 changes: 2 additions & 12 deletions src/Block/BlockContextManager.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,25 +14,15 @@
namespace Sonata\PageBundle\Block;

use Sonata\BlockBundle\Block\BlockContextInterface;
use Sonata\BlockBundle\Block\BlockContextManager as BaseBlockContextManager;
use Sonata\BlockBundle\Block\BlockContextManagerInterface;
use Symfony\Component\OptionsResolver\OptionsResolver;

final class BlockContextManager implements BlockContextManagerInterface
{
private BaseBlockContextManager $blockContextManager;
private BlockContextManagerInterface $blockContextManager;

private OptionsResolver $optionsResolver;

public function __construct(BaseBlockContextManager $blockContextManager)
public function __construct(BlockContextManagerInterface $blockContextManager)
{
$this->blockContextManager = $blockContextManager;
$this->optionsResolver = new OptionsResolver();
}

public function getOptionsResolver(): OptionsResolver
{
return $this->optionsResolver;
}

public function addSettingsByType(string $type, array $settings, bool $replace = false): void
Expand Down
25 changes: 12 additions & 13 deletions src/Block/BreadcrumbBlockService.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,6 @@
use Twig\Environment;

/**
* BlockService for homepage breadcrumb.
*
* @author Sylvain Deloux <sylvain.deloux@ekino.com>
*/
final class BreadcrumbBlockService extends BaseBreadcrumbMenuBlockService
Expand All @@ -35,21 +33,19 @@ final class BreadcrumbBlockService extends BaseBreadcrumbMenuBlockService
*/
private $cmsSelector;

public function __construct(Environment $twig, FactoryInterface $factory, CmsManagerSelectorInterface $cmsSelector)
{
public function __construct(
Environment $twig,
FactoryInterface $factory,
CmsManagerSelectorInterface $cmsSelector
) {
parent::__construct($twig, $factory);

$this->cmsSelector = $cmsSelector;
}

public function getName()
{
return 'sonata.page.block.breadcrumb';
}

public function getMetadata($code = null): MetadataInterface
public function getMetadata(): MetadataInterface
{
return new Metadata($this->getName(), $code ?? $this->getName(), null, 'SonataPageBundle', [
return new Metadata($this->getName(), null, null, 'SonataPageBundle', [
'class' => 'fa fa-bars',
]);
}
Expand Down Expand Up @@ -88,9 +84,12 @@ protected function getMenu(BlockContextInterface $blockContext): ItemInterface
return $menu;
}

private function getName()
{
return 'sonata.page.block.breadcrumb';
}

/**
* Return the current Page.
*
* @return PageInterface|null
*/
private function getCurrentPage()
Expand Down
45 changes: 36 additions & 9 deletions src/Block/ChildrenPagesBlockService.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,15 +13,21 @@

namespace Sonata\PageBundle\Block;

use Sonata\AdminBundle\Form\FormMapper;
use Sonata\AdminBundle\Admin\AdminInterface;
use Sonata\BlockBundle\Block\BlockContextInterface;
use Sonata\BlockBundle\Block\Service\AbstractBlockService;
use Sonata\BlockBundle\Block\Service\EditableBlockService;
use Sonata\BlockBundle\Form\Mapper\FormMapper;
use Sonata\BlockBundle\Meta\Metadata;
use Sonata\BlockBundle\Meta\MetadataInterface;
use Sonata\BlockBundle\Model\BlockInterface;
use Sonata\Form\Type\ImmutableArrayType;
use Sonata\Form\Validator\ErrorElement;
use Sonata\PageBundle\CmsManager\CmsManagerSelectorInterface;
use Sonata\PageBundle\Exception\PageNotFoundException;
use Sonata\PageBundle\Form\Type\PageSelectorType;
use Sonata\PageBundle\Model\PageBlockInterface;
use Sonata\PageBundle\Model\PageInterface;
use Sonata\PageBundle\Site\SiteSelectorInterface;
use Symfony\Component\Form\Extension\Core\Type\CheckboxType;
use Symfony\Component\Form\Extension\Core\Type\TextType;
Expand All @@ -34,18 +40,28 @@
*
* @author Thomas Rabaix <thomas.rabaix@sonata-project.org>
*/
final class ChildrenPagesBlockService extends AbstractBlockService
final class ChildrenPagesBlockService extends AbstractBlockService implements EditableBlockService
{
private SiteSelectorInterface $siteSelector;

private CmsManagerSelectorInterface $cmsManagerSelector;

public function __construct(Environment $twig, SiteSelectorInterface $siteSelector, CmsManagerSelectorInterface $cmsManagerSelector)
{
/**
* @var AdminInterface<PageInterface>
*/
private AdminInterface $pageAdmin;

public function __construct(
Environment $twig,
SiteSelectorInterface $siteSelector,
CmsManagerSelectorInterface $cmsManagerSelector,
AdminInterface $pageAdmin
) {
parent::__construct($twig);

$this->siteSelector = $siteSelector;
$this->cmsManagerSelector = $cmsManagerSelector;
$this->pageAdmin = $pageAdmin;
}

public function execute(BlockContextInterface $blockContext, ?Response $response = null): Response
Expand Down Expand Up @@ -76,7 +92,14 @@ public function execute(BlockContextInterface $blockContext, ?Response $response
], $response);
}

public function buildEditForm(FormMapper $form, BlockInterface $block): void
public function getMetadata(): MetadataInterface
{
return new Metadata('Children Page (core)', null, null, 'SonataPageBundle', [
'class' => 'fa fa-home',
]);
}

public function configureEditForm(FormMapper $form, BlockInterface $block): void
{
if (!$block instanceof PageBlockInterface) {
return;
Expand All @@ -101,8 +124,8 @@ public function buildEditForm(FormMapper $form, BlockInterface $block): void
'label' => 'form.label_current',
]],
['pageId', PageSelectorType::class, [
'model_manager' => $form->getAdmin()->getModelManager(),
'class' => $form->getAdmin()->getClass(),
'model_manager' => $this->pageAdmin->getModelManager(),
'class' => $this->pageAdmin->getClass(),
'site' => $block->getPage()->getSite(),
'required' => false,
'label' => 'form.label_page',
Expand All @@ -116,9 +139,13 @@ public function buildEditForm(FormMapper $form, BlockInterface $block): void
]);
}

public function getName(): string
public function configureCreateForm(FormMapper $form, BlockInterface $block): void
{
$this->configureEditForm($form, $block);
}

public function validate(ErrorElement $errorElement, BlockInterface $block): void
{
return 'Children Page (core)';
}

public function configureSettings(OptionsResolver $resolver): void
Expand Down
17 changes: 2 additions & 15 deletions src/Block/ContainerBlockService.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,11 +24,8 @@
use Sonata\Form\Validator\ErrorElement;
use Symfony\Component\HttpFoundation\Response;
use Symfony\Component\OptionsResolver\OptionsResolver;
use Twig\Environment;

/**
* Render children pages.
*
* @author Thomas Rabaix <thomas.rabaix@sonata-project.org>
*/
final class ContainerBlockService implements BlockServiceInterface, EditableBlockService
Expand All @@ -40,16 +37,6 @@ public function __construct(BaseContainerBlockService $containerBlockService)
$this->containerBlockService = $containerBlockService;
}

public function getName(): string
{
return 'sonata.page.block.container';
}

public function getTwig(): Environment
{
return $this->containerBlockService->getTwig();
}

public function execute(BlockContextInterface $blockContext, ?Response $response = null): Response
{
return $this->containerBlockService->execute($blockContext, $response);
Expand Down Expand Up @@ -80,9 +67,9 @@ public function validate(ErrorElement $errorElement, BlockInterface $block): voi
$this->containerBlockService->validate($errorElement, $block);
}

public function getMetadata($code = null): MetadataInterface
public function getMetadata(): MetadataInterface
{
return new Metadata($this->getName(), $code ?? $this->getName(), null, 'SonataPageBundle', [
return new Metadata('sonata.page.block.container', null, null, 'SonataPageBundle', [
'class' => 'fa fa-square-o',
]);
}
Expand Down
76 changes: 34 additions & 42 deletions src/Block/PageListBlockService.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@

namespace Sonata\PageBundle\Block;

use Sonata\AdminBundle\Form\FormMapper as AdminFormMapper;
use Sonata\BlockBundle\Block\BlockContextInterface;
use Sonata\BlockBundle\Block\Service\AbstractBlockService;
use Sonata\BlockBundle\Block\Service\EditableBlockService;
Expand All @@ -35,50 +34,15 @@ final class PageListBlockService extends AbstractBlockService implements Editabl
{
private PageManagerInterface $pageManager;

public function __construct(Environment $twig, PageManagerInterface $pageManager)
{
public function __construct(
Environment $twig,
PageManagerInterface $pageManager
) {
parent::__construct($twig);

$this->pageManager = $pageManager;
}

public function getName(): string
{
return 'sonata.page.block.pagelist';
}

public function buildEditForm(AdminFormMapper $form, BlockInterface $block): void
{
$form->add('settings', ImmutableArrayType::class, [
'keys' => [
['title', TextType::class, [
'label' => 'form.label_title',
'required' => false,
]],
['translation_domain', TextType::class, [
'label' => 'form.label_translation_domain',
'required' => false,
]],
['icon', TextType::class, [
'label' => 'form.label_icon',
'required' => false,
]],
['class', TextType::class, [
'label' => 'form.label_class',
'required' => false,
]],
['mode', ChoiceType::class, [
'label' => 'form.label_mode',
'choices' => [
'public' => 'form.choice_public',
'admin' => 'form.choice_admin',
],
]],
],
'translation_domain' => 'SonataPageBundle',
]);
}

public function execute(BlockContextInterface $blockContext, ?Response $response = null): Response
{
$pageList = $this->pageManager->findBy([
Expand Down Expand Up @@ -111,15 +75,43 @@ public function configureSettings(OptionsResolver $resolver): void
]);
}

public function getMetadata($code = null): MetadataInterface
public function getMetadata(): MetadataInterface
{
return new Metadata($this->getName(), $code ?? $this->getName(), null, 'SonataPageBundle', [
return new Metadata('sonata.page.block.pagelist', null, null, 'SonataPageBundle', [
'class' => 'fa fa-home',
]);
}

public function configureEditForm(FormMapper $form, BlockInterface $block): void
{
$form->add('settings', ImmutableArrayType::class, [
'keys' => [
['title', TextType::class, [
'label' => 'form.label_title',
'required' => false,
]],
['translation_domain', TextType::class, [
'label' => 'form.label_translation_domain',
'required' => false,
]],
['icon', TextType::class, [
'label' => 'form.label_icon',
'required' => false,
]],
['class', TextType::class, [
'label' => 'form.label_class',
'required' => false,
]],
['mode', ChoiceType::class, [
'label' => 'form.label_mode',
'choices' => [
'public' => 'form.choice_public',
'admin' => 'form.choice_admin',
],
]],
],
'translation_domain' => 'SonataPageBundle',
]);
}

public function configureCreateForm(FormMapper $form, BlockInterface $block): void
Expand Down
Loading

0 comments on commit f561bf5

Please sign in to comment.