services:
    # Listener doctrine for node modifications
    umanit.tree.doctrine.node_listener:
        alias: Umanit\Bundle\TreeBundle\Doctrine\Listener\DoctrineTreeNodeListener
        public: true
    Umanit\Bundle\TreeBundle\Doctrine\Listener\DoctrineTreeNodeListener:
        arguments:
            - '@umanit.tree.node_helper'
        tags:
            - { name: 'doctrine.event_listener', event: postUpdate, priority: -10}
            - { name: 'doctrine.event_listener', event: postPersist, priority: -10 }
            - { name: 'doctrine.event_listener', event: preRemove, priority: -10 }
            - { name: 'doctrine.event_listener', event: postFlush, priority: -10 }

    # Listener doctrine for node modifications
    umanit.tree.doctrine.node_history_listener:
        alias: Umanit\Bundle\TreeBundle\Doctrine\Listener\DoctrineNodeHistoryListener
        public: true
    Umanit\Bundle\TreeBundle\Doctrine\Listener\DoctrineNodeHistoryListener:
        arguments:
            - '%umanit_tree.locale%'
        tags:
            - { name: 'doctrine.event_listener', event: postUpdate, priority: -20 }
            - { name: 'doctrine.event_listener', event: postPersist, priority: -20 }
            - { name: 'doctrine.event_listener', event: postRemove, priority: -20 }
            - { name: 'doctrine.event_listener', event: postFlush, priority: -20 }

    # Listener to redirect to the right controller
    umanit.tree.listener.route_listener:
        alias: Umanit\Bundle\TreeBundle\Listener\RouteListener
        public: true
    Umanit\Bundle\TreeBundle\Listener\RouteListener:
        arguments:
            - '@doctrine'
            - '%umanit_tree.node_types%'
            - '%umanit_tree.locale%'
        tags:
            - { name: 'kernel.event_listener', event: 'kernel.request', priority: -10 }

    # Router for nodes
    umanit.tree.router:
        alias: Umanit\Bundle\TreeBundle\Router\NodeRouter
        public: true
    Umanit\Bundle\TreeBundle\Router\NodeRouter:
        arguments:
            - '@doctrine'
            - '@router'
            - '@request_stack'

    # Helpers twig for links
    umanit.tree.twig.extension.link:
        alias: Umanit\Bundle\TreeBundle\Twig\Extension\LinkExtension
        public: true
    Umanit\Bundle\TreeBundle\Twig\Extension\LinkExtension:
        arguments:
            - '@umanit.tree.router'
            - '@doctrine.orm.entity_manager'
        tags:
            - { name: 'twig.extension' }

    # Helpers twig for SEO
    umanit.tree.twig.extension.seo:
        alias: Umanit\Bundle\TreeBundle\Twig\Extension\SeoExtension
        public: true
    Umanit\Bundle\TreeBundle\Twig\Extension\SeoExtension:
        arguments:
            - '@request_stack'
            - '@translator.default'
            - '@umanit.tree.excerpt'
            - '@umanit.tree.title'
            - '%umanit_tree.seo%'
        tags:
            - { name: 'twig.extension' }

    # Helpers twig for SEO
    umanit.tree.twig.extension.breadcrumb:
        alias: Umanit\Bundle\TreeBundle\Twig\Extension\BreadcrumbExtension
        public: true
    Umanit\Bundle\TreeBundle\Twig\Extension\BreadcrumbExtension:
        arguments:
            - '@request_stack'
            - '@translator.default'
            - '%umanit_tree.breadcrumb%'
            - '@umanit.tree.router'
            - '@doctrine'
        tags:
            - { name: 'twig.extension' }

    # Helper for nodes
    umanit.tree.node_helper:
        alias: Umanit\Bundle\TreeBundle\Helper\NodeHelper
        public: true
    Umanit\Bundle\TreeBundle\Helper\NodeHelper:
        arguments:
            - '%umanit_tree.locale%'
            - '@doctrine'
            - '@event_dispatcher'

    # Excerpt
    umanit.tree.excerpt:
        alias: Umanit\Bundle\TreeBundle\Helper\Excerpt
        public: true
    Umanit\Bundle\TreeBundle\Helper\Excerpt:
        arguments:
            - '@property_accessor'

    # Title
    umanit.tree.title:
        alias: Umanit\Bundle\TreeBundle\Helper\Title
        public: true
    Umanit\Bundle\TreeBundle\Helper\Title:
        arguments:
            - '@property_accessor'

    # Link form type
    umanit.tree.form.type.link:
        alias: Umanit\Bundle\TreeBundle\Form\Type\LinkType
        public: true
    Umanit\Bundle\TreeBundle\Form\Type\LinkType:
        arguments:
            - '@doctrine'
            - '@translator.default'
        tags:
            - { name: 'form.type', alias: umanit_link_type }

    # node form type
    umanit.tree.form.type.node:
        alias: Umanit\Bundle\TreeBundle\Form\Type\TreeNodeType
        public: true
    Umanit\Bundle\TreeBundle\Form\Type\TreeNodeType:
        calls:
            - ['setDoctrine', ['@doctrine']]
            - ['setTranslator', ['@translator.default']]
        tags:
            - { name: 'form.type', alias: umanit_seo_metadata_type }

    # node form type
    umanit.tree.form.type.seo_metadata:
        alias: Umanit\Bundle\TreeBundle\Form\Type\SeoMetadataType
        public: true
    Umanit\Bundle\TreeBundle\Form\Type\SeoMetadataType:
        arguments:
            - '@umanit.tree.router'
            - '@umanit.tree.excerpt'
            - '@umanit.tree.title'
            - '@translator'
            - '%umanit_tree.seo%'
        tags:
            - { name: 'form.type', alias: umanit_node_type }

    # Menu form type
    umanit.tree.form.menu_type:
        class: '%umanit_tree.menu_form_class%'
        arguments:
            - '@doctrine.orm.entity_manager'
            - '%umanit_tree.node_types%'
            - '%umanit_tree.menu_entity_class%'
            - '%umanit_tree.menus%'
        tags:
            - { name: form.type, alias: umanit_tree_menu_type }

    # Menu builder
    umanit.tree.meny.menu_menu_builder:
        alias: Umanit\Bundle\TreeBundle\Menu\MenuBuilder
        public: true
    Umanit\Bundle\TreeBundle\Menu\MenuBuilder:
        arguments:
            - '@doctrine.orm.entity_manager'
            - '%umanit_tree.menu_entity_class%'

    # Menu injector
    umanit.tree.event_subscriber.menu_injector_subscriber:
        alias: Umanit\Bundle\TreeBundle\EventSubscriber\MenuInjectorSubscriber
        public: true
    Umanit\Bundle\TreeBundle\EventSubscriber\MenuInjectorSubscriber:
        arguments:
            - '@twig'
            - '@umanit.tree.meny.menu_menu_builder'
        tags: ['kernel.event_subscriber']

    # Menu builder for sonata
    umanit.tree.event_subscriber.sonata_menu_builder_subscriber:
        alias: Umanit\Bundle\TreeBundle\EventSubscriber\SonataMenuBuilderSubscriber
        public: true
    Umanit\Bundle\TreeBundle\EventSubscriber\SonataMenuBuilderSubscriber:
        arguments:
            - '%umanit_tree.menu_entity_class%'
            - '@security.authorization_checker'
        tags: ['kernel.event_subscriber']

    # Twig configuration extension
    umanit.tree.twig.extension.configuration_extension:
        alias: Umanit\Bundle\TreeBundle\Twig\Extension\ConfigurationExtension
        public: true
    Umanit\Bundle\TreeBundle\Twig\Extension\ConfigurationExtension:
        arguments: ['%umanit_tree.admin_layout%']
        tags:
            - { name: 'twig.extension' }

    umanit_bundle_tree.security.menu_voter:
        alias: Umanit\Bundle\TreeBundle\Security\MenuVoter
        public: true
    Umanit\Bundle\TreeBundle\Security\MenuVoter:
        arguments:
            - '%umanit_tree.menus_roles%'
        tags:
            - { name: security.voter }
