Problem/Motivation

Handling of the is_default property of profiles is currently inconsistent based on factors including how the profile is created (on registration, through the profile add/edit form, programmatically) and whether or not the profile type is designated as multiple (meaning a given user can have more than one profile of that type).

How created Profile type multiple Profile type not multiple
On registration not set as default not set as default
Via profile add/edit form set as default set as default if user selects button
Programmatically not set as default not set as default

What is expected? Put differently, what should a consistent behaviour look like?

The method ProfileStorage::loadDefaultByUser() loads (according to its documentation) "the default user profile" of a given type. The method considers a profile to be default if both its is_default property and its status property evaluate to TRUE.

So: if a user has at least one active profile of a given type, one of them should be the default.

Proposed resolution

  • Add tests to cover this case.
  • Extend Profile::postSave() to cover the case where the current default is deactivated.
    • If the profile being saved is not set as active, and therefore may have been deactivated, attempt to set a new default.
  • Implement Profile::preSave().
    • If the profile is new, and if the profile type doesn't support multiple profiles, then set the profile as the default.
    • If the profile is new, and if the profile type does support multiple profiles, and if this is the first profile of the type for the user, then set the profile as the default.
  • Change code in ProfileForm::actions():
    • Remove ::setDefault method and code that adds it as a submit handler.
    • Alter code adding 'set_default' button so it's added if (a) the profile is active and (b) the profile is not default.
  • Change code in ProfileListBuilder::getOperations() to harmonize with ProfileForm::actions():
    • Alter code adding 'Mark as default' operation so it's added if (a) the profile is active and (b) the profile is not default.
  • Remove an incorrect line from the (unused?) ProfileForm::deactivate() method.

Remaining tasks

User interface changes

'set_default' button will appear on profile add/edit form only if profile is not new.

API changes

Profile::preSave() conditionally sets default status of profiles.

Data model changes

None

Comments

plopesc created an issue. See original summary.

plopesc’s picture

Status: Active » Needs review

Here I'm attaching the patch that performs the changes commented above.

However, not sure if would be more interesting to set always profiles as default at that point given that, even if it's multiple, that's the only profile of that type available when the user is being registered.

If you want I could redo the patch to match that behavior if it's a better fit.

Thanks

plopesc’s picture

StatusFileSize
new661 bytes
hypertext200’s picture

Status: Needs review » Reviewed & tested by the community

This works like charm.

nedjo’s picture

Issue summary: View changes
Status: Reviewed & tested by the community » Needs work

Nice catch. Indeed this is something that needs fixing.

The current patch correctly replicates the logic in ProfileForm::actions(). But - if the aim is to ensure that, if there is at least one profile of a given type, there is a default profile - that logic seems faulty.

The logic is:

  • If this is a new profile and the profile type doesn't support multiple profiles, set this as the default profile.
  • Otherwise, if the profile type supports multiple profiles, offer an option to set this as the default profile.

This doesn't cover the case that that this is a new profile and the first of its type for the user. Unless the user creating the profile chooses to make it the default, there will be no default profile of the given type.

When collecting profile data on registration, we can be sure it's the first profile of its type (unless it's possible to create multiple profiles of a given type on registration).

So it sounds like in this case we should be setting as default irrespective of whether the bundle supports multiple profiles.

But, ideally, we wouldn't be doing any of this in form submission handlers. That leads to duplication (we need the same or similar logic in multiple places). And it also means that profiles created through other workflows will be missed.

Ideally this would have an accompanying test.

Updating the issue summary accordingly.

nedjo’s picture

Assigned: Unassigned » nedjo

Working on a revised patch.

nedjo’s picture

Title: Profiles are not set as default when are unique and created from registration form » Default profile handling is inconsistent
Assigned: nedjo » Unassigned
Issue summary: View changes
Status: Needs work » Needs review
StatusFileSize
new3 KB
new6.69 KB

The last submitted patch, 7: profile-default-2809081-7-tests-only.patch, failed testing.

The last submitted patch, 7: profile-default-2809081-7-tests-only.patch, failed testing.

Status: Needs review » Needs work

The last submitted patch, 7: profile-default-2809081-7.patch, failed testing.

nedjo’s picture

Status: Needs work » Needs review
StatusFileSize
new7.98 KB
new4.28 KB

Fixing up tests.

Status: Needs review » Needs work

The last submitted patch, 11: profile-default-2809081-11-tests-only.patch, failed testing.

nedjo’s picture

Status: Needs work » Needs review
StatusFileSize
new7.98 KB

Uploaded those in the wrong order so this was set back to needs work. Re-uploading the same patch as in #11.

mglaman’s picture

Assigned: Unassigned » mglaman

Reviewing

mglaman’s picture

Assigned: mglaman » Unassigned
StatusFileSize
new2.49 KB

Looks great. Going to commit with some of the unused variable tweaks attached in this interdiff.

  • mglaman committed 07845f1 on 8.x-1.x authored by nedjo
    Issue #2809081 by nedjo, plopesc, mglaman: Default profile handling is...
mglaman’s picture

Status: Needs review » Fixed

nedjo, thanks so much for the effort and patch!

dafeder’s picture

This introduces a regression - new issue created #2878235: Set default button now showing in new profiles again

Status: Fixed » Closed (fixed)

Automatically closed - issue fixed for 2 weeks with no activity.