Closed (fixed)
Project:
Drupal core
Version:
10.3.x-dev
Component:
block_content.module
Priority:
Normal
Category:
Feature request
Assigned:
Unassigned
Reporter:
Created:
17 Jun 2019 at 21:09 UTC
Updated:
14 Aug 2024 at 19:09 UTC
Jump to comment: Most recent, Most recent file
Comments
Comment #2
rlnorthcuttComment #3
rlnorthcuttIt was pointed out to me that this should actually be in the block_content module, so here is a patch with the code moved there.
Comment #4
phenaproximaI think this is a nice idea. However, it's certainly a feature request and will need both tests and sign-off from a frontend framework manager.
Comment #5
phenaproximaThis is interesting. Why would a view mode have a period in it? Normally, view mode IDs take the form
entity_type_id.view_mode_id, and in this case, the entity type ID will never vary (it will always be "block_content"). So, what might be better is to have $sanitized_view_mode be something like this:I don't think this comment adds much. :)
What is $variables['elements']['#id']? What kind of suggestion name will this produce? I'm not sure this one will be very useful, so maybe we should remove it for now.
Comment #6
rlnorthcuttThanks!
1) I was simply taking the same code from node.module on how it deals with sanitized view modes. Mostly, I just wanted to try and maintain parity with the rest of the system - both nodes and media do the same thing. I assume there is some reason we do it over there, but I am open to changing.
2) Good point. Removed.
3) The block.module already provides a "block__[blockid]" suggestion, so it makes sense to me that we would provide a view mode option as well. If you look at the image example, this would be "block__testblock__full.html.twig". That would allow us to get pretty granular if needed.
Comment #7
krzysztof domańskiI added tests.
Comment #9
krzysztof domański1. Duplicated 'block--block-content.html.twig'. I created a separated issue #3062863: Remove duplicate suggestions block--block-content.html.twig.
2. What about 'block--machinename.html.twig' and 'block--block-content--e81b663b-5755-4daf-889d-7ea1c9857b3d.html.twig'? Their order is incorrect.
See How to bring custom block theme suggestions into the right hierachy?.
Comment #11
krzysztof domańskiComment #14
lauriiiThere's potential for collisions here similar to what has been reported here: #2831144: [policy] Bundle / field name / view mode theme suggestions can conflict. Maybe we should separate these with a prefix to ensure that these don't collide?
Comment #15
ravi.shankar commentedI have re-rolled the patch #11 on Drupal 8.9.x.
Still need to resolve comment #14
Comment #16
rlnorthcuttThis looks good!
Regarding #14, I think we should link this issue over there, and then deal with that separately. We are trying to get some parity here with the existing formats in nodes and media. View mode and bundle name collisions are possible, but I don't think they are very common. Plus, one could always add a new theme suggestion hook for their site if there was a collision.
Since this is a reasonable patch with test coverage, can we assume its ready for review?
Comment #19
brandonratz commentedThis patch confirmed working on 8.7.8
However, this does not address
block--block-inline--[name]--[view-mode].html.twignaming convention for layout inline blocks.Comment #20
anas_maw commentedpatch in #16 worked as expected for me
Comment #22
anybodyConfirming RTBC of this important patch and agree as per #16 to handle that point separately. These suggestions are very important and helpful and will replace current workarounds in many many themes which lead to inconsistent naming conventions.
Thank you all very much, I'm very much looking forward to this.
Comment #23
anybody#ignorethis
Comment #24
anybodyAlternative would be to postpone [PP-1] this on #2831144: [policy] Bundle / field name / view mode theme suggestions can conflict. It's definitely very important to have consistency over all entity types.
Sorry for the self-reference, I copied the wrong issue id... -.-
Comment #34
ravi.shankar commentedHere I have fixing failed tests of patch #15.
As patch #15 didn't pass tests so changing status from RTBC to needs review.
Comment #36
abhijith s commentedApplied patch #34 and it works fine.After applying the patch the suggestion with view mode is appearing.Adding screenshots below.
Before patch:

After patch:

On new block type

Comment #37
anybodyComment #42
robpowellThanks for everyone's work here. I took #38 and created a gitlab MR for it. I tested on 9.5.x which defaults the frontend theme to Olivero. Olivero has some block theme suggestions so I switched back to bartik to do a bare bones test.
Testing steps
screenshots
Marking as needs review and will work on change record.
Comment #44
robpowellhere is the draft change record https://www.drupal.org/node/3304793. Please review and feel free to make updates.
Comment #45
smustgrave commentedFor failing test
Comment #46
smustgrave commentedReran the last commit for 9.5.x
The failure was a random one with the quickedit module. Putting back into NR.
Comment #47
smustgrave commentedComment #49
smustgrave commentedThink at this point we will need to change the MR to point to 10.1.x then we can mark
+1 for RTBC after that.
Comment #51
smustgrave commentedMade a D10 MR.
Comment #52
larowlanLeft some comments on the MR, this looks like a good improvement to me.
Fun fact, my first contribution to core was adding these suggestions to node :)
Comment #53
smustgrave commentedAddressed feedback ready for review again.
Comment #54
smustgrave commentedFrom the thread the test should be updated. Should be verified before running.
Comment #55
smustgrave commented@larowlan actually that is correct. I updated the variable but one is the block and the other the blockContent.
Comment #56
larowlanThere are two MRs here, can we get clarification of which one is the correct one? I assume the one with the larger ID?
I will remove the other one.
Comment #58
larowlanAh one is for 9.5, I closed that as this is a feature and 10.1+ only
Comment #59
smustgrave commentedMade the small tweak.
Comment #60
larowlanThis looks RTBC in my book
Comment #61
lauriii#14 has not been addressed yet. I'm not sure if we should add new suggestions with the known bug because changing these can be quite painful.
A concrete recommendation for tackling this would be to implement the suggestions like this:
Thoughts?
Comment #62
larowlanAh sorry for missing that @lauriii - yes I agree avoiding the known collision now is the best approach
Going to take #61 as an FEFM review and remove the tag (please revert if not appropriate)
Comment #63
amstercadWhile I'm slightly off-topic for this particular thread, I just want to sing my praise for everyone's time and effort on this endeavor because otherwise I wouldn't have been able to complete the module I started to write over 1.5 years ago and shelved in frustration, (as I waited for a Change to happen), after much time and effort myself. Thank you all from the bottom of my heart.
Comment #64
danflanagan8I'm using the patch from #34 but it looks like it's basically the same as the MR. I have a block type called mini-nav. Here are the theme suggestions I see:
I think it's unexpected and undesirable that
block--block-content--2c9df2dd-821b-4147-9bd0-adf8ca05474d.html.twigsuggestion is not more powerful. Certainly the uuid is as specific as you can refer to something, right? I think a preferred list of suggestions would be:It seems like this needs to interact more gracefully with the existing theme suggestions provided by the block module. Maybe this should even be
block_content_theme_suggestions_block_alterand do some splicing, along the lines of what happens inumami_theme_suggestions_block_alter:It does the splice so that the new suggestion comes before the suggestion that features the uuid.
Comment #65
smustgrave commentedSo looking at this to change the order think the code would have to be added to the block module now is that desired?
@laurii not sure I understand the conflict issue?
Comment #66
larowlanSo we need to add an extra prefix to address #14 and I think #64 is valid too, the UUID specific one should trump any general suggestions
I think we need to pick one of the two to have a prefix for #14 - either view mode or bundle.
I think the bundle variation will be more common that the view mode, so suggest we prefix the view mode ones with `view_mode_$view_mode` and keep the bundle as is.
Comment #67
smustgrave commentedSwitched to block alter and got
* block--sidebar--id--olivero-testthemes.html.twig
* block--sidebar.html.twig
* block--olivero-testthemes.html.twig
* block--block-content--90a1a6dd-3b88-45dc-9ed3-fe1aa04dcdd4.html.twig
* block--block-content--olivero-testthemes--full.html.twig
* block--block-content--olivero-testthemes.html.twig
* block--block-content--basic--full.html.twig
* block--block-content--basic.html.twig
* block--block-content--full.html.twig
* block--block-content.html.twig
x block.html.twig
Thoughts?
Comment #68
smustgrave commentedAlso updated suggestion, that address #14?
Comment #69
larowlanLooks like we have a valid test fail
Comment #70
smustgrave commentedAlso need test coverage but what do you think of the order?
Comment #71
larowlanNot sure about the ones with the theme name being more specific - or is that the block ID?
Comment #72
anybody@larowlan:
Yes, looking at the code
olivero-testthemesmust be the block ID. You can see that atblock--sidebar--id--olivero-testthemes.html.twigSo we should come back to the order discussion. As I agree the example might be confusing, it would be best to write down the expected outcome into the issue summary and discuss that (if needed), based on the current example, but with more clear ID's and an explanation perhaps?
@smustgrave would you do that?
Comment #74
smustgrave commentedComment #75
smustgrave commentedThis should be ready for review. Updated issue summary too.
Comment #76
smustgrave commentedComment #77
larowlanThis looks good to me.
I like the extra specificity of the `_view_` and `_view_type_` so we don't get collisions, but it would be good for a FEFM to formerly approve that pattern, so tagging as such.
I'll ping @lauriii as he's already looked at this before
Comment #78
quietone commentedThe issue summary explains clearly what is being done. Although, the remaining task says that there is a remaining task of 'Agree of suggestions'. Has that been done?
I then read the comments. I do see discussion of order, in particular #64. So, that seems to be done. I also see that @larowlan and @lauriii have been reviewing this.
I then read the MR and have commented there.
I read the CR and made a few changes to make the before/after clearer. The version numbers in the CR need to be updated. Also, the examples need to be checked and possibly updated. They are they same one when it was created in Aug 2022.
Just a few things, so setting back to NW.
To committers: I updated the credit, the ones unchecked need to be reviewed.
Comment #79
smustgrave commentedBrought this up in #needs-review-queue-initative and @lauriii said he already reviewed and can remove framework tag.
Have addressed the feedback so back to NR.
Comment #80
larowlanEverything looks to be good to go now here
Comment #81
needs-review-queue-bot commentedThe Needs Review Queue Bot tested this issue. It fails the Drupal core commit checks. Therefore, this issue status is now "Needs work".
This does not mean that the patch needs to be re-rolled or the MR rebased. Read the Issue Summary, the issue tags and the latest discussion here to determine what needs to be done.
Consult the Drupal Contributor Guide to find step-by-step guides for working with issues.
Comment #82
smustgrave commentedI think it's safe to remark this myself. Only fix was https://git.drupalcode.org/project/drupal/-/merge_requests/3094/diffs?co... where machinename became machine_name.
Comment #83
longwaveAdded some questions to the MR.
Comment #84
smustgrave commentedFeedback addressed.
Comment #85
acbramley commentedAdded a small nit on the MR otherwise this looks RTBC, all threads have been resolved and code is looking good.
I've updated the CR versions, but not 100% sure if they are accurate.
Comment #87
isalmanhaider commented+1
Thoroughly reviewed and tested; the proposed solution effectively resolves theme suggestions for custom block view modes. Endorsed for community acceptance.
Comment #88
alt.dev commentedWhile MR isn't merged, I'm attaching a patch based on the latest MR that can be applied to Drupal 10.2.x.
Comment #89
acbramley commentedHiding patches to reduce confusion.
FYI - you can download an MR diff locally and use that in your composer workflow instead of uploading to an issue. e.g https://git.drupalcode.org/project/drupal/-/merge_requests/3094.diff
Comment #90
ravi kant commented@alt.dev
I try to apply patch but getting below message.
Comment #94
nod_Updated CR with suggestion names and fancy emojis
Committed b050dbf and pushed to 11.x. Thanks!
Comment #96
john.oltman commentedI opened the following related issue https://www.drupal.org/project/drupal/issues/3468180