-
Notifications
You must be signed in to change notification settings - Fork 202
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
Conversation
use Knp\Menu\ItemInterface; | ||
|
||
/** | ||
* An extension to dynamically configure default menu options. |
There was a problem hiding this comment.
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.
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> |
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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 :)
d9514b6
to
72dc946
Compare
updated |
👍 @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'])) { |
There was a problem hiding this comment.
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)
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); |
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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)
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? |
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. |
can we wrap this one up somehow? |
@wouterj is this PR still active? |
Only register validation metadata when PHPCR is enabled, adjust file structure
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