Skip to content
This repository was archived by the owner on Sep 16, 2021. It is now read-only.

Commit 8586c0e

Browse files
authored
Merge pull request #808 from symfony-cmf/bp-menu
[menu] change doc to best practices
2 parents d9cb711 + 8d90850 commit 8586c0e

File tree

6 files changed

+101
-92
lines changed

6 files changed

+101
-92
lines changed

bundles/menu/configuration.rst

Lines changed: 26 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -64,9 +64,9 @@ persistence configuration has the following configuration:
6464
.. code-block:: php
6565
6666
// app/config/config.php
67-
$container->loadFromExtension('cmf_menu', array(
68-
'persistence' => array(
69-
'phpcr' => array(
67+
$container->loadFromExtension('cmf_menu', [
68+
'persistence' => [
69+
'phpcr' => [
7070
'enabled' => false,
7171
'menu_basepath' => '/cms/menu',
7272
'content_basepath' => null,
@@ -78,9 +78,9 @@ persistence configuration has the following configuration:
7878
'menu_admin_class' => null,
7979
'node_admin_class' => null,
8080
'admin_recursive_breadcrumbs' => true,
81-
),
82-
),
83-
));
81+
],
82+
],
83+
]);
8484
8585
``enabled``
8686
"""""""""""
@@ -244,15 +244,14 @@ You can configure the menu options extension in this sections.
244244
.. code-block:: php
245245
246246
// app/config/config.php
247-
$container->loadFromExtension('cmf_menu', array(
248-
'admin_extensions' => array(
249-
'menu_options' => array(
250-
'enabled' => 'auto',
251-
'advanced' => false,
252-
),
253-
),
254-
),
255-
));
247+
$container->loadFromExtension('cmf_menu', [
248+
'admin_extensions' => [
249+
'menu_options' => [
250+
'enabled' => 'auto',
251+
'advanced' => false,
252+
],
253+
],
254+
]);
256255
257256
``enabled``
258257
"""""""""""
@@ -303,16 +302,16 @@ The ``voters`` section enables you to enable and configure *pre-defined*
303302
.. code-block:: php
304303
305304
// app/config/config.php
306-
$container->loadFromExtension('cmf_menu', array(
307-
'persistence' => array(
308-
'voters' => array(
309-
'content_identity' => array(
305+
$container->loadFromExtension('cmf_menu', [
306+
'persistence' => [
307+
'voters' => [
308+
'content_identity' => [
310309
'content_key' => null,
311-
),
310+
],
312311
'uri_prefix' => false,
313-
),
314-
),
315-
));
312+
],
313+
],
314+
]);
316315
317316
``content_identity``
318317
~~~~~~~~~~~~~~~~~~~~
@@ -382,8 +381,8 @@ To disable the menu content voter, use:
382381
.. code-block:: php
383382
384383
// app/config/config.php
385-
$container->loadFromExtension('cmf_core', array(
386-
'publish_workflow' => array(
384+
$container->loadFromExtension('cmf_core', [
385+
'publish_workflow' => [
387386
'enabled' => false,
388-
),
389-
));
387+
],
388+
]);

bundles/menu/introduction.rst

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -36,11 +36,11 @@ bundles in addition to the CmfMenuBundle::
3636
{
3737
public function registerBundles()
3838
{
39-
$bundles = array(
39+
$bundles = [
4040
// ...
4141
new Knp\Bundle\MenuBundle\KnpMenuBundle(),
4242
new Symfony\Cmf\Bundle\MenuBundle\CmfMenuBundle(),
43-
);
43+
];
4444

4545
// ...
4646
}

bundles/menu/menu_documents.rst

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -31,26 +31,26 @@ the KnpMenu component documentation for more information.
3131
// Attributes are the HTML attributes of the DOM element representing the
3232
// menu node (e.g. <li/>)
3333
$node->setAttribute('attr_name', 'attr_value');
34-
$node->setAttributes(array('attr_name', 'attr_value'));
35-
$node->setChildrenAttributes(array('attr_name', 'attr_value'));
34+
$node->setAttributes(['attr_name', 'attr_value']);
35+
$node->setChildrenAttributes(['attr_name', 'attr_value']);
3636
3737
// Display the node or not
3838
$node->setDisplay(true);
3939
$node->setDisplayChildren(true);
4040
4141
// Any extra attributes you wish to associate with the menu node
42-
$node->setExtras(array('extra_param_1' => 'value'));
42+
$node->setExtras(['extra_param_1' => 'value']);
4343
4444
// The label and the HTML attributes of the label
4545
$node->setLabel('Menu Node');
46-
$node->setLabelAttributes(array('style' => 'color: red;'));
46+
$node->setLabelAttributes(['style' => 'color: red;']);
4747
4848
// The HTML attributes of the link (i.e. <a href=.../>
49-
$node->setLinkAttributes(array('style' => 'color: yellow;'));
49+
$node->setLinkAttributes(['style' => 'color: yellow;']);
5050
5151
// Specify a route name to use and the parameters to use with it
5252
$node->setRoute('my_hard_coded_route_name');
53-
$node->setRouteParameters(array());
53+
$node->setRouteParameters([]);
5454
5555
// Specify if the route should be rendered absolute (otherwise relative)
5656
$node->setRouteAbsolute(true);

bundles/menu/menu_factory.rst

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -183,7 +183,7 @@ The service needs to be tagged as event listener:
183183
<container xmlns="http://symfony.com/schema/dic/services">
184184
185185
<services>
186-
<service id="acme_demo.listener.menu_referrer_listener"
186+
<service id="app.menu_referrer_listener"
187187
class="AppBundle\EventListener\CreateMenuItemFromMenuListener"
188188
>
189189
<argument type="service" id="knp_menu.menu_provider" />
@@ -199,15 +199,16 @@ The service needs to be tagged as event listener:
199199
.. code-block:: php
200200
201201
// app/config/services.php
202+
use AppBundle\EventListener\CreateMenuItemFromMenuListener;
202203
use Symfony\Component\DependencyInjection\Definition;
203204
use Symfony\Component\DependencyInjection\Reference;
204205
205-
$definition = new Definition('AppBundle\EventListener\CreateMenuItemFromMenuListener', array(
206+
$definition = new Definition(CreateMenuItemFromMenuListener::class, [
206207
new Reference('knp_menu.menu_provider'),
207-
));
208-
$definition->addTag('kernel.event_listener', array(
208+
]);
209+
$definition->addTag('kernel.event_listener', [
209210
'event' => 'cmf_menu.create_menu_item_from_node',
210211
'method' => 'onCreateMenuItemFromNode',
211-
));
212+
]);
212213
213-
$container->setDefinition('acme_demo.listener.menu_referrer_listener', $definition);
214+
$container->setDefinition('app.listener.menu_referrer_listener', $definition);

bundles/menu/sonata_admin.rst

Lines changed: 34 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -54,17 +54,17 @@ select the menu node target.
5454
.. code-block:: php
5555
5656
// app/config/config.php
57-
$container->loadFromExtension('cmf_menu', array(
58-
'persistence' => array(
59-
'phpcr' => array(
57+
$container->loadFromExtension('cmf_menu', [
58+
'persistence' => [
59+
'phpcr' => [
6060
// use true/false to force using / not using sonata admin
6161
'use_sonata_admin' => 'auto',
6262
6363
// used with Sonata Admin to manage content; defaults to %cmf_core.basepath%/content
6464
'content_basepath' => null,
65-
),
66-
),
67-
));
65+
],
66+
],
67+
]);
6868
6969
7070
MenuNodeReferrersInterface Sonata Admin Extension
@@ -107,15 +107,17 @@ configuration in the ``sonata_admin`` section of your project configuration:
107107
.. code-block:: php
108108
109109
// app/config/config.php
110-
$container->loadFromExtension('sonata_admin', array(
111-
'extensions' => array(
112-
'cmf_menu.admin_extension.menu_node_referrers' => array(
113-
'implements' => array(
114-
'Symfony\Cmf\Bundle\MenuBundle\Model\MenuNodeReferrersInterface',
115-
),
116-
),
117-
),
118-
));
110+
use Symfony\Cmf\Bundle\MenuBundle\Model\MenuNodeReferrersInterface;
111+
112+
$container->loadFromExtension('sonata_admin', [
113+
'extensions' => [
114+
'cmf_menu.admin_extension.menu_node_referrers' => [
115+
'implements' => [
116+
MenuNodeReferrersInterface::class,
117+
],
118+
],
119+
],
120+
]);
119121
120122
See the `Sonata Admin extension documentation`_ for more information.
121123

@@ -159,15 +161,17 @@ configuration in the ``sonata_admin`` section of your project configuration:
159161
.. code-block:: php
160162
161163
// app/config/config.php
162-
$container->loadFromExtension('sonata_admin', array(
163-
'extensions' => array(
164-
'cmf_menu.admin_extension.menu_options' => array(
165-
'implements' => array(
166-
'Symfony\Cmf\Bundle\MenuBundle\Model\MenuOptionsInterface',
167-
),
168-
),
169-
),
170-
));
164+
use Symfony\Cmf\Bundle\MenuBundle\Model\MenuOptionsInterface;
165+
166+
$container->loadFromExtension('sonata_admin', [
167+
'extensions' => [
168+
'cmf_menu.admin_extension.menu_options' => [
169+
'implements' => [
170+
MenuOptionsInterface::class,
171+
],
172+
],
173+
],
174+
]);
171175
172176
See the `Sonata Admin extension documentation`_ for more information.
173177

@@ -231,13 +235,13 @@ configuration:
231235
.. code-block:: php
232236
233237
// app/config/config.php
234-
$container->loadFromExtension('cmf_menu', array(
235-
'admin_extensions' => array(
236-
'menu_options' => array(
238+
$container->loadFromExtension('cmf_menu', [
239+
'admin_extensions' => [
240+
'menu_options' => [
237241
'advanced' => true,
238-
),
239-
),
240-
));
242+
],
243+
],
244+
]);
241245
242246
.. _`Sonata Admin extension documentation`: https://sonata-project.org/bundles/admin/master/doc/reference/extensions.html
243247
.. _SonataDoctrinePHPCRAdminBundle: https://sonata-project.org/bundles/doctrine-phpcr-admin/master/doc/index.html

bundles/menu/voters.rst

Lines changed: 26 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,7 @@ setting to your configuration. Example config:
5050

5151
.. code-block:: yaml
5252
53+
# app/config/config.yml
5354
cmf_menu:
5455
voters:
5556
content_identity:
@@ -58,6 +59,7 @@ setting to your configuration. Example config:
5859
5960
.. code-block:: xml
6061
62+
<!-- app/config/config.xml -->
6163
<?xml version="1.0" encoding="UTF-8" ?>
6264
<container xmlns="http://symfony.com/schema/dic/services">
6365
<config xmlns="http://cmf.symfony.com/schema/dic/menu">
@@ -69,14 +71,15 @@ setting to your configuration. Example config:
6971
7072
.. code-block:: php
7173
72-
$container->loadFromExtension('cmf_menu', array(
73-
'voters' => array(
74-
'content_identity' => array(
74+
// app/config/config.php
75+
$container->loadFromExtension('cmf_menu', [
76+
'voters' => [
77+
'content_identity' => [
7578
'enabled' => true,
7679
'content_key' => 'myKey',
77-
),
78-
),
79-
));
80+
],
81+
],
82+
]);
8083
8184
.. note::
8285

@@ -107,7 +110,7 @@ article which can be reached at ``/articles/computers/laptops/acme/A200``::
107110

108111
use Symfony\Cmf\Bundle\RoutingBundle\Doctrine\Phpcr\Route;
109112
use Symfony\Cmf\Bundle\MenuBundle\Doctrine\Phpcr\MenuItem;
110-
use Acme\FooBundle\Document\Article;
113+
use AppBundle\Document\Article;
111114

112115
$dm = ...; // get an instance of the document manager
113116

@@ -162,11 +165,11 @@ configuration.
162165
.. code-block:: php
163166
164167
// app/config/config.php
165-
$container->loadFromExtension('cmf_menu', array(
166-
'voters' => array(
168+
$container->loadFromExtension('cmf_menu', [
169+
'voters' => [
167170
'uri_prefix' => true,
168-
),
169-
));
171+
],
172+
]);
170173
171174
RequestParentContentIdentityVoter
172175
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
@@ -206,11 +209,11 @@ voters (see below), except you do not need to write your own PHP code:
206209
207210
# app/config/services.yml
208211
services:
209-
my_bundle.menu_voter.parent:
212+
app.menu_voter_parent:
210213
class: Symfony\Cmf\Bundle\MenuBundle\Voter\RequestParentContentIdentityVoter
211214
arguments:
212215
- contentDocument
213-
- '%my_bundle.my_model_class%'
216+
- AppBundle\Document\Article
214217
tags:
215218
- { name: "knp_menu.voter", request: true }
216219
@@ -223,10 +226,10 @@ voters (see below), except you do not need to write your own PHP code:
223226
xsi:schemaLocation="http://symfony.com/schema/dic/services http://symfony.com/schema/dic/services/services-1.0.xsd">
224227
225228
<services>
226-
<service id="my_bundle.menu_voter.parent"
229+
<service id="app.menu_voter_parent"
227230
class="Symfony\Cmf\Bundle\MenuBundle\Voter\RequestParentContentIdentityVoter">
228231
<argument>contentDocument</argument>
229-
<argument>%my_bundle.my_model_class%</argument>
232+
<argument>AppBundle\Document\Article</argument>
230233
231234
<tag name="knp_menu.voter" request="true"/>
232235
</service>
@@ -236,22 +239,24 @@ voters (see below), except you do not need to write your own PHP code:
236239
.. code-block:: php
237240
238241
// app/config/services.php
242+
use AppBundle\Document\Article;
243+
use Symfony\Cmf\Bundle\MenuBundle\Voter\RequestParentContentIdentityVoter;
239244
use Symfony\Component\DependencyInjection\Definition;
240245
241246
$definition = new Definition(
242-
'Symfony\Cmf\Bundle\MenuBundle\Voter\RequestParentContentIdentityVoter',
243-
array('contentDocument', '%my_bundle.my_model_class%')
247+
RequestParentContentIdentityVoter,
248+
['contentDocument', Article::class]
244249
));
245-
$definition->addMethodCall('setRequest', array(
250+
$definition->addMethodCall('setRequest', [
246251
new Reference(
247252
'request',
248253
ContainerInterface::NULL_ON_INVALID_REFERENCE,
249254
false
250255
)
251-
));
252-
$definition->addTag('knp_menu.voter', array('request' => true));
256+
]);
257+
$definition->addTag('knp_menu.voter', ['request' => true]);
253258
254-
$container->setDefinition('my_bundle.menu_voter.parent', $definition);
259+
$container->setDefinition('app.menu_voter_parent', $definition);
255260
256261
.. _bundles_menu_voters_custom_voter:
257262

0 commit comments

Comments
 (0)