Closed (outdated)
Project:
Drupal core
Version:
11.x-dev
Component:
markup
Priority:
Normal
Category:
Bug report
Assigned:
Unassigned
Reporter:
Created:
23 Apr 2014 at 06:37 UTC
Updated:
14 Jan 2025 at 09:34 UTC
Jump to comment: Most recent, Most recent file
Comments
Comment #1
Jeff Burnz commentedComment #2
Jeff Burnz commentedComment #3
joelpittetI saw something that would be awesome everywhere. But how about this?
{{ node.author|view_mode('compact') }}As long as we had view_mode's for all entities like entity_view(), we can take author and a new filter called view_mode(), with the name of the view mode you'd like to render that entity in.
Thoughts?
Comment #4
mortendk commentedmay i suggest a couple of things:
theme suggestion for user.html.twig
that we put in a theme suggestion as well so we can use user--compact.html.twig
that would make i it logicl
2 i would love if we could grap the image directly without the chance off all kinds of other things coming in (like an editor playing with compact)
something like {{ author.image }} that only prints out the image would make a ton of more sense than the user.html.twig with article tags n everything that we get out now.
Comment #5
Jeff Burnz commented#3 I like that idea a lot, nice to put that at the template level and not buried in preprocess, so I really like it.
Kind of agree with the view mode suggestions, I would probably go that route if we did
{{ node.author|view_mode('compact') }}, to strip the article wrapper rather than doing that in preprocess as per the OP.I like the idea of getting just the image out also, I haven't dug very deep but is there a method for doing that sort of thing, cause all that stuff in #items is protected afaict and seriously #items is so dam complicated, theming has become a real chore in D8, ya know?
Comment #6
andypostAt the same time user picture is a image field now.
So maybe better use a field template override?
Comment #7
Jeff Burnz commentedYes, I am currently using field template in my theme to strip away field markup, so good call, but can we or should we do that for core?
I thought about this yesterday and can see that user_view compact is an interesting idea, as in how this is meant to work pulling the user and a specific view mode - however this actually feels more like you want to add a bio to the node, that you want more than just the author picture - such as Bio field, link to website etc - in other words this is good for adding a complete author bio/byline but for simple user pictures to comment or node is this overkill?
Should we be requiring overriding of two templates to get a clean img element (potential user--view-mode--compact.html.twig) and the field template?
Can we write a method/function that special cases getting the author picture, so we can use that to get it any time we want? Is that uncool in D8 or acceptable?
Just thinking out loud here.
Comment #8
mortendk commentedmy 2 cents
i think its epic overkill to include the whole view with whatever fields etc - what i think we should do is grapping the image and sticking that into the {{ author_picture }} that would make sense for the node & thats whaat we need
.. then it would be awesome with a {{ author_picture|imagesize('small') }} or something.
Comment #9
andypostagree about overkill especially for comments that could be hundreds on page
Comment #10
mortendk commented@jeffbunz yeah i dont think it was ever ment to be pulling a bio etc - thats what we have our beloved blocks for right ?
so in my head im thinking something like this:
the author_image is well basically just the file path to that image ?
some pseudocode like this:
node.module
node.html.twig
then it still keeps using the picture magic etc right ?
Comment #11
tstoecklerSo the reason for why this view mode was introduced in #1292470: Convert user pictures to Image Field was that the user picture is just a regular configurable field that is created by the Standard install profile. And we want to avoid having core themes depend on configuration from installation profiles. The current mechanism allows for other profiles to install a different image field (i.e. with a different name, or a gravatar field, or whatever...) but still use e.g. Bartik and not have to override the node template. That's why pulling the field value directly from the user is not going to fly, I think.
Of course we should definitely avoid printing empty markup, but, yeah...
Comment #12
Jeff Burnz commentedRemove some example code and clarify intentions/discussion points.
Comment #13
Jeff Burnz commentedOK, so re #11 that might leave us with quite limited options here - the view mode suggestion for one is viable and gives us ability to strip markup (article wrapper), and if you need to go further (strip field markup) then themes can do this with a field template? Better ideas more than welcome.
Comment #14
lewisnymanComment #18
megan_m commentedI have made the mistake (more than once) of thinking it would be clever to use the "Compact" view mode as an author bio or teaser type view mode, only to realize that it would cause problems elsewhere. It would be nice if that view mode could be renamed "Picture", so it's more clear that this should just be used for the picture field.
Comment #20
dqdTaken from node.html.twig comment block line 23.
This can be missed quickly (and is confusing if not), so we maybe should rename the view_mode or the author_picture (and user_picture) variable? Actually all 3 namings are not really fitting for their purpose here. Plus: I don't see the reasons for hard coded
<article>HTML element wrapper here eather. Even DS full reset and Fences is not able to remove it. If we need to keep this view mode and the twig variables in here (even if for legacy reasons), we should make it possible to rewrite the markup. Therefore at least a field or view mode theme suggestion would be helpful at minimum. Just first thoughts at a glimpse. If this is too much (like stated already in case of 1000 threaded comments), we possibly need a better way for viewing/referencing the author picture on a node and a user picture on comments then.Beware that we have the default theme setting "show user picture in posts" and "show user picture in comments" under admin appearance (see screenshot uploaded), which can be turned on/off. Both settings activate/fill two different theme variables: {{ user_picture }} and {{ author_picture}}. And both are using the user compact view mode. The user does not await a complete compact user view mode if turned on one or the other, but the user image field only here. Especailly since modules like Flag automatically add their fields to this view mode (tested). 2 possible solutions:
In all cases the
<article>HTML element with quick-edit attributes make no sense here at all, since this will most commonly appear in content lists or node full view mode, where the main article HTML element comes in the mix additionally. So point 2 on Proposed solution in the issue summary should be agreed on.NOTE: I change the focused Drupal core dev version for this issue, since we are on 8.4,2 already ...
Comment #21
dqdComment #22
dqdLet's catch some spots to know of (Gist link since the code is unreadable here): Occurence of author_picture, user_picture and respective settings in Drupal 8.5.x dev
As we can see (this can be also seen as a reply to #8/#10), there are A LOT spots (especially for user_picture), and renaming user_picture (also in functions etc) can become a real mess to keep naming convention in sync. And since the naming convention of user and author sticks together here it is a decision for both. So maybe changing the rendered content in user_picture and author_picture away from a view mode back to a simple field value injection is maybe still the easiest approach for this issue. Even if view modes is a the new way to go. And since this can break themes we should consider an additional twig variable {{ user_compact }} or something similar to reflect the existing view mode.
BTW: there is a way in contrib to revert to the behaviour we have (at that moment here) in core (before we maybe change it next time). It can be used to rebuild the user compact view mode for certain purposes: https://drupal.stackexchange.com/a/207719
Comment #23
dqdComment #24
berdirDidn't read this yet, but #2551959: Hardcoded usage of compact view mode in template_preprocess_node() and template_preprocess_comment() is problematic is related, opened that a long time ago.
Comment #25
dqd@Berdir: Thanks for the useful reference. Yeah this one seems to be a good spot and definitely related. But this link seems to be restricted (I get a 403). But the title looks promising :) (Any chance to add me to the group to access it for getting things done here?)
Comment #26
berdirI don't know why that issue is unpublished, I guess I can only see it because I'm the owner. There is no reason for it mentioned. Try asking someone from the security team.
Comment #27
dqdAnother even "harder" suggestion to solve this whole issue (to raise the MVC and modularity flag again) is:
Finally remove the "show user/author picture" kind of settings thing from appearance and the default user picture field completely. TBH, I do not really know what the use of it is no more when we are able to add fields everywhere nowadays and can render them like we want on module or theme level anytime. Simply turning on this appearance setting mostly looks akward from scretch in any theme anyway and needs tweaking anyway. So why not doing it the Drupal fields way here too? Most users do it already this way and leave the settings off. The whole "show user picture" concept feels quite dated and forces to use this default field, IMHO. This would also affect the issue mentioned by @Berdir and would possibly fix this one too by one strike.
Removing the default user_picture field simply greys-out the appearance settings (screenshot follows) without any issues. I think the suggestion would not break any other contrib or core theme/module.
Comment #28
dqdComment #29
pranali.addweb commentedI can suggest a few things, they might help to improve the solution itself.
Issue: User picture improvements in node template
Solution: I am mentioning few steps from start:
-->We should start from Global theme setting and pretend unwanted checks. Like if we dont want the user picture on user commnets we can prevent it from there by theme global setting.
-->There are two ways to get profile picture:
.One by the suggestions which are mentioned on the top of the twig file. We can directly access from there. i.e: {{ content.user_picture }}
-->The another way to access the profile picture by fetching field in node. If the user picture is a specific field then we should use : i.e: {{ node.uid.entity.field_name.value }}
-->For styling {{ author_picture|imagesize('small') }} this is a sample example which is working fine for me.
-->For styling by taking variable I am mentioning below sample code which by which we can apply css on user picture or auther picture div:
Comment #30
ivan berezhnov commentedComment #42
quietone commentedThis doesn't happen on 11.x with Olivero.