|
5 | 5 | MenuBundle
|
6 | 6 | ==========
|
7 | 7 |
|
8 |
| -The `MenuBundle`_ provides menus from a doctrine object manager with the help |
9 |
| -of `KnpMenuBundle`_. |
| 8 | +The CmfMenuBundle extends the `KnpMenuBundle`_ by adding a menu provider |
| 9 | +that loads menus from a doctrine object manager and generating menu URLs |
| 10 | +from content. |
| 11 | + |
| 12 | +.. caution:: |
| 13 | + |
| 14 | + Make sure you understand how the `KnpMenuBundle`_ works when you want to |
| 15 | + customize the CmfMenuBundle. The CMF menu bundle is just adding |
| 16 | + functionality on top of the Knp menu bundle and this documentation is |
| 17 | + focused on the additional functionality. |
10 | 18 |
|
11 | 19 | .. index:: MenuBundle
|
12 | 20 |
|
13 | 21 | Dependencies
|
14 | 22 | ------------
|
15 | 23 |
|
16 |
| -This bundle is extending the `KnpMenuBundle`_. |
| 24 | +This bundle is extending the `KnpMenuBundle`_. Unless you change defaults and |
| 25 | +provide your own implementations, this bundle also depends on: |
17 | 26 |
|
18 |
| -Unless you change defaults and provide your own implementations, this bundle |
19 |
| -also depends on |
20 |
| - |
21 |
| -* ``SymfonyRoutingBundle`` for the router service |
22 |
| - ``cmf_routing.dynamic_router``. Note that you need to explicitly |
23 |
| - enable the dynamic router as per default it is not loaded. See the |
24 |
| - :doc:`documentation of the cmf routing bundle <routing>` for how to do this. |
25 |
| -* :doc:`PHPCR-ODM <phpcr_odm>` to load route documents from the content repository |
| 27 | +* **CmfRoutingBundle** - if you want to generate routes for content objects. |
| 28 | + Note that you need to explicitly enable the dynamic router as per default it |
| 29 | + is not loaded. See the |
| 30 | + :doc:`documentation of the cmf routing bundle <routing>` for more information. |
| 31 | +* :doc:`PHPCR-ODM <phpcr_odm>` - to load route documents from the content |
| 32 | + repository when using the ``PHPCRMenuProvider``. |
26 | 33 |
|
27 | 34 | Configuration
|
28 | 35 | -------------
|
@@ -57,34 +64,80 @@ The values are:
|
57 | 64 | If you want to render the menu from twig, make sure you have not disabled twig
|
58 | 65 | in the ``knp_menu`` configuration section.
|
59 | 66 |
|
60 |
| -If ``sonata-project/doctrine-phpcr-admin-bundle`` is added to the |
61 |
| -composer.json require section, the menu documents are exposed in the |
62 |
| -SonataDoctrinePhpcrAdminBundle. For instructions on how to configure this |
| 67 | +If you have ``sonata-project/doctrine-phpcr-admin-bundle`` in your |
| 68 | +``composer.json`` require section, the menu documents are exposed in the |
| 69 | +SonataDoctrinePhpcrAdminBundle. For instructions on how to configure this |
63 | 70 | Bundle see :doc:`doctrine_phpcr_admin`.
|
64 | 71 |
|
65 | 72 | By default, ``use_sonata_admin`` is automatically set based on whether
|
66 |
| -SonataDoctrinePhpcrAdminBundle is available but you can explicitly disable it |
| 73 | +SonataDoctrinePhpcrAdminBundle is available, but you can explicitly disable it |
67 | 74 | to not have it even if sonata is enabled, or explicitly enable to get an error
|
68 | 75 | if Sonata becomes unavailable.
|
69 | 76 |
|
70 |
| -By default, menu nodes that have neither the uri nor the route field set and no |
71 |
| -route can be generated from the content they link to are skipped by the |
| 77 | +By default, menu nodes that have neither the URI nor the routeName field set |
| 78 | +and no route can be generated from the linked content are skipped by the |
72 | 79 | ``ContentAwareFactory``. This also leads to their descendants not showing up.
|
73 | 80 | If you want to generate menu items without a link instead, set the
|
74 | 81 | ``allow_empty_items`` parameter to true to make the menu items show up as
|
75 |
| -static text instead. |
| 82 | +plain text instead. |
76 | 83 |
|
77 | 84 | Menu Entries
|
78 | 85 | ------------
|
79 | 86 |
|
80 |
| -A ``MenuItem`` document defines menu entries. You can build menu items based |
81 |
| -on symfony routes, absolute or relative urls or referenceable PHPCR-ODM |
82 |
| -content documents. |
| 87 | +A ``MenuNode`` document defines a menu entry. You can build entries based |
| 88 | +on symfony route names, absolute or relative URLs or referenceable PHPCR-ODM |
| 89 | +content documents. Route names and URLs are provided directly by `KnpMenu`_. |
| 90 | +Generating routes from content objects is a feature of the CmfRoutingBundle. |
| 91 | + |
| 92 | +Menu Provider |
| 93 | +~~~~~~~~~~~~~ |
| 94 | + |
| 95 | +A menu provider is responsible to load a menu when it is requested. KnpMenu |
| 96 | +supports having several providers. The CmfMenuBundle provides the |
| 97 | +``PHPCRMenuProvider`` to load menu items from PHPCR-ODM. |
| 98 | + |
| 99 | +Every menu has a name and is loaded by that name. The ``PHPCRMenuProvider`` |
| 100 | +locates menus by looking at ``persistence.phpcr.menu_basepath``/``<menuname>``. |
| 101 | +You can use custom document classes for menu nodes if needed, as long as they |
| 102 | +implement ``Knp\Menu\NodeInterface`` to integrate with KnpMenuBundle. The |
| 103 | +default ``MenuNode`` class discards children that do not implement the |
| 104 | +``Knp\Menu\NodeInterface``. |
| 105 | + |
| 106 | +.. note:: |
| 107 | + |
| 108 | + There is currently no support for Doctrine ORM or other persistence |
| 109 | + managers. This is not by design, but only because nobody built that yet. |
| 110 | + We would be glad for a pull request refactoring ``PHPCRMenuProvider`` into |
| 111 | + a base class suitable for all doctrine implementations, and storage |
| 112 | + specific providers. |
| 113 | + |
| 114 | +You can also write your completely custom provider and register it with the |
| 115 | +KnpMenu as explained in the `KnpMenuBundle custom provider documentation`_. |
| 116 | + |
| 117 | +Menu Factory |
| 118 | +~~~~~~~~~~~~ |
| 119 | + |
| 120 | +The menu nodes need to be converted into menu items. This is the job of the |
| 121 | +menu factory. A menu item should have a URL associated with it. KnpMenu can |
| 122 | +either take the ``uri`` field from the options, or generate a URL from the |
| 123 | +``route`` and ``routeParameters`` options. The CmfMenuBundle provides the |
| 124 | +``ContentAwareFactory`` that supports to generate the URL from the ``content`` |
| 125 | +option that contains an object the ``DynamicRouter`` can generate a URL for, plus |
| 126 | +eventual ``routeParameters``. Thus a menu node can link to a content object or |
| 127 | +a route object in the database and put that object into the options to have the |
| 128 | +URL generated. |
| 129 | + |
| 130 | +URL generation is absolute or relative, depending on ``routeAbsolute``. |
| 131 | +If you specify the ``linkType`` option, you can control how the URL is |
| 132 | +generated. If this parameter is missing, it is determined automatically, |
| 133 | +tacking in order ``uri``,``route`` or ``content``. |
| 134 | + |
| 135 | +.. note:: |
83 | 136 |
|
84 |
| -The menu tree is built from documents under [menu_basepath]/[menuname]. You |
85 |
| -can use different document classes for menu items as long as they implement |
86 |
| -``Knp\Menu\NodeInterface`` to integrate with KnpMenuBundle. The default |
87 |
| -``MenuNode`` document discards children that do not implement this interface. |
| 137 | + If you just want to generate normal Symfony routes with a menu that is in |
| 138 | + the database, simply make sure to never provide a ``content`` option and |
| 139 | + either provide the ``route`` and eventual ``routeParameters`` or the |
| 140 | + ``uri``. |
88 | 141 |
|
89 | 142 | Examples::
|
90 | 143 |
|
@@ -130,20 +183,8 @@ Examples::
|
130 | 183 |
|
131 | 184 | $dm->flush();
|
132 | 185 |
|
133 |
| -By default content documents are created using a **weak** reference (this |
134 |
| -means you will be able to delete the referenced content). You can specify a |
135 |
| -strong reference by using ``setWeak(false)``:: |
136 |
| - |
137 |
| - <?php |
138 |
| - |
139 |
| - $node = new MenuNode; |
140 |
| - // ... |
141 |
| - $node->setWeak(false); |
142 |
| - |
143 |
| -.. note:: |
144 |
| - |
145 |
| - When content is referenced weakly and subsequently deleted the rendered |
146 |
| - menu will not provide a link to the content. |
| 186 | +The default PHPCR-ODM mapping links content documents by a **weak** reference, |
| 187 | +which means you are able to delete the referenced content. |
147 | 188 |
|
148 | 189 | Current Menu Item
|
149 | 190 | -----------------
|
@@ -342,38 +383,13 @@ The menu name is the name of the node under ``menu_basepath``. For example if
|
342 | 383 | your repository stores the menu nodes under ``/cms/menu`` , rendering "main"
|
343 | 384 | would mean to render the menu that is at ``/cms/menu/main``
|
344 | 385 |
|
345 |
| -How to use Non-Default Other Components |
346 |
| ---------------------------------------- |
347 |
| - |
348 |
| -If you use the cmf menu with PHPCR-ODM, you just need to store Route documents |
349 |
| -under ``menu_basepath``. If you use a different object manager, you need to |
350 |
| -make sure that the menu root document is found with:: |
351 |
| - |
352 |
| - $dm->find($menu_document_class, $menu_basepath . $menu_name) |
353 |
| - |
354 |
| -The route document must implement ``Knp\Menu\NodeInterface`` - see |
355 |
| -``MenuNode`` document for an example. You probably need to specify |
356 |
| -menu_document_class too, as only PHPCR-ODM can determine the document from the |
357 |
| -database content. |
358 |
| - |
359 |
| -If you use the cmf menu with the DynamicRouter, you need no route name as the |
360 |
| -menu document just needs to provide a field content_key in the options. If |
361 |
| -you want to use a different service to generate URLs, you need to make sure |
362 |
| -your menu entries provide information in your selected content_key that the |
363 |
| -url generator can use to generate the url. Depending on your generator, you |
364 |
| -might need to specify a route_name too. |
365 |
| - |
366 |
| -Note that if you just want to generate normal symfony routes with a menu that |
367 |
| -is in the database, you can pass the core router service as |
368 |
| -content_url_generator, make sure the content_key never matches and make your |
369 |
| -menu documents provide the route name and eventual routeParameters. |
370 |
| - |
371 | 386 | Publish Workflow Interface
|
372 | 387 | --------------------------
|
373 | 388 |
|
374 | 389 | Menu nodes implement the write interfaces for publishable and publish time
|
375 | 390 | period, see the :ref:`publish workflow documentation <bundle-core-publish_workflow>`
|
376 | 391 | for more information.
|
377 | 392 |
|
378 |
| -.. _`MenuBundle`: https://github.com/symfony-cmf/MenuBundle#readme |
| 393 | +.. _`KnpMenu`: https://github.com/knplabs/KnpMenu |
379 | 394 | .. _`KnpMenuBundle`: https://github.com/knplabs/KnpMenuBundle
|
| 395 | +.. _`KnpMenuBundle custom provider documentation`: https://github.com/KnpLabs/KnpMenuBundle/blob/master/Resources/doc/custom_provider.md |
0 commit comments