cms icon indicating copy to clipboard operation
cms copied to clipboard

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

Open AtmoFX opened this issue 7 months ago • 0 comments

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 avatar Jun 03 '25 03:06 AtmoFX