Support for Drupal 7 is ending on 5 January 2025—it’s time to migrate to Drupal 10! Learn about the many benefits of Drupal 10 and find migration tools in our resource center.
Coming from #1292470: Convert user pictures to Image Field. We need to lock the user picture field so it doesn't get deleted.
There's another interesting question though: the user picture field is not created in user.install but in standard.install, this means we need to inform people who create custom install profiles they need to call _user_install_picture_field(). Wondering whether we shouldn't move this into user.install anyway, but that's maybe for a follow up.
Comment | File | Size | Author |
---|---|---|---|
#1 | 1859352-1.patch | 496 bytes | swentel |
Comments
Comment #1
swentel CreditAttribution: swentel commentedAnd the patch.
Comment #2
moshe weitzman CreditAttribution: moshe weitzman commentedMakes sense.
In another patch, I'd be fine with moving field creation to user.install as proposed. The swappability of user picture is going to come from changing formatter, and not installing an alternate Field.
Comment #3
swentel CreditAttribution: swentel commentedInterestingly enough, calling _user_install_picture_field() in user_install() doesn't work as field_config table doesn't exist yet, so let's wait after we moved field api to CMI.
Comment #4
BerdirWhy must it not get deleted?
The fact it is just added in standard.profile means that we can't rely on it's existence anyway. We would have to do it in user.install if that's the case. Making locked but not moving it to user.install alone wouldn't really help. Tests for example could not rely on it.
I see that it's problematic to not be able rely on it, but if we have to, then this might require more discussion and adding the lock alone doesn't really change much. It doesn't guarantee that it exists, it just guarantees that once it does, you can't remove it again ;)
Comment #5
swentel CreditAttribution: swentel commentedAll true, the lock is only a first step I guess.
There are hardcoded properties in the theme settings like node_user_picture and comment_user_picture so we kind of need be sure it's always there, or add checks to make sure those properties don't popup on the theme settings. However, right now, the only way to make sure it really exists is adding it after the field_config tables exist, so at this point hook_field_install() is the only reliable place to install it.
It also feels like we need some kind of lock on 'display settings' too, because it's easy now to put something completely different in the compact mode instead of only the user picture.
We maybe need a hook for default fields and default display settings/view modes :)
Comment #6
catchHmm $variables['user_picture'] feels wrong in general.
Really it should just be $variables['account'] no? And then we could stick username in there too for now. And people can rely on there being $node->account or $comment->account because there's always a uid
fieldproperty on those entities.Comment #7
moshe weitzman CreditAttribution: moshe weitzman commentedWe can't Fatal if this field does not exist but I think we have to rely on it to provide rich experience like pictures on content and so on. I think marking the Field as locked is a good next step. We can strengthen the meaning of Locked if we want in a separate issue.
Thats by design. Folks are welcome to customize this View Mode for their needs and show username, bio, etc. along with a picture. Thats why the View Mode is called Compact and not Picture.
#6 - there is a patch for that at #1857324: Use default theme name and entity key in $build for user entity.
Comment #8
yched CreditAttribution: yched commentedI'd tend to agree with @Berdir #4. Preventing the deletion of something provided by standard.profile feels weird. Standard profile is about providing base defaults, not locking you with them. (although, well, 'locked' only prevent deletion through the UI, deletion is still possible through CRUD API)
Comment #9
moshe weitzman CreditAttribution: moshe weitzman commentedI think there is consensus to moving the picture Field creation to user.install. Swentel reports in #3 that we are blocked on that until Field API moves to CMI. So, I propose we add the Locked in this issue and do the move to user.install in a follow-up. OK?
Comment #10
catchI don't think there's consensus on that at all. user pictures could be disabled since at least 6.x if not much earlier, enforcing the user field on user accounts seems completely wrong - what if you want it on a profile entity instead?
No-one responded to #6 yet either, if account is always available, but not necessarily picture, then is there a problem? The variable is already misnamed anyway.
Comment #11
moshe weitzman CreditAttribution: moshe weitzman commentedIf #1853378: Optimize user_view('compact') in template_preprocess_node() goes in as proposed, we won't need a lock at all. It will be totally valid to move/delete the picture Field.
Comment #12
andypostComment #15
dpiThere is no longer a reason to lock/prevent deletion of user picture field now that the field is optional.
The field is not present on minimal profile installs.