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
Open
Changes from 10 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
46 changes: 45 additions & 1 deletion src/Auth/UserTags.php
Original file line number Diff line number Diff line change
Expand Up @@ -196,7 +196,9 @@ public function profileForm()

$data = $this->getFormSession('user.profile');

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

$knownParams = ['redirect', 'error_redirect', 'allow_request_redirect'];

Expand Down Expand Up @@ -708,6 +710,48 @@ protected function getAdditionalRegistrationFields()
->all();
}

/**
* Get tabs with fields filled with extra data for looping over and rendering, using tabs defined in blueprint.
* The result is unpacked into a sections array and a fields array for choosing what to loop over and render.
*
* @return array
*/
protected function getProfileTabs()
{
$user = User::current();

$values = $user
? $user->data()->merge(['email' => $user->email()])->all()
: [];

return User::blueprint()->tabs()
->map(function ($tab) use ($values) {
return [
'display' => $tab->display(),
'sections' => $tab->sections()
->map(function ($section) use ($values) {
return [
'display' => $section->display(),
'instructions' => $section->instructions(),
'fields' => $section->fields()->addValues($values)->preProcess()->all()
->reject(function ($field) {
return in_array($field->handle(), ['password', 'password_confirmation', 'roles', 'groups'])
|| $field->fieldtype()->handle() === 'assets';
})
->map(function ($field) {
return $this->getRenderableField($field, 'user.profile');
})
->values()
->all(),
];
})
->all(),
];
})
->values()
->all();
}

/**
* Get fields with extra data for looping over and rendering.
*
Expand Down