symfony-cmf / menu-bundle

Extends the KnpMenuBundle to work with PHPCR ODM
https://cmf.symfony.com
32 stars 48 forks source link

Ability to edit route parameters for MenuNodes of type route via admin form #143

Closed benglass closed 10 years ago

benglass commented 11 years ago

When you create a menu node, it can be of type "route" and point at a symfony route.

If the symfony route accepts parameters, I am not sure how you can go about setting those parameters on the menu node.

For example, if the route projects_by_category has a parameter named slug, how can you add a MenuNode that will link to this route with the slug parameter set to "foo".

It looks like the ContentAwareFactory already calls getOptions on the MenuNode when it is being created, so if that returned an array with the key routeParameters then those route parameters would be included in the url that is generated. It also looks like MenuNodeBase has a routeParameters member variable that is mapped as an assoc multi value field, so it looks like the only missing piece is a way to specify route parameters when editing a MenuNode.

Providing this functionality (editing a multi value phpcr field while preserving keys) is a more general question. Is there something in sonata phpcr admin that could be used for this? This also relates to a general question about how to map data via a symfony form when the property path would require multiple arguments when called. In other words I need to call $model->setRouteParameter('slug', 'value') rather than just $model->setRouteParameter('value')

benglass commented 11 years ago

https://github.com/sonata-project/SonataDoctrinePhpcrAdminBundle/issues/92

Looks like perhaps we can just use this for the time being so that people can edit route parameters for menu nodes of link type route.

benglass commented 11 years ago

Just tested the use of a collection field for this and it does not allow editing of the keys which would be a requirement in this case so this would require a custom form type most likely.

benglass commented 11 years ago

related to #81

dbu commented 11 years ago

so far we helped ourselves by explicitly having an immutable array in the form, see for example https://github.com/symfony-cmf/RoutingBundle/blob/master/Admin/RouteAdmin.php#L87 . for your usecase you could create a specific menu node that has such fields, that is less flexible but more user friendly for your editors.

but indeed, having a mutable array (hashmap) would be quite cool.

dantleech commented 11 years ago

The associative array form field would definitely be a valuable addition to Sonata I think /cc @rande

rande commented 11 years ago

Immutable array type already exists . Name can be confusing ... Le 4 oct. 2013 09:03, "dantleech" notifications@github.com a écrit :

The associative array form field would definitely be a valuable addition to Sonata I think /cc @rande https://github.com/rande

— Reply to this email directly or view it on GitHubhttps://github.com/symfony-cmf/MenuBundle/issues/143#issuecomment-25679848 .

dbu commented 11 years ago

@rande: we know and use the immutable array. but we would love a mutable array where we can add named key-value pairs to. or are you saying immutable array type is actually mutable in the sense of adding/removing entries?

benglass commented 11 years ago

@dbu looking at the code for the ImmutableType it doesnt extend collection just the AbstractType from symfony so i dont think it has any capability for add/remove.

Looks like a separate type is needed (mutable_array perhaps). I don't think this could extend ImmutableArrayType as that is not a collection type so would not facilitate add/remove.

dbu commented 11 years ago

okay. well maybe the ImmutableType could be refactored to become a special case of the MutableType? anyway, we should look into basic form support for this, it should not necessarily be sonata specific. maybe it could go into the DoctrinePHPCRBundle, as its particularly useful with phpcr data...

dantleech commented 11 years ago

I do think that this should be in SonataAdmin -- it has really nothing to do with PHPCR, it maps equally well to an array field in ORM for example.

dbu commented 11 years ago

it should be in the symfony form component then :-) but well, we have to put it somewhere we have control over. so the base SonataAdminBundle sounds ok to me

phiamo commented 11 years ago

this would also allow editing of

childrenAttributes / Keys linkAttributes / Keys attributes / Keys

is there anywhere anyone working on this? or any further discussion taking place?

benglass commented 11 years ago

@phiamo No i dont think anyone is particularly committed to this at this point. I think its a strong candidate for trying to get into 1.1 since its so multi-purpose

dbu commented 11 years ago

@phiamo i would love this to happen if you have time to work on it. best send an email to symfony-cmf-devs@googlegroups.com so that everybody is aware you are working on it, to avoid duplicated work. and also if you need any help. i think the hard part is making it actually work - and then figuring out into which repository this really belongs, but for that the mailinglist is the right place to discuss.

phiamo commented 11 years ago

@dbu i dont think i will have time nor insight in the next few weeks to go on this :/

phiamo commented 10 years ago

@dbu i would love to have that feature, but i dont have any idea yet where to start ... we will need some generic data transformer or is there already one capable of nested hashmaps? We need to add this to the admin forms one by one. What else did i miss?

dbu commented 10 years ago

bart van den burg created a form type for editing key-value maps: https://github.com/Burgov/KeyValueFormBundle

i think you can leverage that one for editing the defaults and then you are set. you should not need any nested hashmaps, as the route parameters need to be strings anyways if i am not mistaken.

we should not add a dependency on that bundle to the menu bundle but explain in the doc that for sonata it is required. wdyt?

phiamo commented 10 years ago

if "someone" figures out how to include this and document it that would be awesome, which doc would you append that info into, or wouldyou create anew one?

dbu commented 10 years ago

i think for the doc, it could be mentioned in https://github.com/symfony-cmf/symfony-cmf-docs/blob/master/bundles/phpcr_odm.rst#form-types as an additional form type that can be handy.

then the DoctrinePHPCRBundle could suggest the keyvalueformbundle and require-dev it, and adjust the form type guesser to use it - if the class_exists. see https://github.com/doctrine/DoctrinePHPCRBundle/pull/93/files#diff-2 and https://github.com/doctrine/DoctrinePHPCRBundle/issues/111

do you want to give it a shot?

phiamo commented 10 years ago

@dbu https://github.com/doctrine/DoctrinePHPCRBundle/pull/120 a shot...

dbu commented 10 years ago

https://github.com/doctrine/DoctrinePHPCRBundle/pull/120 is merged. anything left to do here?

dbu commented 10 years ago

doc PR https://github.com/symfony-cmf/symfony-cmf-docs/pull/450