diff --git a/src/Auth/UserTags.php b/src/Auth/UserTags.php index 80457a3e75..d7af941581 100644 --- a/src/Auth/UserTags.php +++ b/src/Auth/UserTags.php @@ -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']; @@ -708,6 +710,41 @@ 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(fn ($tab) => [ + 'display' => $tab->display(), + 'sections' => $tab->sections() + ->map(fn ($section) => [ + 'display' => $section->display(), + 'instructions' => $section->instructions(), + 'fields' => $section->fields()->addValues($values)->preProcess()->all() + ->reject(fn ($field) => in_array($field->handle(), ['password', 'password_confirmation', 'roles', 'groups']) + || $field->fieldtype()->handle() === 'assets' + ) + ->map(fn ($field) => $this->getRenderableField($field, 'user.profile')) + ->values() + ->all(), + ]) + ->all(), + ]) + ->values() + ->all(); + } + /** * Get fields with extra data for looping over and rendering. *