Closed (fixed)
Project:
Search and Replace Scanner
Version:
2.0.x-dev
Component:
Code
Priority:
Normal
Category:
Bug report
Assigned:
Unassigned
Issue tags:
Reporter:
Created:
2 Feb 2021 at 16:53 UTC
Updated:
16 Jul 2026 at 17:51 UTC
Jump to comment: Most recent, Most recent file
Comments
Comment #3
mariacha1 commentedActually, 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.
Comment #4
mariacha1 commentedComment #5
sammydigits commentedI applied your patch @mariacha1, but I'm still seeing the same error as you when searching (haven't tried replacing yet)
I definitely need something that goes more than 2 levels deep. Did you make any more progress with this?
Comment #6
rjensen26 commentedGenerating a patch for both mariacha1 fixes with some minor tweaks.. Also added a method_exists() check on getTitle()
Comment #7
rjensen26 commentedFixing additional
getTitle()Comment #8
chrisfromredfinI 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.
Comment #9
rjensen26 commented@cwells, that is a good recommendation.. I do not have time to look into that currently. Is that something you could test??
Comment #10
chrisfromredfinYes, 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.
Comment #11
rjensen26 commentedThanks!
Comment #12
damienmckennaThank 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.
Comment #13
mariacha1 commentedHere'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
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.
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.
Comment #14
jani_pathan commentedCore 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).
Comment #15
jani_pathan commentedPatch for nested paragraphs issue, tested on rc-4
Comment #16
jani_pathan commentedComment #17
damienmckennaComment #18
damienmckennaComment #19
damienmckennaComment #20
mgaskey commentedRerolling patch #15 for rc6
Comment #21
sassafrass commentedI have applied the patch in #20. It applies cleanly to rc6 and works as expected. Thanks!
Comment #22
bdanin commentedThis 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).Comment #23
damienmckennaThat error indicates there's a block being loaded, not a paragraph; we probably need to update the logic to protect against that.
Comment #24
bdanin commentedIt's a paragraph inside a block that's loading.
Comment #25
earthday47I 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.
Comment #26
damienmckennaThanks for rerolling it, glad to see the tests pass now.
Comment #27
damienmckennaThe patch needs work:
1. This line:
That gives off some bad code smell.
2. This part needs cleaning up:
Comment #28
gwvoigtLast 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).
Comment #29
gwvoigtEdit - Accidentally posted twice
Comment #30
gwvoigtModified patch from #25 to address issues from #28
Comment #31
gwvoigtComment #32
banoodle commentedI tried the patch from #30 on D10.2 site, but I still get the error reported in #28.
Comment #33
dmitrii puiandaikin commentedIf 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)
Comment #34
anybodyI 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
Comment #35
anybodyMR!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!
Comment #36
anybodyClosed #3485911: Incompatibility with block_content module as duplicate.
Comment #37
smustgrave commentedCan we update for 2.0.x please
Comment #38
aaron.ferris commentedJust 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
Comment #39
leoenriquezp commentedI've created a patch based on the current merge request, but it can be applied to version
2.0.0-beta1.Comment #40
damienmckennaLet's try to fix this for v2.0.0.
The getTitle() change was moved into #3200455: Call to a member function getEntityTypeId().
Comment #42
damienmckennaSome changes have gone into Scanner that affect the Paragraphs integration, could someone please reroll this? Thank you.
Comment #43
damienmckennaComment #46
damienmckennaThis needs refactoring after #3584678: Refactor search logic to use a method in Entity class was committed.
Comment #49
damienmckennaI 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.
Comment #51
damienmckennaBTW 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.
Comment #52
damienmckennaGoing to assume this is working correctly now, please open a new issue if you spot any problems. Thank you everyone!