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

Latest commit

 

History

History
144 lines (118 loc) · 2.99 KB

UPGRADE-2.0.md

File metadata and controls

144 lines (118 loc) · 2.99 KB

Upgrade from 1.2 to 2.0

Factory

  • The ContentAwareFactory and with it the cmf_menu.factory service are removed. The knp_menu.factory service is now extended instead:

    Before

    services:
        menu_builder:
            class: AppBundle\Menu\MenuBuilder
            arguments: ["@cmf_menu.factory"]

    After

    services:
       menu_builder:
           class: AppBundle\Menu\MenuBuilder
           arguments: ["@knp_menu.factory"]
  • The loadFromNode and loadFromArrays are removed from the factory, use the NodeLoader or ArrayLoader instead:

    Before

    $menuFactory->loadFromNode(...);

    After

    // the node loader is available as the cmf_menu.loader.node service
    $nodeLoader->load(...);

Voters

  • The cmf_menu.voter tag has been removed in favor of knp_menu.voter:

    Before

    services:
        menu_voter:
            class: AppBundle\Menu\Voter\CurrentUrlVoter
            tags:
                - { name: cmf_menu.voter }

    After

    services:
        menu_voter:
            class: AppBundle\Menu\Voter\CurrentUrlVoter
            tags:
                - { name: knp_menu.voter }
  • Voters needing the master requests can now set the request option of the knp_menu.voter tag:

    Before

    services:
        request_menu_voter:
            class: AppBundle\Menu\Voter\RequestVoter
            calls:
                - [setRequest, ["@?request="]]
            tags:
                - { name: cmf_menu.voter }

    After

    services:
        request_menu_voter:
            class: AppBundle\Menu\Voter\RequestVoter
            tags:
                - { name: knp_menu.voter, request: true }
  • The Symfony\Cmf\Bundle\MenuBundle\Voter\VoterInterface is removed in favor of Knp\Menu\Matcher\Voter\VoterInterface:

    Before

    // ...
    use Symfony\Cmf\Bundle\MenuBundle\Voter\VoterInterface;
    
    class CustomVoter implements VoterInterface
    {
        public function matchItem(ItemInterface $item = null)
        {
            // ...
        }
    }

    After

    // ...
    use Knp\Menu\Matcher\Voter\VoterInterface;
    
    class CustomVoter implements VoterInterface
    {
        public function matchItem(ItemInterface $item = null)
        {
            // ...
        }
    }

CreateMenuItemFromNodeEvent

  • The event has no longer access to the menu factory:

    Before

    class CreateMenuItemFromNodeListener
    {
        public function onEvent(CreateMenuItemFromNodeEvent $event)
        {
            $event->getFactory()->createItem(...);
        }
    }

    After

    use Knp\Menu\FactoryInterface;
    
    class CreateMenuItemFromNodeListener
    {
        private $factory;
    
        // factory is available as the knp_menu.factory service
        public function __construct(FactoryInterface $factory)
        {
            $this->factory = $factory;
        }
    
        public function onEvent(CreateMenuItemFromNodeEvent $event)
        {
            $this->factory->createItem(...);
        }
    }