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

Poc to reuse MenuBlock #1612

Merged
merged 6 commits into from
Sep 28, 2022
Merged
Show file tree
Hide file tree
Changes from 5 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
4 changes: 2 additions & 2 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 || ^3.0",
"sonata-project/admin-bundle": "^4.19",
"sonata-project/block-bundle": "^4.16.2",
"sonata-project/block-bundle": "^4.18",
"sonata-project/doctrine-extensions": "^1.18 || ^2.1",
"sonata-project/doctrine-orm-admin-bundle": "^4.0",
"sonata-project/form-extensions": "^1.4",
"sonata-project/seo-bundle": "^3.3",
"sonata-project/seo-bundle": "^3.4",
"sonata-project/twig-extensions": "^1.3 || ^2.0",
"symfony-cmf/routing-bundle": "^2.1 || ^3.0",
"symfony/config": "^4.4 || ^5.4 || ^6.0",
Expand Down
27 changes: 18 additions & 9 deletions src/Block/BreadcrumbBlockService.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,36 +16,38 @@
use Knp\Menu\FactoryInterface;
use Knp\Menu\ItemInterface;
use Sonata\BlockBundle\Block\BlockContextInterface;
use Sonata\BlockBundle\Block\Service\BlockServiceInterface;
use Sonata\BlockBundle\Block\Service\EditableBlockService;
use Sonata\BlockBundle\Meta\Metadata;
use Sonata\BlockBundle\Meta\MetadataInterface;
use Sonata\BlockBundle\Model\BlockInterface;
use Sonata\Form\Validator\ErrorElement;
use Sonata\PageBundle\CmsManager\CmsManagerSelectorInterface;
use Sonata\PageBundle\Model\PageInterface;
use Sonata\SeoBundle\Block\Breadcrumb\BaseBreadcrumbMenuBlockService;
use Symfony\Component\OptionsResolver\OptionsResolver;
use Twig\Environment;

/**
* @author Sylvain Deloux <sylvain.deloux@ekino.com>
*/
final class BreadcrumbBlockService extends BaseBreadcrumbMenuBlockService
final class BreadcrumbBlockService extends BaseBreadcrumbMenuBlockService implements EditableBlockService
{
private CmsManagerSelectorInterface $cmsSelector;

/**
* @param BlockServiceInterface&EditableBlockService $menuBlock
*/
public function __construct(
Environment $twig,
object $menuBlock,
FactoryInterface $factory,
CmsManagerSelectorInterface $cmsSelector
) {
parent::__construct($twig, $menuBlock, $factory);
parent::__construct($twig, $factory);

$this->cmsSelector = $cmsSelector;
}

public function validate(ErrorElement $errorElement, BlockInterface $block): void
{
}

public function getMetadata(): MetadataInterface
{
return new Metadata('sonata.page.block.breadcrumb', null, null, 'SonataPageBundle', [
Expand All @@ -58,10 +60,17 @@ public function handleContext(string $context): bool
return 'page' === $context;
}

protected function getMenu(BlockContextInterface $blockContext): ItemInterface
public function configureSettings(OptionsResolver $resolver): void
{
$blockContext->setSetting('include_homepage_link', false);
parent::configureSettings($resolver);

$resolver->setDefaults([
'include_homepage_link' => false,
]);
}

protected function getMenu(BlockContextInterface $blockContext): ItemInterface
{
$menu = parent::getMenu($blockContext);

$page = $this->getCurrentPage();
Expand Down
6 changes: 6 additions & 0 deletions src/Block/ChildrenPagesBlockService.php
Original file line number Diff line number Diff line change
Expand Up @@ -123,23 +123,28 @@ public function configureEditForm(FormMapper $form, BlockInterface $block): void
['title', TextType::class, [
'required' => false,
'label' => 'form.label_title',
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

is this line one space off?

'translation_domain' => 'SonataPageBundle',
]],
['translation_domain', TextType::class, [
'label' => 'form.label_translation_domain',
'translation_domain' => 'SonataPageBundle',
'required' => false,
]],
['icon', TextType::class, [
'label' => 'form.label_icon',
'translation_domain' => 'SonataPageBundle',
'required' => false,
]],
['current', CheckboxType::class, [
'required' => false,
'label' => 'form.label_current',
'translation_domain' => 'SonataPageBundle',
]],
$this->getPageSelectorBuilder($form, $block),
['class', TextType::class, [
'required' => false,
'label' => 'form.label_class',
'translation_domain' => 'SonataPageBundle',
]],
],
'translation_domain' => 'SonataPageBundle',
Expand Down Expand Up @@ -190,6 +195,7 @@ private function getPageSelectorBuilder(AdminFormMapper $form, PageBlockInterfac
'site' => null !== $page ? $page->getSite() : null,
'required' => false,
'label' => 'form.label_page',
'translation_domain' => 'SonataPageBundle',
]);
$formBuilder->addModelTransformer(new CallbackTransformer(
static fn (?PageInterface $value): ?PageInterface => $value,
Expand Down
4 changes: 4 additions & 0 deletions src/Block/ContainerBlockService.php
Original file line number Diff line number Diff line change
Expand Up @@ -51,16 +51,20 @@ public function configureEditForm(FormMapper $form, BlockInterface $block): void
['code', TextType::class, [
'required' => false,
'label' => 'form.label_code',
'translation_domain' => 'SonataPageBundle',
]],
['layout', TextareaType::class, [
'label' => 'form.label_layout',
'translation_domain' => 'SonataPageBundle',
]],
['class', TextType::class, [
'required' => false,
'label' => 'form.label_class',
'translation_domain' => 'SonataPageBundle',
]],
['template', ContainerTemplateType::class, [
'label' => 'form.label_template_code',
'translation_domain' => 'SonataPageBundle',
]],
],
'translation_domain' => 'SonataPageBundle',
Expand Down
5 changes: 5 additions & 0 deletions src/Block/PageListBlockService.php
Original file line number Diff line number Diff line change
Expand Up @@ -91,22 +91,27 @@ public function configureEditForm(FormMapper $form, BlockInterface $block): void
'keys' => [
['title', TextType::class, [
'label' => 'form.label_title',
'translation_domain' => 'SonataPageBundle',
'required' => false,
]],
['translation_domain', TextType::class, [
'label' => 'form.label_translation_domain',
'translation_domain' => 'SonataPageBundle',
'required' => false,
]],
['icon', TextType::class, [
'label' => 'form.label_icon',
'translation_domain' => 'SonataPageBundle',
'required' => false,
]],
['class', TextType::class, [
'label' => 'form.label_class',
'translation_domain' => 'SonataPageBundle',
'required' => false,
]],
['mode', ChoiceType::class, [
'label' => 'form.label_mode',
'translation_domain' => 'SonataPageBundle',
'choices' => [
'public' => 'form.choice_public',
'admin' => 'form.choice_admin',
Expand Down
1 change: 1 addition & 0 deletions src/Block/SharedBlockBlockService.php
Original file line number Diff line number Diff line change
Expand Up @@ -150,6 +150,7 @@ private function getBlockBuilder(AdminFormMapper $form): FormBuilderInterface
'class' => $this->sharedBlockAdmin->getClass(),
'model_manager' => $this->sharedBlockAdmin->getModelManager(),
'label' => 'form.label_block',
'translation_domain' => 'SonataPageBundle',
]);
$formBuilder->addModelTransformer(new CallbackTransformer(
static fn (?PageBlockInterface $value): ?PageBlockInterface => $value,
Expand Down
1 change: 0 additions & 1 deletion src/Resources/config/block.php
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,6 @@
->tag('sonata.breadcrumb')
->args([
new ReferenceConfigurator('twig'),
new ReferenceConfigurator('sonata.block.service.menu'),
new ReferenceConfigurator('knp_menu.factory'),
new ReferenceConfigurator('sonata.page.cms_manager_selector'),
])
Expand Down
32 changes: 0 additions & 32 deletions src/Resources/translations/SonataPageBundle.bg.xliff
Original file line number Diff line number Diff line change
Expand Up @@ -847,38 +847,6 @@
<source>form.label_text</source>
<target>form.label_text</target>
</trans-unit>
<trans-unit id="form.label_menu_name">
<source>form.label_menu_name</source>
<target>form.label_menu_name</target>
</trans-unit>
<trans-unit id="form.label_safe_labels">
<source>form.label_safe_labels</source>
<target>form.label_safe_labels</target>
</trans-unit>
<trans-unit id="form.label_current_class">
<source>form.label_current_class</source>
<target>form.label_current_class</target>
</trans-unit>
<trans-unit id="form.label_first_class">
<source>form.label_first_class</source>
<target>form.label_first_class</target>
</trans-unit>
<trans-unit id="form.label_last_class">
<source>form.label_last_class</source>
<target>form.label_last_class</target>
</trans-unit>
<trans-unit id="form.label_menu_class">
<source>form.label_menu_class</source>
<target>form.label_menu_class</target>
</trans-unit>
<trans-unit id="form.label_children_class">
<source>form.label_children_class</source>
<target>form.label_children_class</target>
</trans-unit>
<trans-unit id="form.label_menu_template">
<source>form.label_menu_template</source>
<target>form.label_menu_template</target>
</trans-unit>
<trans-unit id="pages.label_no_sites">
<source>pages.label_no_sites</source>
<target>pages.label_no_sites</target>
Expand Down
32 changes: 0 additions & 32 deletions src/Resources/translations/SonataPageBundle.de.xliff
Original file line number Diff line number Diff line change
Expand Up @@ -850,38 +850,6 @@
<source>form.label_text</source>
<target>Text</target>
</trans-unit>
<trans-unit id="form.label_menu_name">
<source>form.label_menu_name</source>
<target>Menu</target>
</trans-unit>
<trans-unit id="form.label_safe_labels">
<source>form.label_safe_labels</source>
<target>Sichere Label Texte</target>
</trans-unit>
<trans-unit id="form.label_current_class">
<source>form.label_current_class</source>
<target>Aktuelle CSS Klasse</target>
</trans-unit>
<trans-unit id="form.label_first_class">
<source>form.label_first_class</source>
<target>Erste CSS Klasse</target>
</trans-unit>
<trans-unit id="form.label_last_class">
<source>form.label_last_class</source>
<target>Letzte CSS Klasse</target>
</trans-unit>
<trans-unit id="form.label_menu_class">
<source>form.label_menu_class</source>
<target>Menü CSS Klasse</target>
</trans-unit>
<trans-unit id="form.label_children_class">
<source>form.label_children_class</source>
<target>Submenü CSS Klasse</target>
</trans-unit>
<trans-unit id="form.label_menu_template">
<source>form.label_menu_template</source>
<target>Menü Template</target>
</trans-unit>
<trans-unit id="pages.label_no_sites">
<source>pages.label_no_sites</source>
<target>Keine Seiten konfiguriert</target>
Expand Down
32 changes: 0 additions & 32 deletions src/Resources/translations/SonataPageBundle.en.xliff
Original file line number Diff line number Diff line change
Expand Up @@ -855,38 +855,6 @@
<source>form.label_text</source>
<target>Text</target>
</trans-unit>
<trans-unit id="form.label_menu_name">
<source>form.label_menu_name</source>
<target>Menu</target>
</trans-unit>
<trans-unit id="form.label_safe_labels">
<source>form.label_safe_labels</source>
<target>Safe labels</target>
</trans-unit>
<trans-unit id="form.label_current_class">
<source>form.label_current_class</source>
<target>Current CSS class</target>
</trans-unit>
<trans-unit id="form.label_first_class">
<source>form.label_first_class</source>
<target>First CSS class</target>
</trans-unit>
<trans-unit id="form.label_last_class">
<source>form.label_last_class</source>
<target>Last CSS class</target>
</trans-unit>
<trans-unit id="form.label_menu_class">
<source>form.label_menu_class</source>
<target>Menu CSS class</target>
</trans-unit>
<trans-unit id="form.label_children_class">
<source>form.label_children_class</source>
<target>Children CSS class</target>
</trans-unit>
<trans-unit id="form.label_menu_template">
<source>form.label_menu_template</source>
<target>Menu template</target>
</trans-unit>
<trans-unit id="pages.label_no_sites">
<source>pages.label_no_sites</source>
<target>No sites configured</target>
Expand Down
32 changes: 0 additions & 32 deletions src/Resources/translations/SonataPageBundle.es.xliff
Original file line number Diff line number Diff line change
Expand Up @@ -847,38 +847,6 @@
<source>form.label_text</source>
<target>form.label_text</target>
</trans-unit>
<trans-unit id="form.label_menu_name">
<source>form.label_menu_name</source>
<target>form.label_menu_name</target>
</trans-unit>
<trans-unit id="form.label_safe_labels">
<source>form.label_safe_labels</source>
<target>form.label_safe_labels</target>
</trans-unit>
<trans-unit id="form.label_current_class">
<source>form.label_current_class</source>
<target>form.label_current_class</target>
</trans-unit>
<trans-unit id="form.label_first_class">
<source>form.label_first_class</source>
<target>form.label_first_class</target>
</trans-unit>
<trans-unit id="form.label_last_class">
<source>form.label_last_class</source>
<target>form.label_last_class</target>
</trans-unit>
<trans-unit id="form.label_menu_class">
<source>form.label_menu_class</source>
<target>form.label_menu_class</target>
</trans-unit>
<trans-unit id="form.label_children_class">
<source>form.label_children_class</source>
<target>form.label_children_class</target>
</trans-unit>
<trans-unit id="form.label_menu_template">
<source>form.label_menu_template</source>
<target>form.label_menu_template</target>
</trans-unit>
<trans-unit id="pages.label_no_sites">
<source>pages.label_no_sites</source>
<target>pages.label_no_sites</target>
Expand Down
32 changes: 0 additions & 32 deletions src/Resources/translations/SonataPageBundle.fr.xliff
Original file line number Diff line number Diff line change
Expand Up @@ -856,38 +856,6 @@
<source>form.label_text</source>
<target>Text</target>
</trans-unit>
<trans-unit id="form.label_menu_name">
<source>form.label_menu_name</source>
<target>Nom du menu</target>
</trans-unit>
<trans-unit id="form.label_safe_labels">
<source>form.label_safe_labels</source>
<target>Labels</target>
</trans-unit>
<trans-unit id="form.label_current_class">
<source>form.label_current_class</source>
<target>Class CSS élément séléctionné</target>
</trans-unit>
<trans-unit id="form.label_first_class">
<source>form.label_first_class</source>
<target>Class CSS premier élément</target>
</trans-unit>
<trans-unit id="form.label_last_class">
<source>form.label_last_class</source>
<target>Class CSS dernier élément</target>
</trans-unit>
<trans-unit id="form.label_menu_class">
<source>form.label_menu_class</source>
<target>Class CSS Menu</target>
</trans-unit>
<trans-unit id="form.label_children_class">
<source>form.label_children_class</source>
<target>Class CSS enfant</target>
</trans-unit>
<trans-unit id="form.label_menu_template">
<source>form.label_menu_template</source>
<target>Modèle de page</target>
</trans-unit>
<trans-unit id="pages.label_no_sites">
<source>pages.label_no_sites</source>
<target>pages.label_no_sites</target>
Expand Down
Loading