Skip to content

Instantly share code, notes, and snippets.

@bdunogier
Created November 30, 2021 16:29
Show Gist options
  • Save bdunogier/70c19c0c4289244627f59e38d22dbd44 to your computer and use it in GitHub Desktop.
Save bdunogier/70c19c0c4289244627f59e38d22dbd44 to your computer and use it in GitHub Desktop.
IBEXA DXP: different user content type for registration per siteaccess

Ibexa DXP has allowed multiple user content types for a while now, but there is no documented, native way to change the user content type used for registration based on the siteaccess.

image

As it turns out, it is quite easy with a bit of tweaking.

The EzSystems\EzPlatformUser\ConfigResolver\ConfigurableRegistrationContentTypeLoader service is used by the registration process to provide the user content type used for registration. It requires the identifier of the content type to be passed as a parameter.

We can change that parameter to a siteaccess aware one by redefining the service.

First, create as many user content types as you need. Let's say site1user and site2user for site1 and site2.

Now, create a siteaccess aware setting for the registration content types:

parameters:
    app.default.user_register_content_type: 'user'
    app.site1.user_register_content_type: 'site1user'
    app.site2.user_register_content_type: 'site2user'

Finally, redefine the content type loader service above to use the siteaccess aware parameter instead of the standard symfony container one:

services:
    EzSystems\EzPlatformUser\Form\DataMapper\UserRegisterMapper:
        calls:
            - [setParam, ["language", "@=service('ezpublish.config.resolver').getParameter('languages', null, null)[0]"]]

And that's it. If you open /user/register on site1, it will use the site1user content type, while it will use site2user on site2.

Changing the destination group

As it turns out, the group where registered users will be created is already siteaccess aware. It can be changed by setting a different value for the user_registration.group_id setting for each siteaccess.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment