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.

Screenshot with a block in the recipe after instructions

API changes

None.

Data model changes

None

Release notes snippet

None.

Issue fork drupal-3312072

Command icon 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

penyaskito created an issue. See original summary.

penyaskito’s picture

Issue summary: View changes
StatusFileSize
new892.43 KB

Added screenshot.

penyaskito’s picture

Status: Active » Needs review
StatusFileSize
new9.82 KB

Attached patch with config. Not sure what happened but the commands for working with the issue fork are failing on my side.

ckrina’s picture

Status: Needs review » Needs work

Nice feature!

I would suggest, on a design perspective, do either:

  1. Leave more space above the block.
  2. (I'd prefer this one) Create a new white (and separated) region that contains this block.
penyaskito’s picture

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

ckrina’s picture

Yeah, 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".

penyaskito’s picture

I got a nice PM today on Slack:

Hi Christian, I just want to let you know my appreciation about the Related Content block you reported (https://www.drupal.org/project/drupal/issues/3312072).

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.

markconroy’s picture

+++ b/core/profiles/demo_umami/config/install/views.view.related.yml
@@ -0,0 +1,301 @@
+        type: grid

Let'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.

markconroy’s picture

Status: Needs work » Needs review
StatusFileSize
new10.68 KB
new3.38 KB

Patch attached to address items from #8

penyaskito’s picture

Issue summary: View changes
StatusFileSize
new278.7 KB

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

penyaskito’s picture

Not sure how that is related to this issue, but the style isn't applied when using core css aggregation.

penyaskito’s picture

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

Status: Needs review » Needs work

The last submitted patch, 12: 3312072-umami-related-recipes-block-12.patch, failed testing. View results

markconroy’s picture

Issue summary: View changes
Status: Needs work » Reviewed & tested by the community
StatusFileSize
new549.26 KB

This looks perfect to me, and is working fine even with CSS aggregation turned on. Screenshot here for CSS aggregation:

Umami with CSS aggregation turned on

penyaskito’s picture

That MR was an accident :_)

lauriii’s picture

Issue summary: View changes
Status: Reviewed & tested by the community » Needs work
StatusFileSize
new1.32 MB

Looks like we are missing a Spanish translation:

markconroy’s picture

@lauriii Not everything in Umami is translated. That is by design to show what happens with fallbacks when items are not translated.

lauriii’s picture

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

markconroy’s picture

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

lauriii’s picture

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

penyaskito’s picture

Status: Needs work » Reviewed & tested by the community
StatusFileSize
new377.47 KB

New install of umami with the patch applied.

(ddev drush si demo_umami --yes)

screenshot in spanish that shows all in spanish but Related recipes block title

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.

Status: Reviewed & tested by the community » Needs work

The last submitted patch, 12: 3312072-umami-related-recipes-block-12.patch, failed testing. View results

penyaskito’s picture

Status: Needs work » Reviewed & tested by the community

Test failure seems unrelated, back to RTBC

Status: Reviewed & tested by the community » Needs work

The last submitted patch, 12: 3312072-umami-related-recipes-block-12.patch, failed testing. View results

Version: 10.1.x-dev » 11.x-dev

Drupal core is moving towards using a “main” branch. As an interim step, a new 11.x branch has been opened, as Drupal.org infrastructure cannot currently fully support a branch named main. New developments and disruptive changes should now be targeted for the 11.x branch, which currently accepts only minor-version allowed changes. For more information, see the Drupal core minor version schedule and the Allowed changes during the Drupal core release cycle.

penyaskito’s picture

Status: Needs work » Reviewed & tested by the community

Test failure seems unrelated, back to RTBC

  • lauriii committed 1c7e6e6a on 11.x
    Issue #3312072 by penyaskito, markconroy, ckrina: Display category-...

  • lauriii committed 76506205 on 10.1.x
    Issue #3312072 by penyaskito, markconroy, ckrina: Display category-...
lauriii’s picture

Version: 11.x-dev » 10.1.x-dev
Status: Reviewed & tested by the community » Fixed

Committed 1c7e6e6 and pushed to 11.x. Thanks! Also cherry-picked to 10.1.x since Umami is forever experimental.

spokje’s picture

Status: Fixed » Needs work

Looks like this has broken HEAD of 10.1.x and 11.x but only for pgsql:

1) Drupal\Tests\demo_umami\Functional\DemoUmamiProfileTest::testDemonstrationWarningMessage
Behat\Mink\Exception\ExpectationException: Current response status code is 500, but 200 expected.

/var/www/html/vendor/behat/mink/src/WebAssert.php:794
/var/www/html/vendor/behat/mink/src/WebAssert.php:130
/var/www/html/core/profiles/demo_umami/tests/src/Functional/DemoUmamiProfileTest.php:74
/var/www/html/vendor/phpunit/phpunit/src/Framework/TestResult.php:728

If we look at the HTML-artifacts (https://dispatcher.drupalci.org/job/drupal_patches/194048/artifact/jenki...) we see a:

Drupal\Core\Database\DatabaseExceptionWrapper: Exception in Related recipes[related_recipes]: SQLSTATE[22P02]: Invalid text representation: 7 ERROR: invalid input syntax for type bigint: "31,22,13" LINE 5: ...recipe_category.field_recipe_category_target_id = '31,22,13'... ^: SELECT "node_field_data"."created" AS "node_field_data_created", "node_field_data"."nid" AS "nid", "node_field_data"."langcode" AS "node_field_data_langcode" FROM "test58917544node_field_data" "node_field_data" LEFT JOIN "test58917544node__field_recipe_category" "node__field_recipe_category" ON node_field_data.nid = node__field_recipe_category.entity_id AND node__field_recipe_category.deleted = :views_join_condition_0 WHERE (((node_field_data.nid != :node_field_data_nid OR node_field_data.nid IS NULL)) AND ((node__field_recipe_category.field_recipe_category_target_id = :node__field_recipe_category_field_recipe_category_target_id))) AND (("node_field_data"."status" = :db_condition_placeholder_1) AND ("node_field_data"."type" IN (:db_condition_placeholder_2)) AND ("node_field_data"."langcode" IN (:db_condition_placeholder_3))) ORDER BY "node_field_data_created" DESC NULLS LAST LIMIT 4 OFFSET 0; Array ( [:node_field_data_nid] => 1 [:node__field_recipe_category_field_recipe_category_target_id] => 31,22,13 [:db_condition_placeholder_1] => 1 [:db_condition_placeholder_2] => recipe [:db_condition_placeholder_3] => en [:views_join_condition_0] => 0 ) in main() (line 19 of index.php). 

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.

  • lauriii committed 7b399734 on 10.1.x
    Revert "Issue #3312072 by penyaskito, markconroy, ckrina: Display...
lauriii’s picture

Thanks @Spokje, reverted to sort out PostgreSQL.

  • lauriii committed f153645d on 11.x
    Revert "Issue #3312072 by penyaskito, markconroy, ckrina: Display...
penyaskito’s picture

Requeued the patch with pgsql too.

penyaskito’s picture

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

penyaskito’s picture

Still don't have a proper patch, but the problem is here:

diff --git a/core/modules/views/src/Plugin/views/argument/NumericArgument.php b/core/modules/views/src/Plugin/views/argument/NumericArgument.php
index b40817b1a2..2a8af51b1b 100644
--- a/core/modules/views/src/Plugin/views/argument/NumericArgument.php
+++ b/core/modules/views/src/Plugin/views/argument/NumericArgument.php
@@ -90,7 +90,7 @@ public function titleQuery() {
   public function query($group_by = FALSE) {
     $this->ensureMyTable();

-    if (!empty($this->options['break_phrase'])) {
+    if (!empty($this->options['break_phrase']) || TRUE) {
       $break = static::breakString($this->argument, FALSE);
       $this->value = $break->value;
       $this->operator = $break->operator;

The value is "123,12,3" but we are not separating that, and considering a single value instead.

fjgarlin’s picture

This 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,13

As @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.

fjgarlin’s picture

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

fjgarlin’s picture

Status: Needs work » Needs review

All tests are green now for the three DB types.

Please review and also test manually.

smustgrave’s picture

Status: Needs review » Reviewed & tested by the community
Issue tags: +Needs Review Queue Initiative
StatusFileSize
new1.37 MB

Tested with a fresh install of Umami with MR 4708 applied
Going into a recipe I see the related ones

See

related

LGTM!

lauriii’s picture

Status: Reviewed & tested by the community » Fixed

Committed dbb54ac and pushed to 11.x. Also cherry-picked to 10.1.x since Umami is experimental. Thanks!

  • lauriii committed dbb54acf on 11.x
    Issue #3312072 by fjgarlin, penyaskito, markconroy, lauriii, smustgrave...

  • lauriii committed 28ada580 on 10.1.x
    Issue #3312072 by fjgarlin, penyaskito, markconroy, lauriii, smustgrave...

Status: Fixed » Closed (fixed)

Automatically closed - issue fixed for 2 weeks with no activity.