services:
    oro_organization.form.business_unit:
        class: Symfony\Component\Form\Form
        public: true
        factory: ['@form.factory', createNamed]
        arguments:
            - oro_business_unit_form
            - Oro\Bundle\OrganizationBundle\Form\Type\BusinessUnitType

    oro_organization.form.type.business_unit:
        class: Oro\Bundle\OrganizationBundle\Form\Type\BusinessUnitType
        arguments:
            - '@oro_organization.business_unit_manager'
            - '@oro_security.token_accessor'
        tags:
            - { name: form.type, alias: oro_business_unit }

    oro_organization.form.type.business_unit.api:
        class: Oro\Bundle\OrganizationBundle\Form\Type\BusinessUnitApiType
        arguments:
            - '@oro_organization.business_unit_manager'
            - '@oro_security.token_accessor'
        tags:
            - { name: form.type, alias: business_unit }

    oro_organization.form.handler.business_unit:
        class: Oro\Bundle\OrganizationBundle\Form\Handler\BusinessUnitHandler
        public: true
        arguments:
            - '@oro_organization.form.business_unit'
            - '@request_stack'
            - '@doctrine.orm.entity_manager'
            - '@oro_security.ownership_tree_provider.chain'

    oro_organization.form.type.business_unit_tree_type:
        class: Oro\Bundle\OrganizationBundle\Form\Type\BusinessUnitTreeType
        arguments:
            - '@oro_organization.business_unit_manager'
        tags:
            - { name: form.type, alias: oro_business_unit_tree }

    oro_organization.form.type.business_unit_tree_select_type:
        class: Oro\Bundle\OrganizationBundle\Form\Type\BusinessUnitTreeSelectType
        tags:
            - { name: form.type, alias: oro_business_unit_tree_select }

    oro_organization.form.business_unit.api:
        class: Symfony\Component\Form\Form
        public: true
        factory: ['@form.factory', createNamed]
        arguments: ["business_unit", Oro\Bundle\OrganizationBundle\Form\Type\BusinessUnitApiType, null]

    oro_organization.form.handler.business_unit.api:
        class: Oro\Bundle\OrganizationBundle\Form\Handler\BusinessUnitHandler
        public: true
        arguments:
            - '@oro_organization.form.business_unit.api'
            - '@request_stack'
            - '@doctrine.orm.entity_manager'
            - '@oro_security.ownership_tree_provider.chain'

    oro_organization.form.type.business_unit_select:
        class: Oro\Bundle\OrganizationBundle\Form\Type\BusinessUnitSelectType
        arguments:
            - '@doctrine'
            - '@oro_security.token_accessor'
        tags:
            - { name: form.type, alias: oro_business_unit_select }

    oro_organization.form.type.business_unit_select_autocomplete:
        class: Oro\Bundle\OrganizationBundle\Form\Type\BusinessUnitSelectAutocomplete
        arguments:
            - '@doctrine.orm.entity_manager'
            - 'Oro\Bundle\OrganizationBundle\Entity\BusinessUnit'
            - '@oro_organization.business_unit_manager'
        tags:
            - { name: form.type, alias: "oro_type_business_unit_select_autocomplete" }

    oro_organization.form.type.organization:
        class: Oro\Bundle\OrganizationBundle\Form\Type\OrganizationType
        arguments:
            - '@oro_security.token_accessor'
        tags:
            - { name: form.type, alias: oro_organization }

    oro_organization.form.handler.organization:
        class: Oro\Bundle\OrganizationBundle\Form\Handler\OrganizationHandler
        arguments:
            - '@request_stack'
            - '@doctrine.orm.entity_manager'

    Oro\Bundle\OrganizationBundle\Form\Handler\OrganizationHandler:
        alias: oro_organization.form.handler.organization

    oro_organization.form.type.organization_select:
        class: Oro\Bundle\OrganizationBundle\Form\Type\OrganizationSelectType
        tags:
            - { name: form.type, alias: oro_organization_select }

    oro_organization.form.type.organizations_select:
        class: Oro\Bundle\OrganizationBundle\Form\Type\OrganizationsSelectType
        arguments:
            - '@oro_organization.business_unit_manager'
            - '@oro_security.token_accessor'
        tags:
            - { name: form.type, alias: oro_organizations_select }

    oro_organization.form.extension.owner:
        class: Oro\Bundle\OrganizationBundle\Form\Extension\OwnerFormExtension
        arguments:
            - '@oro_entity.doctrine_helper'
            - '@oro_security.token_accessor'
            - '@security.authorization_checker'
            - '@Psr\Container\ContainerInterface'
        tags:
            - { name: form.type_extension, alias: form, extended_type: 'Symfony\Component\Form\Extension\Core\Type\FormType' }
            - { name: container.service_subscriber, id: security.acl.voter.basic_permissions }
            - { name: container.service_subscriber, id: oro_security.owner.ownership_metadata_provider }
            - { name: container.service_subscriber, id: oro_security.owner.entity_owner_accessor }
            - { name: container.service_subscriber, id: oro_security.ownership_tree_provider }
            - { name: container.service_subscriber, id: oro_organization.business_unit_manager }

    oro_organization.form.extension.organization:
        class: Oro\Bundle\OrganizationBundle\Form\Extension\OrganizationFormExtension
        arguments:
            - '@doctrine'
            - '@oro_security.token_accessor'
            - '@oro_security.owner.ownership_metadata_provider.link'
        tags:
            - { name: form.type_extension, alias: form, extended_type: 'Symfony\Component\Form\Extension\Core\Type\FormType' }

    oro_organization.form.listener:
        class: Oro\Bundle\OrganizationBundle\Event\FormListener
        arguments:
            - '@oro_entity_config.config_manager'
        tags:
            - { name: kernel.event_listener, event: entity_form.render.before, method: addOwnerField }

    oro_organization.autocomplete.organization.search_handler:
        parent: oro_form.autocomplete.search_handler
        arguments:
            - 'Oro\Bundle\OrganizationBundle\Entity\Organization'
            - ['name']
        tags:
            - { name: oro_form.autocomplete.search_handler, alias: organization, acl_resource: oro_organization_view }

    oro_organization.form.type.widget_business_unit_select:
        class: Oro\Bundle\OrganizationBundle\Form\Type\WidgetBusinessUnitSelectType
        arguments:
            - '@doctrine.orm.entity_manager'
            - '@oro_form.autocomplete.search_registry'
            - '@oro_entity_config.provider.form'
            - '@oro_entity.doctrine_helper'
        tags:
            - { name: form.type, alias: 'oro_type_widget_business_unit_select' }

    oro_organization.widget_config_value.widget_business_unit_multiselect.converter:
        class: Oro\Bundle\OrganizationBundle\Dashboard\Converters\WidgetBusinessUnitSelectConverter
        arguments:
            - '@oro_user.dashboard.owner_helper'
            - '@oro_security.acl_helper'
            - '@oro_entity.entity_name_resolver'
            - '@oro_entity.doctrine_helper'
            - '@doctrine.orm.entity_manager'
            - 'Oro\Bundle\OrganizationBundle\Entity\BusinessUnit'
        tags:
            - { name: oro_dashboard.value.converter, form_type: Oro\Bundle\OrganizationBundle\Form\Type\WidgetBusinessUnitSelectType }
