Ensure that nested paragraphs work properly and do not cause problems.

Issue fork scanner-3196119

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

mariacha1 created an issue. See original summary.

mariacha1’s picture

Status: Active » Needs work

Actually, once I got into the code, there are a few problems with this whole section.

The initial issue patch on https://www.drupal.org/project/scanner/issues/3095812 solves the issue of a paragraph with a top-level null reference, but doesn't re-check the parent entity to make sure it's not null if you've got a nested set of paragraphs. So if I had my Cards -> Card nesting on a node with NID 1 and then deleted that node and somehow the paragraphs persisted, I need to re-check that the parent exists at each reference. The additional patch at https://git.drupalcode.org/project/scanner/-/merge_requests/1/diffs?comm... does that.

It feels pretty ad-hoc though. What I really want to do is pull that whole logic into its own function that runs right after if (!empty($paragraph)) { so we don't have to keep checking the status of the parent in this function.

It's also a bit disingenuous, because it looks like the replace function only replaces 2-levels deep of paragraphs, so showing results for paragraphs nested 10 levels down or whatever will imply that the changes will take when they never will. So ultimately that while loop should just be a second, two-level check to match the logic in https://git.drupalcode.org/project/scanner/-/blob/8.x-1.x/src/Plugin/Sca...

But for now, this patch seems to work.

mariacha1’s picture

Title: Error on search-only for deep-nested paragraphs » Errors on search-only for deep-nested paragraphs
sammydigits’s picture

I applied your patch @mariacha1, but I'm still seeing the same error as you when searching (haven't tried replacing yet)

Error: Call to undefined method Drupal\paragraphs\Entity\Paragraph::getTitle()

I definitely need something that goes more than 2 levels deep. Did you make any more progress with this?

rjensen26’s picture

StatusFileSize
new3.96 KB

Generating a patch for both mariacha1 fixes with some minor tweaks.. Also added a method_exists() check on getTitle()

rjensen26’s picture

StatusFileSize
new4.61 KB

Fixing additional getTitle()

chrisfromredfin’s picture

I think this does not take into account the fact that paragraphs could be attached to other types of entities, though. For example, we have a block type that we use with layout builder, that has a paragraph on it, that then nests another paragraph in that (Accordion Items, Accordion Item, ex.g.).

I think perhaps we need to traverse getParentEntity() until the parent entity type !== 'paragraph'?

We get 'call to undefined function BlockContent::getParentEntity()' even with this patch applied.

rjensen26’s picture

@cwells, that is a good recommendation.. I do not have time to look into that currently. Is that something you could test??

chrisfromredfin’s picture

StatusFileSize
new4.82 KB

Yes, that seems to work much better. I have a test site where I have a paragraph with paragraphs in it. I have applied that pattern to a custom block type and a node. No more breaking with block_content. I think it requires a re-think of iterating on paragraphs until you get to a non-paragraph. Updated patch.

rjensen26’s picture

Thanks!

damienmckenna’s picture

Version: 8.x-1.0-rc4 » 8.x-1.x-dev
Issue tags: +Needs tests

Thank you for working on this, it's appreciated.

The patch needs a reroll. And I think some test coverage would be best to ensure it works as expected and doesn't break in the future.

mariacha1’s picture

Here's an updated patch that has the getTitle() work in it, but also pulls the concept of the parent out into a couple of functions:
https://git.drupalcode.org/project/scanner/-/merge_requests/1.diff

getValidParent

which gets the parent of the current paragraph AND validates that it's not an orphan (so also verifies that the parent claims that paragraph in the field it's pointed to.

getRootParentEntity

That loops through all the paragraphs' parents until it either encounters an orphan or finds a non-paragraph parent.

I'll work on trying to get some tests in too -- this patch doesn't do that yet.

jani_pathan’s picture

Core Drupal 8.9.16. I have a relationship of "node -> paragraph ->nested paragraph" entity reference. I have tried applying the patch https://git.drupalcode.org/project/scanner/-/merge_requests/1.diff

Error: Drupal\Core\Entity\Query\QueryException: 'wp_page_header_v1' not found in Drupal\Core\Entity\Query\Sql\Tables->ensureEntityTable() (line 368 of /Users/projects/web/core/lib/Drupal/Core/Entity/Query/Sql/Tables.php).

jani_pathan’s picture

StatusFileSize
new4.74 KB

Patch for nested paragraphs issue, tested on rc-4

jani_pathan’s picture

damienmckenna’s picture

Status: Needs work » Needs review
damienmckenna’s picture

mgaskey’s picture

Issue summary: View changes
StatusFileSize
new4.74 KB

Rerolling patch #15 for rc6

sassafrass’s picture

Issue summary: View changes

I have applied the patch in #20. It applies cleanly to rc6 and works as expected. Thanks!

bdanin’s picture

This still errors for me with a nested paragraph:
ResponseText: Error: Call to undefined method Drupal\block_content\Entity\BlockContent::getParentEntity() in Drupal\scanner\Plugin\Scanner\Paragraph->search() (line 73 of /app/docroot/modules/contrib/scanner/src/Plugin/Scanner/Paragraph.php).

damienmckenna’s picture

Status: Needs review » Needs work

That error indicates there's a block being loaded, not a paragraph; we probably need to update the logic to protect against that.

bdanin’s picture

It's a paragraph inside a block that's loading.

earthday47’s picture

StatusFileSize
new4.24 KB

I needed to reroll the patch in #20 for 1.0-rc7. I made a couple of code formatting tweaks but left the logic alone - there are some things in there that are a little unusual, goto and while(1==1) , that make it a little hard to follow. It probably needs a little more work.

damienmckenna’s picture

Status: Needs work » Needs review

Thanks for rerolling it, glad to see the tests pass now.

damienmckenna’s picture

Issue summary: View changes
Status: Needs review » Needs work

The patch needs work:

1. This line:

+          checkPE:
+            if (is_null($parentEntity)) goto checkPE;

That gives off some bad code smell.

2. This part needs cleaning up:

+                // Two or more levels of nesting.
+                else {
+                  if (!is_null($parentEntity->getEntityTypeId())) {
+                    while (1 == 1) {
+                      if (is_null($parentEntity)) break;
+                      $tempA = $parentEntity->getEntityTypeId();
+                      if (is_null($tempA)) break;
+                      if ($tempA == 'node') break;
+                      $parentEntity = $parentEntity->getParentEntity();
+                    }
+                  }
+                }
gwvoigt’s picture

Last patch gives me:

An AJAX HTTP error occurred.
HTTP Result Code: 200
Debugging information follows.
Path: /batch?id=410&op=do_nojs&op=do
StatusText: parsererror
ResponseText: Error: Call to undefined method Drupal\paragraphs\Entity\Paragraph::getTitle() in Drupal\scanner\Plugin\Scanner\Paragraph->search() (line 115 of /app/web/modules/contrib/scanner/src/Plugin/Scanner/Paragraph.php).

gwvoigt’s picture

Edit - Accidentally posted twice

gwvoigt’s picture

StatusFileSize
new5.38 KB

Modified patch from #25 to address issues from #28

gwvoigt’s picture

Status: Needs work » Needs review
banoodle’s picture

Status: Needs review » Needs work
StatusFileSize
new429.12 KB
new78.7 KB

I tried the patch from #30 on D10.2 site, but I still get the error reported in #28.

Screen shot of AJAX error

Screen shot of watchdog error

dmitrii puiandaikin’s picture

StatusFileSize
new5.43 KB

If a parent entity doesn't have getParentEntity() method, it returns the error below:

Error: Call to undefined method Drupal\block_content\Entity\BlockContent::getParentEntity() in Drupal\scanner\Plugin\Scanner\Paragraph->search() (line 70 of /var/www/html/web/docroot/modules/contrib/scanner/src/Plugin/Scanner/Paragraph.php)

anybody’s picture

I can confirm the issue from #33 regarding incompatibility with block_content (which is quite widely used). I created a separate issue for that now: #3485911: Incompatibility with block_content module

anybody’s picture

MR!1 looks very promising and the logic is much better than the existing. I think we should stop posting patches and instead finish the MR!1. Could someone please check, which changes the MR is missing from the comments and update it accordingly?

I also left some comments. I think we're quite close to fixing this!

anybody’s picture

smustgrave’s picture

Version: 8.x-1.x-dev » 2.0.x-dev

Can we update for 2.0.x please

aaron.ferris’s picture

Just wanted to add some notes from https://www.drupal.org/project/scanner/issues/3448005 which I think can be closed as a duplicate, because this approach should (at least from my local testing) resolve the issue over there. Does need a reroll, which I can try and take a look at.

Setup
1. Drupal 10.3
2. Scanner 1.0/2.0 beta
3. ERR 1.12
4. Paragraphs 1.18
5. Setup as above
6. Add a new paragraph with a string field
7. Add a paragraphs field to the basic page content type, allow references to the new paragraph
8. Add a new basic page
9. Use 'old paragraph value' as the string
10. Save
11. Edit this node
12. Remove the old paragraph, add a new one, use 'new paragraph value' as the field value
13. Save
14. In scanner, search for 'old paragraph value'
15. Expected: 0 results
16. Actual: 0 results
17. Search for 'new paragraph value'
18. Expected: 1 result
19. Actual: 1 result

leoenriquezp’s picture

StatusFileSize
new8.66 KB

I've created a patch based on the current merge request, but it can be applied to version 2.0.0-beta1.

damienmckenna’s picture

Let's try to fix this for v2.0.0.

The getTitle() change was moved into #3200455: Call to a member function getEntityTypeId().

damienmckenna changed the visibility of the branch 3196119-reroll-patch-for-rc6 to hidden.

damienmckenna’s picture

Some changes have gone into Scanner that affect the Paragraphs integration, could someone please reroll this? Thank you.

damienmckenna’s picture

damienmckenna changed the visibility of the branch 8.x-1.x to hidden.

damienmckenna changed the visibility of the branch 3196119-reroll-patch-for-rc6 to active.

damienmckenna’s picture

damienmckenna changed the visibility of the branch 2.0.x to hidden.

damienmckenna’s picture

Status: Needs work » Needs review

I added test coverage in MR!69 that shows pretty deeply nested paragraphs does seem to work now, possibly through some of the refactoring done elsewhere. Can someone please test the current dev version and let me know if the problem still exists for searching only, if so please help expand the test to show the problem and we can look into it further.

  • damienmckenna committed d598645a on 2.0.x
    Issue #3196119 by DamienMcKenna: Test coverage for searching for nested...
damienmckenna’s picture

BTW I've refactored the Paragraphs search logic in #3586025: Refactor Paragraphs search using improved Entity::search() method, so I'd really like to hear if you can confirm problems.

damienmckenna’s picture

Status: Needs review » Fixed

Going to assume this is working correctly now, please open a new issue if you spot any problems. Thank you everyone!

Now that this issue is closed, review the contribution record.

As a contributor, attribute any organization that helped you, or if you volunteered your own time.

Maintainers, credit people who helped resolve this issue.

Status: Fixed » Closed (fixed)

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