[6.x] Fix default: current Users fieldtype behavior - #15072
Conversation
|
Automated review via an internal PR review skill — a human still needs to sanity check this. The approach here is sound and the The "Current User" chip opens a broken edit stack
:editable="canEdit && (item.editable || item.editable === undefined)"Users has Compare private function currentUserOption(): array
{
return [
'id' => 'current',
'title' => __('Current User'),
'editable' => false,
];
}
|
|
Follow-up to narrow that list — I went back and diffed my notes against Retract entirely:
Downgrade:
Unchanged — these are genuinely this PR's:
So: the first item is the one that needs fixing, the second is a one-word |
The Users fieldtype supports
currentas a default value which sets the currently logged in user as the default. However, this is only available by editing the blueprint's YAML directly and not an option in the UI. There is also another issue with it right now. If you setdefault: currentin the YAML and then opened the blueprint and field in the CP, the current user was shown but saving would then hardcode that user's id into the blueprint which is obviously not the intended behavior of that setting.This PR introduces both selecting it via the UI and also fixes the hardcoding of the ID on save.
The
defaultconfig field is flagged internally withallow_current, which is what tells the picker to treatcurrentas a real, selectable value in this context (and only this context). With that flag set the fieldtype:currentinstead of resolving it to an id, so it round-tripscleanly through the CP, and
For actual
usersfields (noallow_current),currentcontinues to resolve to the logged-in user as before, so existingdefault: currentblueprints keep working exactly the same. The resolution logic now also handlescurrentinside an array, matching howaugment()already worked.While working on those fixes I noticed another potential bug: The default picker ignored the field's own
max_itemsconfig value so you could select (and save) more default users than the field itself allowed.max_itemsof its own, so it was always unbounded. It now reactively mirrors the field's configured max items in the field's settings UI so you can't select more default users than the field permits. It also adds server side validation so you can't circumvent it easily. Otherwise you can allow three users, select three, lower it to allow 2, and still successfully save the blueprint.It now respects that config:
Closes #8796.