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

User fields do not load existing values when using Eloquent User Driver #2111

Closed
gsenior opened this Issue Aug 8, 2018 · 1 comment

Comments

Projects
None yet
3 participants
@gsenior

gsenior commented Aug 8, 2018

Describe the bug
User fields do not load their saved value(s) when using the Eloquent User Driver with numeric primary keys.

To Reproduce
Steps to reproduce the behavior:

  1. Configure a fresh Statamic install to use the Eloquent User Driver
  2. Add a user field to a collections fieldset
  3. Edit a collection entry, select one or more users and save
  4. Navigate back to collection list, then back to edit the entry just modified
  5. The user field will now be empty

Expected behavior
The user field should display the previously selected values.

Environment details (please complete the following information):

  • Statamic Version: 2.10.3
  • Fresh Install or Upgrade: Fresh
  • OS: macOS 10.13.6
  • Browser: Chrome 68
  • Web Server: Valet
  • PHP Version: 7.1
  • Addons installed:
    • SEOPro

Additional context
It looks like the problem stems from the way that the UsersMode is implemented and loose typing in PHP. When the suggestions are loaded, they are cast as integers. After a bit more digging, I removed the following code from /statamic/bundles/Suggest/Modes/UsersMode.php:

$suggestions = [];

foreach (User::all() as $user) {
    $suggestions[$user->id()] = $this->label($user, 'username');
}

And replaced with:

$suggestions = new \stdClass;

foreach (User::all() as $user) {
    $id = (string) $user->id();
    $suggestions->{$id} = $this->label($user, 'username');
}

$suggestions = (array) $suggestions;

I can also work around this with a custom Statamic\Addons\Suggest\Mode implementation for the time being, but a patch in core would be ideal!

@jesseleite

This comment has been minimized.

Member

jesseleite commented Oct 29, 2018

Should be fixed in next release 👍

@jackmcdade jackmcdade closed this Nov 6, 2018

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment