services:
    Oro\Bundle\UserBundle\Form\Type\UserType:
        alias: oro_user.form.user

    oro_user.form.user:
        class: Symfony\Component\Form\Form
        public: true
        factory: ['@form.factory', createNamed]
        arguments: ["oro_user_user_form", Oro\Bundle\UserBundle\Form\Type\UserType, null]

    oro_user.form.user.api:
        class: Symfony\Component\Form\Form
        public: true
        factory: ['@form.factory', createNamed]
        arguments: ["user", Oro\Bundle\UserBundle\Form\Type\UserApiType, null]

    oro_user.form.role:
        class: Symfony\Component\Form\Form
        factory: ['@form.factory', createNamed]
        arguments: ["oro_user_role_form", "oro_user_role"]

    oro_user.form.role.api:
        class: Symfony\Component\Form\Form
        public: true
        factory: ['@form.factory', createNamed]
        arguments: ["role", Oro\Bundle\UserBundle\Form\Type\RoleApiType, null]

    oro_user.form.group:
        class: Symfony\Component\Form\Form
        public: true
        factory: ['@form.factory', createNamed]
        arguments: ["oro_user_group_form", Oro\Bundle\UserBundle\Form\Type\GroupType]

    oro_user.form.group.api:
        class: Symfony\Component\Form\Form
        public: true
        factory: ['@form.factory', createNamed]
        arguments: ["group", Oro\Bundle\UserBundle\Form\Type\GroupApiType, null]

    oro_user.form.reset:
        class: Symfony\Component\Form\Form
        public: true
        factory: ['@form.factory', createNamed]
        arguments: ["oro_user_reset_form", Oro\Bundle\UserBundle\Form\Type\ResetType, null, { validation_groups: [ResetPassword, Default] }]

    oro_user.form.emailsettings:
        class: Symfony\Component\Form\Form
        factory: ['@form.factory', createNamed]
        arguments: ["oro_user_emailsettings_form", Oro\Bundle\UserBundle\Form\Type\EmailSettingsType, null]

    oro_user.form.type.user:
        class: Oro\Bundle\UserBundle\Form\Type\UserType
        arguments:
            - '@security.authorization_checker'
            - '@oro_security.token_accessor'
            - '@request_stack'
            - '@oro_user.form.provider.password_field_options_provider'
            - '@oro_user.form.provider.roles_choices_for_user'
        tags:
            - { name: form.type, alias: oro_user_user }

    oro_user.form.type.user.api:
        class: Oro\Bundle\UserBundle\Form\Type\UserApiType
        arguments:
            - '@security.authorization_checker'
            - '@oro_security.token_accessor'
            - '@request_stack'
            - '@oro_user.form.provider.password_field_options_provider'
            - '@oro_user.form.provider.roles_choices_for_user'
        calls:
            - [setUserConfigManager, ["@oro_config.user"]]
        tags:
            - { name: form.type, alias: user }

    oro_user.form.type.change_password:
        class: Oro\Bundle\UserBundle\Form\Type\ChangePasswordType
        arguments:
             - '@oro_user.change_password.subscriber'
             - '@oro_user.form.provider.password_field_options_provider'
        tags:
            - { name: form.type, alias: oro_change_password }

    oro_user.form.type.set_password.form.type:
        class: Oro\Bundle\UserBundle\Form\Type\SetPasswordType
        arguments:
             - '@oro_user.form.provider.password_field_options_provider'
        tags:
            - { name: form.type, alias: oro_set_password }

    oro_user.form.type.set_password.form:
        class: Symfony\Component\Form\Form
        public: true
        factory: ['@form.factory', createNamed]
        arguments:
            - "oro_set_password_form"
            - Oro\Bundle\UserBundle\Form\Type\SetPasswordType

    oro_user.form.type.email:
        class: Oro\Bundle\UserBundle\Form\Type\EmailType
        tags:
            - { name: form.type, alias: oro_user_email }

    oro_user.form.type.role.api:
        class: Oro\Bundle\UserBundle\Form\Type\RoleApiType
        tags:
            - { name: form.type, alias: role }

    oro_user.form.type.group:
        class: Oro\Bundle\UserBundle\Form\Type\GroupType
        tags:
            - { name: form.type, alias: oro_user_group }

    oro_user.form.type.group.api:
        class: Oro\Bundle\UserBundle\Form\Type\GroupApiType
        tags:
            - { name: form.type, alias: group }

    oro_user.form.type.reset:
        class: Oro\Bundle\UserBundle\Form\Type\ResetType
        arguments:
            - 'Oro\Bundle\UserBundle\Entity\User'
            - '@oro_user.form.provider.password_field_options_provider'
        tags:
            - { name: form.type, alias: oro_user_reset }

    oro_user.form.type.user_select:
        class: Oro\Bundle\UserBundle\Form\Type\UserSelectType
        tags:
            - { name: form.type, alias: oro_user_select }

    oro_user.form.type.user_acl_select:
        class: Oro\Bundle\UserBundle\Form\Type\UserAclSelectType
        tags:
            - { name: form.type, alias: oro_user_acl_select }

    oro_user.form.type.organization_user_acl_select:
        class: Oro\Bundle\UserBundle\Form\Type\OrganizationUserAclSelectType
        tags:
            - { name: form.type, alias: oro_user_organization_acl_select }

    oro_user.form.type.user_multiselect:
        class: Oro\Bundle\UserBundle\Form\Type\UserMultiSelectType
        arguments:
            - '@doctrine.orm.entity_manager'
        tags:
            - { name: form.type, alias: oro_user_multiselect }

    oro_user.form.type.role_multiselect:
        class: Oro\Bundle\UserBundle\Form\Type\RoleMultiSelectType
        arguments:
            - '@doctrine.orm.entity_manager'
        tags:
            - { name: form.type, alias: oro_role_multiselect }

    oro_user.form.type.organization_user_multiselect:
        class: Oro\Bundle\UserBundle\Form\Type\OrganizationUserAclMultiSelectType
        arguments:
            - '@doctrine.orm.entity_manager'
        tags:
            - { name: form.type, alias: oro_user_organization_acl_multiselect }

    oro_user.form.type.gender:
        class: Oro\Bundle\UserBundle\Form\Type\GenderType
        arguments:
            - '@oro_user.gender_provider'
        tags:
            - { name: form.type, alias: oro_gender }

    oro_user.form.type.user_emailsettings:
        class: Oro\Bundle\UserBundle\Form\Type\EmailSettingsType
        arguments:
            - '@oro_user.imap_configuration.subscriber'
            - '@oro_imap.oauth_manager_registry'
        tags:
            - { name: form.type, alias: oro_user_emailsettings }

    oro_user.form.handler.user:
        class: Oro\Bundle\UserBundle\Form\Handler\UserHandler
        public: true
        arguments:
            - '@oro_user.form.user'
            - '@request_stack'
            - '@oro_user.manager'
            - '@oro_email.manager.template_email'
            - '@oro_config.user'
            - '@session.flash_bag'
            - '@translator'
            - '@logger'

    oro_user.form.handler.user.api:
        class: Oro\Bundle\UserBundle\Form\Handler\UserHandler
        public: true
        arguments:
            - '@oro_user.form.user.api'
            - '@request_stack'
            - '@oro_user.manager'

    oro_user.form.handler.role.api:
        class: Oro\Bundle\UserBundle\Form\Handler\RoleHandler
        public: true
        arguments:
            - '@oro_user.form.role.api'
            - '@request_stack'
            - '@doctrine.orm.entity_manager'

    oro_user.form.handler.group:
        class: Oro\Bundle\UserBundle\Form\Handler\GroupHandler
        public: true
        arguments:
            - '@oro_user.form.group'
            - '@request_stack'
            - '@doctrine.orm.entity_manager'

    oro_user.form.handler.group.api:
        class: Oro\Bundle\UserBundle\Form\Handler\GroupHandler
        public: true
        arguments:
            - '@oro_user.form.group.api'
            - '@request_stack'
            - '@doctrine.orm.entity_manager'

    Oro\Bundle\UserBundle\Form\Handler\ResetHandler:
        alias: oro_user.form.handler.reset

    oro_user.form.handler.reset:
        class: Oro\Bundle\UserBundle\Form\Handler\ResetHandler
        public: true
        arguments:
            - '@oro_user.form.reset'
            - '@request_stack'
            - '@oro_user.manager'
            - '@logger'

    oro_user.form.handler.abstract.acl_role:
        class: Oro\Bundle\UserBundle\Form\Handler\AclRoleHandler
        shared: false
        arguments:
            - '@form.factory'
            - '@security.acl.cache.doctrine'
            - '%oro_user.privileges%'
        calls:
            - [setAclManager, ["@oro_security.acl.manager"]]
            - [setAclPrivilegeRepository, ["@oro_security.acl.privilege_repository"]]
            - [setManagerRegistry, ["@doctrine"]]
            - [setConfigurableName, ['default']]
            - [setConfigurableFilter, ["@oro_security.filter.configurable_permission_filter"]]
            - [setQueryCacheProvider, ['@oro_security.acl_query.cache_provider']]

    oro_user.form.handler.acl_role:
        parent: oro_user.form.handler.abstract.acl_role
        public: true
        shared: false
        calls:
            - [setRequestStack, ['@request_stack']]
            - [addExtensionFilter, ['action', '']]    # only default group actions are allowed

    Oro\Bundle\UserBundle\Form\Handler\SetPasswordHandler:
        alias: oro_user.form.handler.set_password

    oro_user.form.handler.set_password:
        class: Oro\Bundle\UserBundle\Form\Handler\SetPasswordHandler
        public: true
        arguments:
            - '@logger'
            - '@request_stack'
            - '@translator'
            - '@oro_user.form.type.set_password.form'
            - '@oro_user.mailer.processor'
            - '@oro_user.manager'
            - '@validator'

    oro_user.form.provider.password_tooltip:
        class: Oro\Bundle\UserBundle\Form\Provider\PasswordTooltipProvider
        arguments:
            - '@oro_user.provider.password_complexity_config_provider'
            - '@translator'

    oro_user.form.provider.password_field_options_provider:
        class: Oro\Bundle\UserBundle\Form\Provider\PasswordFieldOptionsProvider
        arguments:
            - '@oro_user.provider.password_complexity_config_provider'
            - '@oro_user.form.provider.password_tooltip'

    oro_user.form.provider.roles_choices_for_user:
        class: Oro\Bundle\UserBundle\Form\Provider\RolesChoicesForUserProvider
        arguments:
            - '@doctrine'
            - '@oro_security.acl_helper'

    oro_user.form.extension.js_validation.password_complexity_extension:
        class: Oro\Bundle\UserBundle\Form\Extension\JsValidation\PasswordComplexityExtension
        arguments:
            - '@oro_form.extension.js_validation.constraints_provider'
            - '@oro_user.provider.password_complexity_config_provider'
        tags:
            - { name: form.type_extension, alias: form, extended_type: Symfony\Component\Form\Extension\Core\Type\RepeatedType }

    # Dashboard
    oro_user.form.type.widget_owners:
        class: Oro\Bundle\UserBundle\Form\Type\WidgetOwnersType
        tags:
            - { name: form.type, alias: 'oro_type_widget_owners' }

    oro_user.form.type.widget_user_multiselect:
        class: Oro\Bundle\UserBundle\Form\Type\WidgetUserSelectType
        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_user_select' }

    oro_user.form.type.widget_role_multiselect:
        class: Oro\Bundle\UserBundle\Form\Type\WidgetRoleSelectType
        tags:
            - { name: form.type, alias: 'oro_type_widget_role_select' }

    oro_user.widget_config_value.widget_user_multiselect.converter:
        class: Oro\Bundle\UserBundle\Dashboard\Converters\WidgetUserSelectConverter
        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\UserBundle\Entity\User'
        calls:
            - [setTokenAccessor, ['@oro_security.token_accessor']]
        tags:
            - { name: oro_dashboard.value.converter, form_type: Oro\Bundle\UserBundle\Form\Type\WidgetUserSelectType }

    oro_user.widget_config_value.widget_role_multiselect.converter:
        class: Oro\Bundle\DashboardBundle\Provider\Converters\WidgetEntitySelectConverter
        arguments:
            - '@oro_security.acl_helper'
            - '@oro_entity.entity_name_resolver'
            - '@oro_entity.doctrine_helper'
            - '@doctrine.orm.entity_manager'
            - 'Oro\Bundle\UserBundle\Entity\Role'
        tags:
            - { name: oro_dashboard.value.converter, form_type: Oro\Bundle\UserBundle\Form\Type\WidgetRoleSelectType }

    oro_user.widget_config_value.widget_owners.converter:
        class: Oro\Bundle\UserBundle\Dashboard\Converters\WidgetDefaultOwnersConverter
        arguments:
            - '@translator'
        calls:
            - [ setConverter, ['@oro_organization.widget_config_value.widget_business_unit_multiselect.converter', 'businessUnits', 'oro.user.dashboard.business_unit'] ]
            - [ setConverter, ['@oro_user.widget_config_value.widget_role_multiselect.converter', 'roles', 'oro.user.dashboard.role'] ]
            - [ setConverter, ['@oro_user.widget_config_value.widget_user_multiselect.converter', 'users', 'oro.user.dashboard.owner'] ]
        tags:
            - { name: oro_dashboard.value.converter, form_type: Oro\Bundle\UserBundle\Form\Type\WidgetOwnersType }

    oro_user.form.type.apikey_gen:
        class: Oro\Bundle\UserBundle\Form\Type\UserApiKeyGenType
        tags:
            - { name: form.type, alias: oro_user_apikey_gen }

    oro_user.form.type.apikey_gen_key:
        class: Oro\Bundle\UserBundle\Form\Type\UserApiKeyGenKeyType
        tags:
            - { name: form.type, alias: oro_user_apikey_gen_key }
