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

[menu-bundle] change doc to best practices #797

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
53 changes: 26 additions & 27 deletions bundles/menu/configuration.rst
Original file line number Diff line number Diff line change
Expand Up @@ -64,9 +64,9 @@ persistence configuration has the following configuration:
.. code-block:: php

// app/config/config.php
$container->loadFromExtension('cmf_menu', array(
'persistence' => array(
'phpcr' => array(
$container->loadFromExtension('cmf_menu', [
'persistence' => [
'phpcr' => [
'enabled' => false,
'menu_basepath' => '/cms/menu',
'content_basepath' => null,
Expand All @@ -78,9 +78,9 @@ persistence configuration has the following configuration:
'menu_admin_class' => null,
'node_admin_class' => null,
'admin_recursive_breadcrumbs' => true,
),
),
));
],
],
]);

``enabled``
"""""""""""
Expand Down Expand Up @@ -244,15 +244,14 @@ You can configure the menu options extension in this sections.
.. code-block:: php

// app/config/config.php
$container->loadFromExtension('cmf_menu', array(
'admin_extensions' => array(
'menu_options' => array(
'enabled' => 'auto',
'advanced' => false,
),
),
),
));
$container->loadFromExtension('cmf_menu', [
'admin_extensions' => [
'menu_options' => [
'enabled' => 'auto',
'advanced' => false,
],
],
]);

``enabled``
"""""""""""
Expand Down Expand Up @@ -303,16 +302,16 @@ The ``voters`` section enables you to enable and configure *pre-defined*
.. code-block:: php

// app/config/config.php
$container->loadFromExtension('cmf_menu', array(
'persistence' => array(
'voters' => array(
'content_identity' => array(
$container->loadFromExtension('cmf_menu', [
'persistence' => [
'voters' => [
'content_identity' => [
'content_key' => null,
),
],
'uri_prefix' => false,
),
),
));
],
],
]);

``content_identity``
~~~~~~~~~~~~~~~~~~~~
Expand Down Expand Up @@ -382,8 +381,8 @@ To disable the menu content voter, use:
.. code-block:: php

// app/config/config.php
$container->loadFromExtension('cmf_core', array(
'publish_workflow' => array(
$container->loadFromExtension('cmf_core', [
'publish_workflow' => [
'enabled' => false,
),
));
],
]);
4 changes: 2 additions & 2 deletions bundles/menu/introduction.rst
Original file line number Diff line number Diff line change
Expand Up @@ -36,11 +36,11 @@ bundles in addition to the CmfMenuBundle::
{
public function registerBundles()
{
$bundles = array(
$bundles = [
// ...
new Knp\Bundle\MenuBundle\KnpMenuBundle(),
new Symfony\Cmf\Bundle\MenuBundle\CmfMenuBundle(),
);
];

// ...
}
Expand Down
12 changes: 6 additions & 6 deletions bundles/menu/menu_documents.rst
Original file line number Diff line number Diff line change
Expand Up @@ -31,26 +31,26 @@ the KnpMenu component documentation for more information.
// Attributes are the HTML attributes of the DOM element representing the
// menu node (e.g. <li/>)
$node->setAttribute('attr_name', 'attr_value');
$node->setAttributes(array('attr_name', 'attr_value'));
$node->setChildrenAttributes(array('attr_name', 'attr_value'));
$node->setAttributes(['attr_name', 'attr_value']);
$node->setChildrenAttributes(['attr_name', 'attr_value']);

// Display the node or not
$node->setDisplay(true);
$node->setDisplayChildren(true);

// Any extra attributes you wish to associate with the menu node
$node->setExtras(array('extra_param_1' => 'value'));
$node->setExtras(['extra_param_1' => 'value']);

// The label and the HTML attributes of the label
$node->setLabel('Menu Node');
$node->setLabelAttributes(array('style' => 'color: red;'));
$node->setLabelAttributes(['style' => 'color: red;']);

// The HTML attributes of the link (i.e. <a href=.../>
$node->setLinkAttributes(array('style' => 'color: yellow;'));
$node->setLinkAttributes(['style' => 'color: yellow;']);

// Specify a route name to use and the parameters to use with it
$node->setRoute('my_hard_coded_route_name');
$node->setRouteParameters(array());
$node->setRouteParameters([]);

// Specify if the route should be rendered absolute (otherwise relative)
$node->setRouteAbsolute(true);
Expand Down
12 changes: 6 additions & 6 deletions bundles/menu/menu_factory.rst
Original file line number Diff line number Diff line change
Expand Up @@ -183,7 +183,7 @@ The service needs to be tagged as event listener:
<container xmlns="http://symfony.com/schema/dic/services">

<services>
<service id="acme_demo.listener.menu_referrer_listener"
<service id="app.menu_referrer_listener"
class="AppBundle\EventListener\CreateMenuItemFromMenuListener"
>
<argument type="service" id="knp_menu.menu_provider" />
Expand All @@ -202,12 +202,12 @@ The service needs to be tagged as event listener:
use Symfony\Component\DependencyInjection\Definition;
use Symfony\Component\DependencyInjection\Reference;

$definition = new Definition('AppBundle\EventListener\CreateMenuItemFromMenuListener', array(
$definition = new Definition('AppBundle\EventListener\CreateMenuItemFromMenuListener', [
new Reference('knp_menu.menu_provider'),
));
$definition->addTag('kernel.event_listener', array(
]);
$definition->addTag('kernel.event_listener', [
'event' => 'cmf_menu.create_menu_item_from_node',
'method' => 'onCreateMenuItemFromNode',
));
]);

$container->setDefinition('acme_demo.listener.menu_referrer_listener', $definition);
$container->setDefinition('app.listener.menu_referrer_listener', $definition);
64 changes: 34 additions & 30 deletions bundles/menu/sonata_admin.rst
Original file line number Diff line number Diff line change
Expand Up @@ -54,17 +54,17 @@ select the menu node target.
.. code-block:: php

// app/config/config.php
$container->loadFromExtension('cmf_menu', array(
'persistence' => array(
'phpcr' => array(
$container->loadFromExtension('cmf_menu', [
'persistence' => [
'phpcr' => [
// use true/false to force using / not using sonata admin
'use_sonata_admin' => 'auto',

// used with Sonata Admin to manage content; defaults to %cmf_core.basepath%/content
'content_basepath' => null,
),
),
));
],
],
]);


MenuNodeReferrersInterface Sonata Admin Extension
Expand Down Expand Up @@ -107,15 +107,17 @@ configuration in the ``sonata_admin`` section of your project configuration:
.. code-block:: php

// app/config/config.php
$container->loadFromExtension('sonata_admin', array(
'extensions' => array(
'cmf_menu.admin_extension.menu_node_referrers' => array(
'implements' => array(
'Symfony\Cmf\Bundle\MenuBundle\Model\MenuNodeReferrersInterface',
),
),
),
));
use Symfony\Cmf\Bundle\MenuBundle\Model\MenuNodeReferrersInterface;

$container->loadFromExtension('sonata_admin', [
'extensions' => [
'cmf_menu.admin_extension.menu_node_referrers' => [
'implements' => [
MenuNodeReferrersInterface::class,
],
],
],
]);

See the `Sonata Admin extension documentation`_ for more information.

Expand Down Expand Up @@ -159,15 +161,17 @@ configuration in the ``sonata_admin`` section of your project configuration:
.. code-block:: php

// app/config/config.php
$container->loadFromExtension('sonata_admin', array(
'extensions' => array(
'cmf_menu.admin_extension.menu_options' => array(
'implements' => array(
'Symfony\Cmf\Bundle\MenuBundle\Model\MenuOptionsInterface',
),
),
),
));
use Symfony\Cmf\Bundle\MenuBundle\Model\MenuOptionsInterface;

$container->loadFromExtension('sonata_admin', [
'extensions' => [
'cmf_menu.admin_extension.menu_options' => [
'implements' => [
MenuOptionsInterface::class,
],
],
],
]);

See the `Sonata Admin extension documentation`_ for more information.

Expand Down Expand Up @@ -231,13 +235,13 @@ configuration:
.. code-block:: php

// app/config/config.php
$container->loadFromExtension('cmf_menu', array(
'admin_extensions' => array(
'menu_options' => array(
$container->loadFromExtension('cmf_menu', [
'admin_extensions' => [
'menu_options' => [
'advanced' => true,
),
),
));
],
],
]);

.. _`Sonata Admin extension documentation`: https://sonata-project.org/bundles/admin/master/doc/reference/extensions.html
.. _SonataDoctrinePHPCRAdminBundle: https://sonata-project.org/bundles/doctrine-phpcr-admin/master/doc/index.html
Expand Down
47 changes: 26 additions & 21 deletions bundles/menu/voters.rst
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ setting to your configuration. Example config:

.. code-block:: yaml

# app/config/config.yml
cmf_menu:
voters:
content_identity:
Expand All @@ -59,6 +60,7 @@ setting to your configuration. Example config:
.. code-block:: xml

<?xml version="1.0" encoding="UTF-8" ?>
<!-- app/config/config.xml -->
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

should be the first line

<container xmlns="http://symfony.com/schema/dic/services">
<config xmlns="http://cmf.symfony.com/schema/dic/menu">
<voters>
Expand All @@ -69,14 +71,15 @@ setting to your configuration. Example config:

.. code-block:: php

$container->loadFromExtension('cmf_menu', array(
'voters' => array(
'content_identity' => array(
// app/config/config.php
$container->loadFromExtension('cmf_menu', [
'voters' => [
'content_identity' => [
'enabled' => true,
'content_key' => 'myKey',
),
),
));
],
],
]);

.. note::

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

use Symfony\Cmf\Bundle\RoutingBundle\Doctrine\Phpcr\Route;
use Symfony\Cmf\Bundle\MenuBundle\Doctrine\Phpcr\MenuItem;
use Acme\FooBundle\Document\Article;
use AppBundle\Document\Article;

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

Expand Down Expand Up @@ -162,11 +165,11 @@ configuration.
.. code-block:: php

// app/config/config.php
$container->loadFromExtension('cmf_menu', array(
'voters' => array(
$container->loadFromExtension('cmf_menu', [
'voters' => [
'uri_prefix' => true,
),
));
],
]);

RequestParentContentIdentityVoter
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Expand Down Expand Up @@ -206,11 +209,11 @@ voters (see below), except you do not need to write your own PHP code:

# app/config/services.yml
services:
my_bundle.menu_voter.parent:
app.menu_voter_parent:
class: Symfony\Cmf\Bundle\MenuBundle\Voter\RequestParentContentIdentityVoter
arguments:
- contentDocument
- '%my_bundle.my_model_class%'
- AppBundle\Document\Article
tags:
- { name: "knp_menu.voter", request: true }

Expand All @@ -223,10 +226,10 @@ voters (see below), except you do not need to write your own PHP code:
xsi:schemaLocation="http://symfony.com/schema/dic/services http://symfony.com/schema/dic/services/services-1.0.xsd">

<services>
<service id="my_bundle.menu_voter.parent"
<service id="app.menu_voter_parent"
class="Symfony\Cmf\Bundle\MenuBundle\Voter\RequestParentContentIdentityVoter">
<argument>contentDocument</argument>
<argument>%my_bundle.my_model_class%</argument>
<argument>AppBundle\Document\Article</argument>

<tag name="knp_menu.voter" request="true"/>
</service>
Expand All @@ -236,22 +239,24 @@ voters (see below), except you do not need to write your own PHP code:
.. code-block:: php

// app/config/services.php
use AppBundle\Document\Article;
use Symfony\Cmf\Bundle\MenuBundle\Voter\RequestParentContentIdentityVoter;
use Symfony\Component\DependencyInjection\Definition;

$definition = new Definition(
'Symfony\Cmf\Bundle\MenuBundle\Voter\RequestParentContentIdentityVoter',
array('contentDocument', '%my_bundle.my_model_class%')
RequestParentContentIdentityVoter,
['contentDocument', Article::class]
));
$definition->addMethodCall('setRequest', array(
$definition->addMethodCall('setRequest', [
new Reference(
'request',
ContainerInterface::NULL_ON_INVALID_REFERENCE,
false
)
));
$definition->addTag('knp_menu.voter', array('request' => true));
]);
$definition->addTag('knp_menu.voter', ['request' => true]);

$container->setDefinition('my_bundle.menu_voter.parent', $definition);
$container->setDefinition('app.menu_voter_parent', $definition);

.. _bundles_menu_voters_custom_voter:

Expand Down