cms
cms copied to clipboard
[5.x] Feature/add user profile form tabs sections
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:
- The
getProfileTabs()method:- Generates the array of tabs that can be looped through
- Excludes the fields
password,password_confirmation,roles,groupsas well as assets fields, on the same principle as the existinggetProfileFieldsmethod. - Adds values and preprocess the fields, again on the same principle as the existing
getProfileFieldsmethod.
- The result of
getProfileTab() is then used to create the new{{ tabs }}` inner tag. - It is then flattened into another array used to create the new
{{ sections }}inner tag. - This new array is flattened again into an array used to create the existing
{{ fields }}inner tag (i.e. instead of usinggetProfileFields()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.