Problem/Motivation

When the style plugins provide their templates, they are not always used since they don't seem to be added at the end of the suggestions array.

Proposed resolution

Ensure that the template suggestions are added at the end.

Remaining tasks

User interface changes

API changes

Data model changes

Support from Acquia helps fund testing for Drupal Acquia logo

Comments

yongt9412 created an issue. See original summary.

johnchque’s picture

Status: Active » Needs review
FileSize
4.37 KB

This should work, adding tests. Need to update tests, doing that.

johnchque’s picture

So this should be a better test, forgot about it. Not sure why it is not taken the paragraph type template.

The last submitted patch, 2: ensure_style_templates-2965637-2.patch, failed testing. View results
- codesniffer_fixes.patch Interdiff of automated coding standards fixes only.

Status: Needs review » Needs work

The last submitted patch, 3: ensure_style_templates-2965637-3.patch, failed testing. View results
- codesniffer_fixes.patch Interdiff of automated coding standards fixes only.

johnchque’s picture

Status: Needs work » Needs review

Not really sure why it fails, it seems that the quote Paragraph type has its own template to be overriden. My changes did not do anything related with the quote type.

Berdir’s picture

Status: Needs review » Needs work
+++ b/paragraphs_collection.module
@@ -18,9 +18,9 @@ function paragraphs_collection_paragraph_access(EntityInterface $entity, $operat
 /**
- * Implements hook_theme_suggestions_HOOK().
+ * Implements hook_theme_suggestions_HOOK_alter().
  */
-function paragraphs_collection_theme_suggestions_paragraph(array $variables) {
+function paragraphs_collection_theme_suggestions_paragraph_alter(array &$suggestions, array $variables) {
   $suggestions = [];

as discussed, you drop the existing suggestions here. you also don't need to return them anymore (as they are altered by reference), but you do want to keep the early return.

+++ b/tests/themes/paragraphs_collection_test_theme_a/templates/paragraphs/paragraph--separator--test-template.html.twig
@@ -0,0 +1,6 @@
+{#
+/**
+ * @file
+ * Theme override for paragraph separator.
+#}
+{% block content %}paragraph-style-template{% endblock %}

replacing the template *only* with your change could be confusing when debugging. I would suggest you instead extend from the default paragraph.html.twig and just *add* a static line, to assert that it is there.

johnchque’s picture

Status: Needs work » Needs review
FileSize
4.86 KB
2.24 KB

Yeah, sorry my bad, didn't realize that I have removed that. :)

Berdir’s picture

Status: Needs review » Needs work
+++ b/src/Tests/ParagraphsStylePluginTest.php
@@ -553,4 +553,45 @@ class ParagraphsStylePluginTest extends ParagraphsExperimentalTestBase {
+    ];
+    $this->drupalPostForm(NULL, $edit, 'Save');
+    // Assert that the text of the templates are displayed.
+    $this->assertUniqueText('paragraph-style-template');
+    $this->assertUniqueText('paragraph-type-template');

Hm. You're not *really* sure that the right paragraph is using the right template with this.

I would do it with a single paragraph that you change. First create it without a style value, save. Make sure it shows the type template.

Then edit, select a style and save again, make sure it uses the other template now.

johnchque’s picture

Status: Needs work » Needs review
FileSize
5.18 KB
1.61 KB

Right, now should be better. :)

  • Berdir committed 832ff1a on 8.x-1.x authored by yongt9412
    Issue #2965637 by yongt9412: Ensure that the style templates are added...
Berdir’s picture

Status: Needs review » Fixed

Thanks, looks good.

Status: Fixed » Closed (fixed)

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