Problem/Motivation

If user pictures are enabled but no user picture is set an empty <article> wrapper prints in node template. Additionally even when there is a user picture the article is untitled.

Proposed resolution

  • Prevent empty markup printing.
  • Remove the article wrapper entirely (however we do that, this should happen).
  • Consider a method for getting the user/author picture directly without any wrapper markup, this should be a renderable array.

Remaining tasks

Discuss and patch.

User interface changes

None.

API changes

None.

Comments

Jeff Burnz’s picture

Jeff Burnz’s picture

Issue summary: View changes
joelpittet’s picture

I 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?

mortendk’s picture

may 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.

Jeff Burnz’s picture

#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?

andypost’s picture

At the same time user picture is a image field now.
So maybe better use a field template override?

Jeff Burnz’s picture

Yes, 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.

mortendk’s picture

my 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.

andypost’s picture

agree about overkill especially for comments that could be hundreds on page

mortendk’s picture

@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

preprocess ...
$author_image = the_image_from_the_user

node.html.twig

{{ autor_image}}

then it still keeps using the picture magic etc right ?

tstoeckler’s picture

So 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...

Jeff Burnz’s picture

Issue summary: View changes

Remove some example code and clarify intentions/discussion points.

Jeff Burnz’s picture

OK, 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.

LewisNyman’s picture

Issue tags: +frontend

Version: 8.0.x-dev » 8.1.x-dev

Drupal 8.0.6 was released on April 6 and is the final bugfix release for the Drupal 8.0.x series. Drupal 8.0.x will not receive any further development aside from security fixes. Drupal 8.1.0-rc1 is now available and sites should prepare to update to 8.1.0.

Bug reports should be targeted against the 8.1.x-dev branch from now on, and new development or disruptive changes should be targeted against the 8.2.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

Version: 8.1.x-dev » 8.2.x-dev

Drupal 8.1.9 was released on September 7 and is the final bugfix release for the Drupal 8.1.x series. Drupal 8.1.x will not receive any further development aside from security fixes. Drupal 8.2.0-rc1 is now available and sites should prepare to upgrade to 8.2.0.

Bug reports should be targeted against the 8.2.x-dev branch from now on, and new development or disruptive changes should be targeted against the 8.3.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

Version: 8.2.x-dev » 8.3.x-dev

Drupal 8.2.6 was released on February 1, 2017 and is the final full bugfix release for the Drupal 8.2.x series. Drupal 8.2.x will not receive any further development aside from critical and security fixes. Sites should prepare to update to 8.3.0 on April 5, 2017. (Drupal 8.3.0-alpha1 is available for testing.)

Bug reports should be targeted against the 8.3.x-dev branch from now on, and new development or disruptive changes should be targeted against the 8.4.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

megan_m’s picture

I 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.

Version: 8.3.x-dev » 8.4.x-dev

Drupal 8.3.6 was released on August 2, 2017 and is the final full bugfix release for the Drupal 8.3.x series. Drupal 8.3.x will not receive any further development aside from critical and security fixes. Sites should prepare to update to 8.4.0 on October 4, 2017. (Drupal 8.4.0-alpha1 is available for testing.)

Bug reports should be targeted against the 8.4.x-dev branch from now on, and new development or disruptive changes should be targeted against the 8.5.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.