Skip to content
This repository has been archived by the owner on Sep 16, 2021. It is now read-only.

[Admin] Added Route Parameters to MenuNodeAdmin #109

Open
wants to merge 5 commits into
base: master
Choose a base branch
from
Open
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
10 changes: 10 additions & 0 deletions src/Admin/Menu/AbstractMenuNodeAdmin.php
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,11 @@ abstract class AbstractMenuNodeAdmin extends AbstractAdmin
*/
protected $menuRoot;

/**
* @var bool
*/
protected $useBurgovKeyValueForm;
Copy link
Member

Choose a reason for hiding this comment

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

why is this on the base class? it is only used in one place, lets move it to the specific class until we need it in more places.


/**
* @var string
*/
Expand Down Expand Up @@ -92,6 +97,11 @@ public function setContentTreeBlock($contentTreeBlock)
$this->contentTreeBlock = $contentTreeBlock;
}

public function setUseBurgovKeyValueForm($useBurgovKeyValueForm)
{
$this->useBurgovKeyValueForm = $useBurgovKeyValueForm;
}

public function toString($object)
{
if ($object instanceof MenuNodeBase && $object->getLabel()) {
Expand Down
22 changes: 21 additions & 1 deletion src/Admin/Menu/MenuNodeAdmin.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
use Sonata\DoctrinePHPCRAdminBundle\Form\Type\ChoiceFieldMaskType;
use Knp\Menu\ItemInterface as MenuItemInterface;
use Doctrine\Common\Util\ClassUtils;
use Burgov\Bundle\KeyValueFormBundle\Form\Type\KeyValueType;

class MenuNodeAdmin extends AbstractMenuNodeAdmin
{
Expand Down Expand Up @@ -69,14 +70,33 @@ protected function configureFormFields(FormMapper $formMapper)
'content' => 'content',
),
'map' => array(
'route' => array('link'),
'route' => array('link', 'routeParameters'),
'uri' => array('link'),
'content' => array('content', TreeSelectType::class),
),
'placeholder' => 'auto',
'required' => false,
))
->add('link', TextType::class, array('required' => false, 'mapped' => false))
;

if ($this->useBurgovKeyValueForm)
{
$formMapper
->add('routeParameters', KeyValueType::class, array(
'value_type' => TextType::class,
'required' => false,
'entry_options' => array(
'value_type' => TextType::class,
'label' => false,
'attr' => array('style' => 'clear:both'),
),
'label' => 'form.label_options'
))
;
}

$formMapper
->add(
'content',
TreeSelectType::class,
Expand Down
9 changes: 9 additions & 0 deletions src/DependencyInjection/Factory/MenuAdminFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ public function addConfiguration(NodeBuilder $builder)
{
$builder
->booleanNode('recursive_breadcrumbs')->defaultTrue()->end()
->booleanNode('use_burgov_keyvalue_form')->defaultFalse()->end()
Copy link
Member

Choose a reason for hiding this comment

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

plesae make this a true/false/auto option node like in the seo configuration

->arrayNode('extensions')
->addDefaultsIfNotSet()
->children()
Expand Down Expand Up @@ -72,6 +73,7 @@ public function create(array $config, ContainerBuilder $container, XmlFileLoader
$loader->load('menu.xml');

$this->loadExtensions($config['extensions'], $container, $loader);
$this->loadBurgovKeyValueForm($container);
}

private function loadExtensions(array $config, ContainerBuilder $container, XmlFileLoader $loader)
Expand Down Expand Up @@ -101,4 +103,11 @@ private function loadExtensions(array $config, ContainerBuilder $container, XmlF
}
}
}

private function loadBurgovKeyValueForm(ContainerBuilder $container)
{
$bundles = $container->getParameter('kernel.bundles');

$container->setParameter('cmf_sonata_phpcr_admin_integration.menu.use_burgov_keyvalue_form', isset($bundles['BurgovKeyValueFormBundle']) );
Copy link
Member

Choose a reason for hiding this comment

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

this ignores the value set in the configuration. please use the logic as in the SEO DI extension to check for the bundle if the value is auto, and fail if set to true and burgov is missing

}
}
4 changes: 4 additions & 0 deletions src/Resources/config/menu.xml
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,10 @@
<call method="setRecursiveBreadcrumbs">
<argument>%cmf_sonata_phpcr_admin_integration.menu.recursive_breadcrumbs%</argument>
</call>

<call method="setUseBurgovKeyValueForm">
<argument>%cmf_sonata_phpcr_admin_integration.menu.use_burgov_keyvalue_form%</argument>
</call>
</service>

<service
Expand Down