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.
It would be nice to have contextual links activated on media/{mid} pages. Its also nice to use quickedit on these pages.
Comment | File | Size | Author |
---|---|---|---|
#64 | contextual_links.png | 108.2 KB | xjm |
#56 | interdiff-51-56.txt | 2.23 KB | seanB |
#56 | 2775131-56.patch | 2.47 KB | seanB |
#51 | interdiff-43-50.txt | 1.96 KB | marcoscano |
#51 | 2775131-50.patch | 3.56 KB | marcoscano |
Comments
Comment #2
chr.fritschHere is a first patch. We already have a dependency to the entity module, so we could use their EntityViewBuilder which supports contextual link building.
Comment #3
slashrsm CreditAttribution: slashrsm at MD Systems GmbH commentedCan we print entire title_suffix here?
When was this class added to the Entity module? Do we need to raise minimum version of the dependency?
Comment #4
chr.fritschtitle_suffix.contextual_links will be set from the contextual module if $element['#contextual_links'] is set. This is done by Drupal\entity\EntityViewBuilder.
So no new dependencies here
Comment #5
gippy CreditAttribution: gippy as a volunteer commentedI tested this with simplytest.me. The patch worked exactly as described.
Comment #6
phenaproximaAh, video proof! Love it. :) Thank you, @gippy and @chr.fristch!
So, this seems like an issue that is quite possibly affecting the core Media system as well. We should definitely fix it there, since we've pretty much halted development on Media Entity 1.x in favour of core Media. We'll certainly need automated tests for this, but I see no reason why we shouldn't address this once #2831274: Bring Media entity module to core as Media module lands.
I'll be adding this to the list of issues that comprise the core Media MVP: #2825215: Media initiative: Roadmap
Comment #7
phenaproximaComment #8
phenaproximaThis issue is now part of the core Media Initiative. Postponed on #2831274: Bring Media entity module to core as Media module.
Comment #9
phenaproxima#2831274: Bring Media entity module to core as Media module is in! No longer postponed.
Comment #10
dawehnerrelying on the entity module certainly doesn't fly :) Maybe we could bring this particular class into Drupal core?
Comment #11
phenaproximaOooh, nice catch. It seems like bringing the view builder from Entity API to core would be a giant pain in the ass in relation to the scope of this issue, though...surely we can do it some other way that doesn't involve moving parts of Entity API into core?
Comment #12
katzillaAdded a new class: MediaViewBuilder and adapted code from NodeViewBuilder to add contextual links. Also added the title_suffix to classy and stable media.html.twig, so this should be tested in those themes.
Comment #13
katzillaComment #14
webflo CreditAttribution: webflo at UEBERBIT GmbH commentedWould be sufficient and more in line with other docs in core.
template_preprocess_media provides no label variable. Its "name" in this case.
Comment #15
katzillaAdded a new patch with suggestions from @webflo. Still works ;)
Comment #16
phenaproximaAs far as I know, the only circumstances under which $entity->id() would be falsy is if the entity is new...in which case we should be using the more generalized
if (!$entity->isNew()) {...}
I don't understand why this was done, or how it works. Where is name being set? I'm sorry if I'm being dense here, I'm just not sure what this change is doing in the context of this patch.
It looks like we're now echoing content whether or not it is empty, which is a change from the way it was before. Why is that being done? As with my previous comment, I'm not against it but I'm wondering why it was done.
Comment #17
katzilla@phenaproxima - thanks for your feedback!
Just a few words for 2 and 3, I'll check 1 later.
2.) The name variable comes from core/modules/media/media.module - there is a preprocess function: template_preprocess_media.
3) If content variable is empty, nothing gets rendered in Twig, so there is no need to check, if it is empty. We will not get an exception. Also this is how it is done in node template for example. No if statement.
Comment #18
chr.fritschI adjusted the code regarding #16-1
Comment #19
chr.fritschComment #20
phenaproximaRe-tagging. The patch looks good to me, but it still needs tests.
Comment #21
chr.fritschOk, here with a very simple test, to check that contextual links will be rendered.
Comment #23
Berdiroops.
should we check the revision as well? Edit: Ah, see below, looks like there actually are no revision contextual links, not sure if this is added then or not.
I'm fine with adding it just to media in this issue, but I'm wondering if we already have an issue to add it to the parent? Seems fairly save to do and shouldn't really conflict with anything as long as the entity type doesn't define contextual links. If there is no issue yet, can we open one?
Edit: We could also introduce the concept of a contextual links handler, the view builder could call that and we could also let it generate the contextual link definitions automatically?
What I'm wondering about a bit is that we add media_revision contextual link info as well, if I understand this correctly, this works through the contextual links group, but neither node nor media actually have revision contextual links?
Comment #25
chr.fritschComment #26
phenaproximaPostponed on #2791571: Automatically supply contextual links for entities.
Comment #27
chr.fritschPatch now based on #2791571: Automatically supply contextual links for entities
Comment #28
chr.fritschWohoo, #2791571: Automatically supply contextual links for entities landed.
So let's finish this one.
Comment #29
phenaproximaThis seems out of scope; why was this change made?
Other than that, this looks pretty good...
Comment #30
chr.fritschYeah, this is currently an issue in our media.html.twig...
Which we have to fix it to get the contextual links support working.
Comment #31
marcoscanoI have manually tested and this works as expected. No big remarks on the patch, except a very minor observation:
Probably only
'contextual',
is needed here. The base class already declares all others, and they all get added in the end.I also don't mind the change mentioned in #29, even if unrelated. So for me this is +1 RTBC.
Comment #32
chr.fritschThanks, @marcoscano for reviewing.
I fixed the remarks from #31 and adjusted the test accordingly to NodeContextualLinksTest.
Comment #33
marcoscanoAssuming the bot doesn't complain, this looks good :)
Comment #35
Gábor HojtsyHm, stable is meant to be stable, especially for a stable module :) I would refer to @laurii on what exactly is allowed to be changed with stable templates.
Comment #36
phenaproximaTagging for review by front-end experts :)
Comment #37
BerdirI'm not sure about this.
I understand we need the title prefix/suffix stuff for contextual links to work, correct?
But this makes more changes, it introduces similar title/name logic that node templates have, including the hardcoded view_mode (in case of node it is the is page flag, but that makes little difference).
What this means is that it basically undoes your own recent change to make the display of the name configurable and it will *always* be there. The thing is that #2912298: Make media name available on manage display did not add any actual test coverage that it works, it merely tests that the API set it to configurable, not that the template actually respects that.
If anything, then we need to show content.name and check for that being visible. thinking about it, I'd even expect this to display the title twice, once in content if configured and then additionally hardcoded.
Comment #38
lauriiiFirst of all, I'm changing the category to a bug report as this is a bug where media entities are not compatible with contextual links.
Secondly, I noticed that the templates media module is providing do already support contextual links. Therefore this bug only exists when Stable or Classy are being used.
Looking at the media templates it seems like the templates inside the module have been already been off-sync from Stable and Classy and I'm not sure what is the reason for that. I didn't find any information from #2831274: Bring Media entity module to core as Media module related to that.
According to our BC policy, we are not allowed to make changes to Stable and Classy. However, if we can come up with a non-disruptive way to solve this, the maintainer team could consider making an exception in this case.
I'm not sure if I understand the reason for adding the hardcoded title into the template. Could we remove that since it shouldn't be a requirement for supporting contextual links?
Comment #39
seanBThanks for pointing me here Berdir! This seems to conflict with #2930788: Do not show name by default in media displays. If we use a view mode to render media in entity reference fields by default, this means you will always get the media title. That will also break the change in #2895382: Hide label, thumbnail, etc. for default display of media file and image references.
I don't know enough about how the contextual links work, but hardcoding the H2 is definitely an issue.
Comment #40
marcoscanoThis might explain why the title is not being shown twice :)
#2931057: Media template should use 'name' instead of 'label'
Comment #41
seanBThe patch in #32 contains the same change as #2931057: Media template should use 'name' instead of 'label'. Let's fix the other issue first before we continue here.
Comment #42
marcoscanoThis should definitely be solved after #2930788: Do not show name by default in media displays is fixed.
For reference, this is a patch rerolled on the top of #2930788-33: Do not show name by default in media displays.
Comment #43
marcoscano#2930788: Do not show name by default in media displays landed, so we should be good to go with this now.
Comment #44
phenaproximaThanks, @marcoscano!
Despite the fact that this patch changes Stable, it is a bug fix and therefore probably justifiable from a BC standpoint, as @lauriii pointed out in #38. So I think this is RTBC.
Comment #46
marcoscanoTestbot glitch
Comment #47
alexpottThis looks super odd... just printing the suffix without the rest. I guess this is because contextual links just add themselves to the title_suffix. Should we add a comment to the template header to explain this? Or we could change this to
{{ title_suffix.contextual_links }}
which would be self-documenting. Not sure.Comment #48
phenaproximaI like the idea of that, but there are two problems I can see:
Personally, I think we should just add a comment in the template header to explain, and leave it at that.
Comment #49
BerdirComment works for me.
There's also the theoretical option of re-thinking those special title suffix/prefix variables, how they're named and placed. But I'm not surehow to exactly make changes there in a BC compatible way.
Btw, the node template only adds those if there is a title, meaning not on the node page. This now adds them always, does this mean that there are now also contextual links on the media page? Or is contextual module already not adding them on the full page?
Comment #50
alexpottWell they'll be thwarted trying to alter the title or title_prefix too? Won't these problems surface later too? I think doing the minimum necessary to support contextual links is preferable to adding something which looks super obscure and begs more questions - ie? Where's the title this is suffixing? Where's the prefix?
Comment #51
marcoscanoAdded a comment to the templates.
Comment #52
phenaproximaIMHO, stuffing the contextual links into {{ title_suffix }} is the source of the confusion, but that was a decision made long ago. Contextual links should be their own template variable, precisely to eliminate such implicit weirdness. But that would be outside the scope of this issue. Follow-up, maybe?
I think the template comment @marcoscano added in #51 should be enough to reduce themer confusion in the short term until the title_suffix and title_prefix can be properly untangled, which will obviously take a much longer time. So I'm moving this back to RTBC.
Comment #54
marcoscanoTestbot misbehaving
Comment #55
alexpottI woke up this morning thinking about the principle of least astonishment and I think the solution here violates that. Because if you are printing title_suffix you would expect both the title and the title_prefix to be printed as well. I think the solution that just prints the contextual links is the better and least surprising solution. I can imagine things in custom and contrib that add opening tags to title_suffix and closing things to title_prefix and this is going to be broken by this change.
Comment #56
seanBI agree with alexpott. Showing the contextual links only is more explicit for now. Moving the contextual links to it's own variable would be way better, but that is a separate issue.
Updated the patch.
Comment #57
alexpottDiscussed with @phenaproxima on slack. tldr; we agreed that
{{ title_suffix.contextual_links }}
was the best solution with the least possible side effects.Here's the discussion:
phenaproxima: @alexpott So about the contextual links...IMHO the least astonishing way to do it is to do what every other template in core does
phenaproxima: @alexpott Because if we have to change it later, in stable, we will be breaking BC
alexpott: @phenaproxima so then you have to add the title and title_suffix - which you can't do.
phenaproxima: @alexpott Why? We can just add {{ title_prefix }} and {{ title_suffix }} with no title between them.
alexpott: But that is also astonishing
phenaproxima: @alexpott But is it less astonishing than just showing the contextual links?
alexpott: In my opinion yes. We have no way for things to arbitrarily dump stuff into templates - contextual is using title_prefix to do this and it is super weird. But just printing title_suffix.contextual to enable contextual links in media is totally unastonishing given how contextual links works. Also printing just title_suffix.contextual is the smallest way to fix the actually bug with the least amount of possible side effects
phenaproxima: @alexpott Well, I just asked another opinion and they agree with you, so I guess I concede this one
alexpott: Which, I think is also preferred given the imponderables of what people do on real sites
phenaproxima: @alexpott I'd rather just get contextual links working than debate it for very long =P
alexpott: @phenaproxima "just get contextual links working" = do smallest possible change with least possible side effects :slightly_smiling_face:
phenaproxima: @alexpott Okay then :slightly_smiling_face: We agree. We should have a follow-up, maybe, to untangle contextual links from the prefix/suffix variables
There are issues about how contextual uses title_suffix in the core queue, for example: #2933695: Make contextual links less intrusive to front end templates maybe we need a more generic one.
Comment #58
xjm#52 - #57 seems reasonable.
The current patch though is still making changes to Stable and Classy, which @lauriii raised in #38 with the previous approach because it's a BC break. I think we'd need frontend framework manager's signoff if we were to go ahead with changing the stable base templates.
To avoid breaking BC for the stable base themes, we could make the change to the Media template itself and copy it to Bartik and Seven, but not change the base themes. (A followup could do that later if we decide the bug is buggy enough to break BC for the base themes.)
A second opinion might be good but let's start with that for now and maybe file a followup. I'll also ping @lauriii for his thoughts again.
Comment #59
lauriiiThe latest patch seems to have addressed concerns that I brought up in my previous comment. I also think that the current approach is fine - we don't have to solve problems outside the scope of this issue.
I think on this issue it would be worth taking the risk to break BC and provide this fix in Classy and Stable. This change is in the safer end of potential changes that could be done (adding a new child element inside a pre-existing wrapper). Also, not fixing this bug in Classy and Stable would cause confusing UX because of missing contextual links on some sites.
It would be great if we could have a small change record explaining the change in the markup to make sure developers are aware that this might affect their sites.
Comment #60
xjmThanks @lauriii! So then we just need the CR and then this can have its final review.
Comment #61
marcoscanoCreated CR: https://www.drupal.org/node/2935088
Not sure if the impact on themers should be more explicit, please advise if so.
Thanks!
Comment #62
phenaproximaThen I think we’re ready.
Comment #63
xjmI added a bit more explicit statement about the impacts:
https://www.drupal.org/node/2935088/revisions/view/10782605/10782949
Comment #64
xjmAlright, the approach has signoff from a frontend maintainer, the CR is in place, and I manually tested and confirmed it resolved the issue without any side effects:
Saving issue credit.
Comment #66
xjmCommitted to 8.5.x and published the CR. Thanks!
Comment #67
tstoecklerI think #51 rather than #56 was committed here by accident.
Comment #68
xjmWhoops, good spot. Fixed, thanks.
Comment #71
bgilhome CreditAttribution: bgilhome commentedPatch for backport to 8.4.x-dev at https://www.drupal.org/project/drupal/issues/2948838.