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

Add ability to configure default menu options #278

Closed
wants to merge 1 commit into from

Conversation

wouterj
Copy link
Collaborator

@wouterj wouterj commented Aug 27, 2015

In the CMF, menu's aren't created programatically. With the current code, it means the menu options needs to be saved in the database in order to be set on the menu items.

It would be much better if we could configure this in the application settings. This PR implements a very simple DefaultOptionsExtensions, setting the default options based on a configured set of options.

This extension is automatically registered as soon as at least one option is configured.

@stof @Nek- I would love to hear your opinion about this (both the idea and whether it should be in this bundle or in the CMF).

Related issue: symfony-cmf/menu-bundle#128

use Knp\Menu\ItemInterface;

/**
* An extension to dynamically configure default menu options.
Copy link
Collaborator

Choose a reason for hiding this comment

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

why "dynamically"? if the default options are in the configuration file, i would consider that rather static.

@dbu
Copy link
Collaborator

dbu commented Aug 28, 2015

i like it!

xsi:schemaLocation="http://symfony.com/schema/dic/services http://symfony.com/schema/dic/services/services-1.0.xsd">

<parameters>
<parameter key="knp_menu.extension.default_options.class">Knp\Bundle\MenuBundle\Extension\DefaultOptionsExtension</parameter>
Copy link
Collaborator

Choose a reason for hiding this comment

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

please don't introduce new class parameters. this practice is now discouraged in symfony

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Ok, in the CMF, we decided to add them in the 1.x serie, for consistency and remove them all in 2.0. So I was a bit unsure about the standard of KnpMenu :)

@wouterj wouterj force-pushed the configure_default_values branch from d9514b6 to 72dc946 Compare August 29, 2015 10:19
@wouterj
Copy link
Collaborator Author

wouterj commented Aug 29, 2015

updated

@dbu
Copy link
Collaborator

dbu commented Aug 29, 2015

👍

@Nek- do you agree with this one?

@@ -38,6 +38,11 @@ public function load(array $configs, ContainerBuilder $container)
}

$container->setParameter('knp_menu.default_renderer', $config['default_renderer']);

if (isset($config['default_menu_options'])) {
Copy link
Collaborator

Choose a reason for hiding this comment

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

it is always set (prototyped array nodes have a default value of empty array)

@dbu
Copy link
Collaborator

dbu commented Sep 20, 2015

oh, right. otherwise do you agree with the PR @stof or is that the only issue that needs to be fixed?

*/
public function buildOptions(array $options = array())
{
return array_merge($this->options, $options);
Copy link
Collaborator

Choose a reason for hiding this comment

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

many options of the library are arrays. This makes them hard to use with your extension

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

So you suggest using array_merge_recursive instead?

Copy link
Collaborator

Choose a reason for hiding this comment

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

I don't know what to use here. array_merge_recursive has a very weird behavior when associate arrays are involved, so it is not the solution either (it would be even worse). array_replace_recursive would already be a bit better as we mostly have associative arrays (but this one leads to an unexpected behavior when lists are merged together though, and this happens in extras, for instance for the list of matched routes)

@dbu
Copy link
Collaborator

dbu commented Sep 28, 2015

this was in the 2.1 milestone but @stof just tagged 2.1.0

should we remove the milestone now? does it go to 2.2?

@stof
Copy link
Collaborator

stof commented Sep 28, 2015

Well, I don't rely on the milestone in the project actually. I won't delay a release because a new feature is not ready. It can simply go in a new release.

@stof stof removed this from the 2.1 milestone Sep 28, 2015
@dbu
Copy link
Collaborator

dbu commented Jun 21, 2016

can we wrap this one up somehow?

@garak
Copy link
Collaborator

garak commented Jul 25, 2019

@wouterj is this PR still active?
Some comments need to be addressed, and some conflicts need to be solved

EmmanuelVella pushed a commit to EmmanuelVella/KnpMenuBundle that referenced this pull request Sep 23, 2020
Only register validation metadata when PHPCR is enabled, adjust file structure
@wouterj wouterj closed this Oct 12, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants