From 4e1ca6f326e6c799120828ba203f9fb5b2af4b7f Mon Sep 17 00:00:00 2001 From: Iwona Just Date: Fri, 16 Feb 2024 09:42:12 +0000 Subject: [PATCH 1/3] allow removal of fullName --- src/elements/User.php | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/src/elements/User.php b/src/elements/User.php index 4cbe0c1d1fe..9c5f80e0088 100644 --- a/src/elements/User.php +++ b/src/elements/User.php @@ -977,6 +977,16 @@ public function setAttributes($values, $safeOnly = true): void $this->fullName = null; } + // if we're set to show full name field, and it's empty, clear out first and last names too + if ( + !Craft::$app->getConfig()->getGeneral()->showFirstAndLastNameFields && + array_key_exists('fullName', $values) && + empty(trim($values['fullName'])) + ) { + $this->firstName = null; + $this->lastName = null; + } + parent::setAttributes($values, $safeOnly); } From 54e6eef53b257fbd7c2ca7c35cba376d9910d487 Mon Sep 17 00:00:00 2001 From: brandonkelly Date: Sat, 17 Feb 2024 06:13:49 -0800 Subject: [PATCH 2/3] Cleanup --- src/elements/User.php | 17 +++++++---------- 1 file changed, 7 insertions(+), 10 deletions(-) diff --git a/src/elements/User.php b/src/elements/User.php index 9c5f80e0088..dc51beee694 100644 --- a/src/elements/User.php +++ b/src/elements/User.php @@ -973,18 +973,15 @@ public function setAttributes($values, $safeOnly = true): void } } - if (array_key_exists('firstName', $values) || array_key_exists('lastName', $values)) { - $this->fullName = null; - } - - // if we're set to show full name field, and it's empty, clear out first and last names too - if ( - !Craft::$app->getConfig()->getGeneral()->showFirstAndLastNameFields && - array_key_exists('fullName', $values) && - empty(trim($values['fullName'])) - ) { + if (array_key_exists('fullName', $values)) { + // Clear out the first and last names. + // They'll get reset from prepareNamesForSave() if fullName isn't empty. $this->firstName = null; $this->lastName = null; + } elseif (array_key_exists('firstName', $values) || array_key_exists('lastName', $values)) { + // Clear out the full name. + // It'll get reset from prepareNamesForSave() if the first/last names aren't empty. + $this->fullName = null; } parent::setAttributes($values, $safeOnly); From 3e01ed0cacd198fac68abc326dac2be44fc3ecee Mon Sep 17 00:00:00 2001 From: brandonkelly Date: Sat, 17 Feb 2024 06:16:41 -0800 Subject: [PATCH 3/3] Release note --- CHANGELOG.md | 1 + 1 file changed, 1 insertion(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index e8dba40cfd6..30e5b3c4243 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -4,6 +4,7 @@ - Slideout sidebars are now always toggleable; not just when the slideout is too narrow to show the sidebar alongside the content. ([#14418](https://github.com/craftcms/cms/pull/14418)) - Field Layout Designers now hide the component library sidebar in favor of “Add” disclosure menus, when they’re too narrow to show the sidebar alongside configured tabs. ([#14411](https://github.com/craftcms/cms/pull/14411)) +- Fixed a bug where it wasn’t possible to clear out users’ full names once they were set. ([#14402](https://github.com/craftcms/cms/pull/14402)) ## 5.0.0-beta.2 - 2024-02-15