Problem/Motivation
A common issue site builders face is adding a related content block based on categories. This is doable only with Drupal core, but people assume they will need a contrib module for that. Let's provide a related recipes block on the recipe full page, so we can demo that, and also point them to an example when they ask for support for doing this.
Proposed resolution
Add a block with related recipes view content based on category. E.g. if I look at a dessert, I see other dessert recipes linked.
Remaining tasks
Patch with config.
User interface changes
Recipe detail will have a block at the bottom with related recipes.

API changes
None.
Data model changes
None
Release notes snippet
None.
| Comment | File | Size | Author |
|---|---|---|---|
| #43 | Screenshot 2023-09-08 at 12.51.07 PM.png | 1.37 MB | smustgrave |
| #23 | umami-related-es.png | 377.47 KB | penyaskito |
| #18 | Screen Shot 2023-04-26 at 22.39.54.png | 1.32 MB | lauriii |
| #14 | Screenshot 2023-04-05 at 09.25.58.jpg | 549.26 KB | markconroy |
| #12 | 3312072-umami-related-recipes-block-12.patch | 11.07 KB | penyaskito |
Issue fork drupal-3312072
Show commands
Start within a Git clone of the project using the version control instructions.
Or, if you do not have SSH keys set up on git.drupalcode.org:
Comments
Comment #2
penyaskitoAdded screenshot.
Comment #3
penyaskitoAttached patch with config. Not sure what happened but the commands for working with the issue fork are failing on my side.
Comment #4
ckrinaNice feature!
I would suggest, on a design perspective, do either:
Comment #5
penyaskitoIf you mean "region" as in "theme region defined in umami.info.yml", we would need to make the block part of the block system and not layout builder as I did (as far as I know, you cannot define a layout builder section in a different region).
I think it's pretty cool showing that layout builder allows to place this kind of blocks, but I think we have other examples of that in umami.
If you mean "region" as "visual region", I need to check how you can add a css class or something to a section in layout builder. I'm pretty sure that's something doable with preprocess methods, but never done that before so I'd need to do some research.
Comment #6
ckrinaYeah, sorry, I meant "visual region". If that's too complicated I'd be fine with option 1, which is adding more margin on top of the block so it's visually separated from the content and perceived as "extra info".
Comment #7
penyaskitoI got a nice PM today on Slack:
Aside of the kind words which I appreciate, this validates that providing this as an example in umami is needed. I'll prioritize getting this in.
Comment #8
markconroy commentedLet's remove 'grid' here and set it to 'Unformatted list'. Then in the views CSS field, add grid--3 as a class (this is what we do for the layout of the articles and recipes pages).
Once that's done, and the extra spacing requested by @ckrina I think this will be ready for RTBC.
Comment #9
markconroy commentedPatch attached to address items from #8
Comment #10
penyaskitoLove it!
Attached screenshot and updated it in issue summary. CSPell is complaining about the css rule, but don't know how we could change that taking into account that the css rule comes from the layout builder block class.
Comment #11
penyaskitoNot sure how that is related to this issue, but the style isn't applied when using core css aggregation.
Comment #12
penyaskitoMinor adjustments to the view (changed id, add human readable label, added description). Renamed css class per the view changes. Added css generated name to dictionary.
The previous problem with css agreggation enabled still applies.
Comment #14
markconroy commentedThis looks perfect to me, and is working fine even with CSS aggregation turned on. Screenshot here for CSS aggregation:
Comment #16
penyaskitoThat MR was an accident :_)
Comment #18
lauriiiLooks like we are missing a Spanish translation:
Comment #19
markconroy commented@lauriii Not everything in Umami is translated. That is by design to show what happens with fallbacks when items are not translated.
Comment #20
lauriiiAlthough translation fallbacks can be useful in certain situations, I don't believe they're appropriate in this case as they can create confusion and give the impression that something is broken or not finished. Even if we have the capability to do something, it doesn't necessarily mean it's a good fit for the particular use case. Fallbacks could make sense as a backup solution or when handling dialect translations. However, in many scenarios, they tend to result in a subpar user experience.
Comment #21
markconroy commented@lauriii The screenshot you uploaded (Spanish) seems to have the very same recipes as the screenshot I uploaded (English). What translation is missing?
And should we create a follow up issue to have that translated, instead of allowing it to hold up this issue. Also, remember, this is a demo site, not a real live site so maybe it's okay if there's a translation missing.
Comment #22
lauriii"Related recipes" title, "Difficulty" label and value of that field, and the "View recipe" link are missing a translation. I think we should be able to get that resolved with @penyaskito without the hassle of a follow-up 😇.
It's certainly not a live site but it's something people use to give demos about Drupal. I agree that there's a balance between good and perfect but something like missing translations may appear unfinished, and I don't think that's a the impression we want to give. I think an alternative solution which balances both needs could be hiding the block on the Spanish translation, in the case that we can't get the strings translated.
Comment #23
penyaskitoNew install of umami with the patch applied.
(ddev drush si demo_umami --yes)
The only missing translation is the title of the block.
@lauriii I don't think we are using anything for interface/config translation in umami aside of localize.drupal.org. In that case we can't translate that string until this is released with at least an alpha.
Comment #25
penyaskitoTest failure seems unrelated, back to RTBC
Comment #28
penyaskitoTest failure seems unrelated, back to RTBC
Comment #31
lauriiiCommitted 1c7e6e6 and pushed to 11.x. Thanks! Also cherry-picked to 10.1.x since Umami is forever experimental.
Comment #32
spokjeLooks like this has broken HEAD of
10.1.xand11.xbut only for pgsql:If we look at the HTML-artifacts (https://dispatcher.drupalci.org/job/drupal_patches/194048/artifact/jenki...) we see a:
EDIT: Looking at the code (or rather lack of any) in the commit, it's more probable this has "just" uncovered an already present bug.
Comment #34
lauriiiThanks @Spokje, reverted to sort out PostgreSQL.
Comment #36
penyaskitoRequeued the patch with pgsql too.
Comment #37
penyaskitoWe will need a new issue for that. Haven't created that yet, but I'm looking at this. Sounds similar to #3364621: Drupal\Tests\file\Kernel\Views\RelationshipNodeFileDataTest fails on HEAD with PostgreSQL, just that this would be when the Tid argument/default_argument is used in views.
Comment #38
penyaskitoStill don't have a proper patch, but the problem is here:
The value is "123,12,3" but we are not separating that, and considering a single value instead.
Comment #39
fjgarlin commentedThis happens because the generated query seems to be:
(node__field_recipe_category.field_recipe_category_target_id = :node__field_recipe_category_field_recipe_category_target_id)))and the replacement pattern is[:node__field_recipe_category_field_recipe_category_target_id] => 31,22,13As @penyaskito said, we are not separating that, so
$this->value = [$this->argument];which will have actually just one value, so will make the query use "=" instead of "IN".Maybe all we need is "break_phrase: true" added to the new view.
Comment #41
fjgarlin commentedJust created an MR with the changes that were initially committed (and then reverted) plus the suggestion of changing "break_phrase" to "true".
https://git.drupalcode.org/project/drupal/-/merge_requests/4708/diffs#3f...
Will trigger tests for MySQL and PosgreSQL.
Comment #42
fjgarlin commentedAll tests are green now for the three DB types.
Please review and also test manually.
Comment #43
smustgrave commentedTested with a fresh install of Umami with MR 4708 applied
Going into a recipe I see the related ones
See
LGTM!
Comment #44
lauriiiCommitted dbb54ac and pushed to 11.x. Also cherry-picked to 10.1.x since Umami is experimental. Thanks!