sonata-project/SonataPageBundle — pull request #74 by tamayg (2012-04-08 20:32:39+00:00)
Title: Support for SiteMenus (KNP Menu)

Not sure if you want to merge this, but i'd appreciate comments.
Here is what ive done:

added "showInMenu" field to page/snapshotpage entity.
Added translations; one can choose in the admin-backend if a page should be displayed in the sitemenu.

The Site menu is provided by a service and can be called with {{ knp_menu_render('SiteMainMenu') }}, which will render the Menu for the actual site (using page titles as menu item labels).

ISSUE: currently the Menu/MenuBuilder.php uses a workaround to generate the menu on base of the actual pages or its snapshots. I havent yet found a nice solution for this, any help or suggestions would be highly appreciated.

The workaround (the following quote refers to the MenuBuilder.php):

The workaround can be seen on lines 43-53 (the cause), 77 (symptom), 83-87 (symptom).
The problem is the page-/snapshotManager, which i need to get all pages with certain fields.

I actually liked the way how the CmsManager(Selector) solution works, both, the CmsSnapshotManager and the CmsPageManager implement the same interfaces, which makes it possible to use the same commands without any problems.
But i needed access to the page-/snapshotManager, which was not given in the CmsManager. So i thought i'd try a similar way, decide dynamicly which one to use, and call the same methods.
Almost worked fine, except that it started bugging with the findby and the "parent" field.
The parent field itself is only available to a snapshot(pageproxy), after a ->getPage() was called (cause it there calls the load method).
So i couldnt use findby(parent => ..), instead i used parentId, which worked.
Now that messed up the pageManager which only would understand 'parent' in its findby method/field declarations.

So i ended up checking which manager was loaded and adjusting the required field, but i feel like its a badstyle workaround and after i've seen that the creators of the Bundle spend some thought on the CmsManager i thought there must be a better way to do it, but i couldnt find it.