diff --git a/app/Http/Controllers/FormController.php b/app/Http/Controllers/FormController.php index 282a8260..649eca19 100644 --- a/app/Http/Controllers/FormController.php +++ b/app/Http/Controllers/FormController.php @@ -12539,13 +12539,22 @@ class FormController extends Controller /** * Selected user attribute codes when the form is configured to show them. + * Uses the saved attribute list as the source of truth so columns still render + * if Show User Attributes was left off after attributes were selected. */ protected function userAttributeCodes($form): array { - if (!$form || ($form->show_user_attributes ?? 'no') !== 'yes') { + if (!$form) { return []; } $raw = $form->user_attributes ?? []; + if (is_object($raw)) { + $raw = (array) $raw; + } + if (is_string($raw) && $raw !== '') { + $decoded = json_decode($raw, true); + $raw = is_array($decoded) ? $decoded : explode('#', $raw); + } if (!is_array($raw)) { return []; } @@ -12553,13 +12562,16 @@ class FormController extends Controller foreach ($raw as $code) { if (is_object($code)) { $code = $code->code ?? ''; + } elseif (is_array($code)) { + $code = $code['code'] ?? ''; } $code = trim((string) $code); if ($code !== '') { $codes[] = $code; } } - return array_values(array_unique($codes)); + $codes = array_values(array_unique($codes)); + return $codes; } protected function userAttributeValue($user, string $attr): string diff --git a/app/Http/Controllers/FormentityController.php b/app/Http/Controllers/FormentityController.php index 7b7eb08e..f9a5ce7e 100644 --- a/app/Http/Controllers/FormentityController.php +++ b/app/Http/Controllers/FormentityController.php @@ -158,6 +158,9 @@ class FormentityController extends Controller $values->show_manager_details = $values->show_manager_details ?? 'no'; $values->show_user_attributes = (($values->show_user_attributes ?? 'no') === 'yes') ? 'yes' : 'no'; $values->user_attributes = $this->normalizeAttributeCodes($values->user_attributes ?? []); + if (!empty($values->user_attributes)) { + $values->show_user_attributes = 'yes'; + } } //echo '
'; print_r($values); exit;
return $values;
@@ -251,6 +254,9 @@ class FormentityController extends Controller
$data['roles_info'] = ($data['roles_info'] ?? 'no') === 'yes' ? 'yes' : 'no';
$data['show_user_attributes'] = ($data['show_user_attributes'] ?? 'no') === 'yes' ? 'yes' : 'no';
$data['user_attributes'] = $this->normalizeAttributeCodes($data['user_attributes'] ?? []);
+ if (!empty($data['user_attributes'])) {
+ $data['show_user_attributes'] = 'yes';
+ }
if ($data['email_notification'] === 'no') {
$data['email_notification_rules'] = [];
} else {