parameters:
    oro_menu.entity.menu_item.class: Oro\Bundle\MenuBundle\Entity\MenuItem

services:
    oro_menu.cache.item:
        public: false
        parent: oro.cache.abstract
        calls:
            - [ setNamespace, [ 'oro_menu_item' ] ]

    oro_menu.form.type.menu_item:
        class: 'Oro\Bundle\MenuBundle\Form\Type\MenuItemType'
        calls:
            - [setDataClass, ['%oro_menu.entity.menu_item.class%']]
        tags:
            - { name: form.type, alias: oro_menu_item }

    oro_menu.tree.menu_item_tree_handler:
        class: 'Oro\Bundle\MenuBundle\JsTree\MenuItemTreeHandler'
        arguments:
            - '%oro_menu.entity.menu_item.class%'
            - "@doctrine"
            - "@oro_menu.menu_provider"

    oro_menu.entity.menu_item_manager:
        class: 'Oro\Bundle\MenuBundle\Entity\Manager\MenuItemManager'

    oro_menu.menu.factory:
        class: 'Knp\Menu\MenuFactory'
        calls:
            - [ addExtension, [ "@oro_menu.menu.feature_extension" ] ]
            - [ addExtension, [ "@oro_menu.menu.acl_extension" ] ]
            - [ addExtension, [ "@oro_menu.menu.condition.condition_extension" ] ]

    oro_menu.menu.database_builder:
        class: 'Oro\Bundle\MenuBundle\Menu\DatabaseBuilder'
        public: false
        arguments:
            - "@doctrine"
            - "@oro_menu.menu.factory"

    oro_menu.twig.menu_item_extension:
        class: 'Oro\Bundle\MenuBundle\Twig\MenuItemExtension'
        public: false
        arguments:
            - "@oro_menu.tree.menu_item_tree_handler"
            - '@knp_menu.matcher'
        tags:
            - { name: twig.extension }

    oro_menu.menu_array_loader:
        class: Knp\Menu\Loader\ArrayLoader
        public: false
        arguments:
            - "@oro_menu.menu.factory"

    oro_menu.menu_manipulator:
        class: Knp\Menu\Util\MenuManipulator
        public: false

    oro_menu.menu_serializer:
        class: 'Oro\Bundle\MenuBundle\Menu\MenuSerializer'
        public: false
        arguments:
            - "@oro_menu.menu_array_loader"
            - "@oro_menu.menu_manipulator"

    oro_menu.menu_provider:
        class: 'Oro\Bundle\MenuBundle\Menu\DatabaseMenuProvider'
        public: false
        arguments:
            - "@oro_menu.menu.database_builder"
            - "@oro_locale.helper.localization"
            - "@oro_menu.menu_serializer"
            - "@doctrine"
        calls:
            - [setEntityClass, ['%oro_menu.entity.menu_item.class%']]
            - [setCache, ["@oro_menu.cache.item"]]

    oro_menu.menu_provider.link:
        public: false
        tags:
            - { name: oro_service_link,  service: oro_menu.menu_provider }

    oro_menu.menu.condition.condition_extension:
        class: 'Oro\Bundle\MenuBundle\Menu\Condition\ConditionExtension'
        public: false

    oro_menu.menu.condition.config_value_expression_language_provider:
        class: 'Oro\Bundle\MenuBundle\Menu\Condition\ConfigValueExpressionLanguageProvider'
        public: false
        arguments:
            - "@oro_config.manager"
        tags:
            - { name: oro_menu.condition.expression_language_provider, alias: config_value }

    oro_menu.menu.condition.logged_in_expression_language_provider:
        class: 'Oro\Bundle\MenuBundle\Menu\Condition\LoggedInExpressionLanguageProvider'
        public: false
        arguments:
            - "@oro_security.security_facade.link"
        tags:
            - { name: oro_menu.condition.expression_language_provider, alias: is_logged_in }

    oro_menu.event_listener.orm.menu_item_cache_listener:
        class: Oro\Bundle\MenuBundle\Entity\Listener\MenuItemListener
        public: false
        arguments:
            - "@oro_menu.menu_provider.link"
        tags:
            - { name: doctrine.orm.entity_listener } #todo: add entity and event keys https://magecore.atlassian.net/browse/BB-1289

    oro_menu.event_listener.localization_listener:
        class: Oro\Bundle\MenuBundle\EventListener\LocalizationListener
        public: false
        arguments:
            - "@oro_menu.menu_provider.link"
        tags:
            - { name: doctrine.event_listener, event: postPersist }
            - { name: doctrine.event_listener, event: postUpdate }
            - { name: doctrine.event_listener, event: postRemove }

    oro_menu.event_listener.menu_item_form_handler_listener:
        class: Oro\Bundle\MenuBundle\EventListener\MenuItemFormHandlerListener
        arguments:
            - "@oro_menu.menu_provider"
        tags:
            - { name: kernel.event_listener, event: oro.form.update_handler.after_entity_flush.oro_menu_item,  method: afterEntityFlush }

    oro_menu.menu.acl_extension:
        class: 'Oro\Bundle\NavigationBundle\Menu\AclAwareMenuFactoryExtension'
        public: false
        arguments:
            - "@router"
            - "@oro_security.security_facade.link"
        calls:
            - [ setCache, [ "@oro_menu.cache" ] ]
            - [ setHideAllForNotLoggedInUsers, [ false ] ]

    oro_menu.menu.feature_extension:
        class: 'Oro\Bundle\NavigationBundle\Menu\FeatureAwareMenuFactoryExtension'
        public: false
        arguments:
            - '@oro_featuretoggle.checker.feature_checker'

    oro_menu.cache.warmer.item:
        public: false
        class: Oro\Bundle\MenuBundle\Cache\CacheWarmer
        arguments:
            - "@oro_entity.doctrine_helper"
            - "@oro_menu.menu_provider"
        calls:
            - [setEntityClass, ['%oro_menu.entity.menu_item.class%']]
        tags:
            - { name: kernel.cache_warmer }

    oro_menu.layout.data_provider.menu:
        class: 'Oro\Bundle\MenuBundle\Layout\DataProvider\MenuProvider'
        arguments:
            - "@oro_menu.menu_provider"
        tags:
            - { name: layout.data_provider, alias: menu }
