Skip to content

[5.x] Feature/add user profile form tabs sections #11836

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 15 commits into
base: 5.x
Choose a base branch
from

Conversation

AtmoFX
Copy link

@AtmoFX AtmoFX commented Jun 3, 2025

This PR follows a discussion on Discord.

It adds/changes the following to {{ user:profile_form }}:

  • Main purpose: added loops over sections, using the {{ sections }} inner tag.
    This aligns the profile form to other forms where it was possible to loop over sections.
  • Additionally: added loops over tabs, using the {{ tabs }} inner tag.
    Tabs do not exist in forms' blueprints.

Technically, the tags work by:

  1. The getProfileTabs() method:
    1. Generates the array of tabs that can be looped through
    2. Excludes the fields password, password_confirmation, roles, groups as well as assets fields, on the same principle as the existing getProfileFields method.
    3. Adds values and preprocess the fields, again on the same principle as the existing getProfileFields method.
  2. The result of getProfileTab() is then used to create the new {{ tabs }}` inner tag.
  3. It is then flattened into another array used to create the new {{ sections }} inner tag.
  4. This new array is flattened again into an array used to create the existing {{ fields }} inner tag (i.e. instead of using getProfileFields() to create {{ fields }}).
    This removes duplicate code (getProfileFields() is not called anymore, though I have not removed it) and is expected to have better performance.

Note: flattening the Array from tabs to sections and then to profile is done on the same way as it is done for regular forms:

$data['tabs'] = $this->getProfileTabs();
$data['sections'] = collect($data['tabs'])->flatMap->sections->all();
$data['fields'] = collect($data['sections'])->flatMap->fields->all();

But it could have been done using:

$array_tabs = $this->getProfileTabs();
$array_sections = array_reduce(array_column($array_tabs, 'sections'), 'array_merge', []);
$array_fields = array_reduce(array_column($array_sections, 'fields'), 'array_merge', []);

One method might be superior in terms of performance.

@AtmoFX AtmoFX changed the title Feature/add user profile form tabs sections [5.x] Feature/add user profile form tabs sections Jun 3, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants