Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Upgrade Sonatablock and SonataSeo #1483

Merged
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
5 changes: 2 additions & 3 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -26,11 +26,11 @@
"doctrine/doctrine-bundle": "^2.5",
"doctrine/persistence": "^2.1",
"sonata-project/admin-bundle": "^3.99",
"sonata-project/block-bundle": "^3.20",
"sonata-project/block-bundle": "^4.11",
"sonata-project/doctrine-extensions": "^1.8",
"sonata-project/doctrine-orm-admin-bundle": "^3.19",
"sonata-project/form-extensions": "^1.4",
"sonata-project/seo-bundle": "^2.11",
"sonata-project/seo-bundle": "^3.0",
"sonata-project/twig-extensions": "^1.3",
"symfony-cmf/routing-bundle": "^2.1",
"symfony/config": "^4.4 || ^5.4",
Expand All @@ -45,7 +45,6 @@
"symfony/routing": "^4.4 || ^5.4",
"symfony/security-core": "^4.4",
"symfony/security-http": "^4.4",
"symfony/templating": "^4.4 || ^5.4",
"symfony/validator": "^4.4 || ^5.4",
"twig/string-extra": "^3.0",
"twig/twig": "^2.12.1 || ^3.0"
Expand Down
6 changes: 0 additions & 6 deletions phpstan-baseline.neon

This file was deleted.

1 change: 0 additions & 1 deletion phpstan.neon.dist
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
includes:
- phpstan-baseline.neon
- vendor/phpstan/phpstan/conf/bleedingEdge.neon

parameters:
Expand Down
7 changes: 1 addition & 6 deletions src/Admin/BaseBlockAdmin.php
Original file line number Diff line number Diff line change
Expand Up @@ -229,12 +229,7 @@ private function loadBlockDefaults(PageBlockInterface $block): PageBlockInterfac

$resolver = new OptionsResolver();
// use new interface method whenever possible
// NEXT_MAJOR: Remove this check and legacy setDefaultSettings method call
if (method_exists($service, 'configureSettings')) {
$service->configureSettings($resolver);
} else {
$service->setDefaultSettings($resolver);
}
$service->configureSettings($resolver);

try {
$block->setSettings($resolver->resolve($block->getSettings()));
Expand Down
10 changes: 2 additions & 8 deletions src/Admin/BlockAdmin.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
use Doctrine\ORM\EntityRepository;
use Sonata\AdminBundle\Form\FormMapper;
use Sonata\AdminBundle\Route\RouteCollection;
use Sonata\BlockBundle\Block\BlockServiceInterface;
use Sonata\BlockBundle\Block\Service\BlockServiceInterface;
use Sonata\BlockBundle\Block\Service\EditableBlockService;
use Sonata\BlockBundle\Form\Type\ServiceListType;
use Sonata\BlockBundle\Model\BlockInterface;
Expand Down Expand Up @@ -190,13 +190,7 @@ protected function configureFormFields(FormMapper $form): void
private function getDefaultTemplate(BlockServiceInterface $blockService)
{
$resolver = new OptionsResolver();
// use new interface method whenever possible
// NEXT_MAJOR: Remove this check and legacy setDefaultSettings method call
if (method_exists($blockService, 'configureSettings')) {
$blockService->configureSettings($resolver);
} else {
$blockService->setDefaultSettings($resolver);
}
$blockService->configureSettings($resolver);
$options = $resolver->resolve();

return $options['template'] ?? null;
Expand Down
46 changes: 25 additions & 21 deletions src/Block/BlockContextManager.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,34 +13,38 @@

namespace Sonata\PageBundle\Block;

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

/**
* NEXT_MAJOR: Do not extend from `BlockContextManager` since it will be final.
*
* @psalm-suppress InvalidExtendClass
* @phpstan-ignore-next-line
*/
final class BlockContextManager extends BaseBlockContextManager
final class BlockContextManager implements BlockContextManagerInterface
{
protected function configureSettings(OptionsResolver $optionsResolver, BlockInterface $block): void
private BlockContextManagerInterface $blockContextManager;

public function __construct(BlockContextManagerInterface $blockContextManager)
{
$this->blockContextManager = $blockContextManager;
}

public function addSettingsByType(string $type, array $settings, bool $replace = false): void
{
parent::configureSettings($optionsResolver, $block);
$this->blockContextManager->addSettingsByType($type, $settings, $replace);
}

$optionsResolver->setDefaults([
public function addSettingsByClass(string $class, array $settings, bool $replace = false): void
{
$this->blockContextManager->addSettingsByClass($class, $settings, $replace);
}

public function get($meta, array $settings = []): BlockContextInterface
{
return $this->blockContextManager->get($meta, [
'manager' => false,
'page_id' => false,
]);
}

$optionsResolver
->addAllowedTypes('manager', ['string', 'bool'])
->addAllowedTypes('page_id', ['int', 'string', 'bool']);

$optionsResolver->setRequired([
'manager',
'page_id',
]);
public function exists(string $type): bool
{
return $this->blockContextManager->exists($type);
}
}
48 changes: 24 additions & 24 deletions src/Block/BreadcrumbBlockService.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,54 +15,51 @@

use Knp\Menu\FactoryInterface;
use Knp\Menu\ItemInterface;
use Knp\Menu\Provider\MenuProviderInterface;
use Sonata\BlockBundle\Block\BlockContextInterface;
use Sonata\BlockBundle\Meta\Metadata;
use Sonata\BlockBundle\Meta\MetadataInterface;
use Sonata\PageBundle\CmsManager\CmsManagerSelectorInterface;
use Sonata\PageBundle\Model\PageInterface;
use Sonata\SeoBundle\Block\Breadcrumb\BaseBreadcrumbMenuBlockService;
use Symfony\Bundle\FrameworkBundle\Templating\EngineInterface;
use Twig\Environment;

/**
* BlockService for homepage breadcrumb.
*
* @author Sylvain Deloux <[email protected]>
*/
final class BreadcrumbBlockService extends BaseBreadcrumbMenuBlockService
{
/**
* @var CmsManagerSelectorInterface
*/
protected $cmsSelector;
private $cmsSelector;

/**
* @param string $context
* @param string $name
*/
public function __construct($context, $name, EngineInterface $templating, MenuProviderInterface $menuProvider, FactoryInterface $factory, CmsManagerSelectorInterface $cmsSelector)
{
$this->cmsSelector = $cmsSelector;
public function __construct(
Environment $twig,
FactoryInterface $factory,
CmsManagerSelectorInterface $cmsSelector
) {
parent::__construct($twig, $factory);

parent::__construct($context, $name, $templating, $menuProvider, $factory);
$this->cmsSelector = $cmsSelector;
}

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

public function getBlockMetadata($code = null)
public function handleContext(string $context): bool
{
return new Metadata($this->getName(), (null !== $code ? $code : $this->getName()), false, 'SonataPageBundle', [
'class' => 'fa fa-bars',
]);
return $this->getName() === $context;
}

protected function getMenu(BlockContextInterface $blockContext)
protected function getMenu(BlockContextInterface $blockContext): ItemInterface
{
$blockContext->setSetting('include_homepage_link', false);

$menu = $this->getRootMenu($blockContext);
$menu = parent::getMenu($blockContext);

$page = $this->getCurrentPage();

Expand All @@ -87,12 +84,15 @@ protected function getMenu(BlockContextInterface $blockContext)
return $menu;
}

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

/**
* Return the current Page.
*
* @return PageInterface|null
*/
protected function getCurrentPage()
private function getCurrentPage()
{
$cms = $this->cmsSelector->retrieve();

Expand Down
47 changes: 37 additions & 10 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,21 +40,31 @@
*
* @author Thomas Rabaix <[email protected]>
*/
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)
public function execute(BlockContextInterface $blockContext, ?Response $response = null): Response
{
$settings = $blockContext->getSettings();

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
Loading