Problem/Motivation

Currently much of the logic is hardcoded to do search and replace in nodes. However, on sites using Layout Builder overrides extensively, much of their content is made up of blocks (reuseable or not) placed on nodes.

Proposed resolution

Add a BlockContent scanner plugin.

Remaining tasks

Write tests?

User interface changes

none

API changes

Plugins need to key their search() returns by entity_type:$id instead of just $id.

Data model changes

none

Issue fork scanner-3203383

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

cwells created an issue. See original summary.

chrisfromredfin’s picture

I apologize, my VSCode auto-formats to Drupal coding standards, so there's a bunch of changes in that realm. To that end:

  • there are no substantive changes to ScannerForm. Just coding standards stuff.
  • the new file is the BlockContent scanner plugin, which seems to work in my test cases, which are the block fields themselves, but this is also working replacing paragraphs inside of blocks.
  • in Node.php, I've switched to keying $title_collect by ['entity_type:id'] instead of just [$id]. I discovered that when something was found in /block/1 and /node/1 it would only switch one of theme. This also helps us simplify the view/edit logic in the scanner-results.html.twig template.
  • Paragraphs.php contains the patch from 3196119#10 https://www.drupal.org/project/scanner/issues/3196119#comment-14028687
chrisfromredfin’s picture

Issue summary: View changes
chrisfromredfin’s picture

Status: Active » Needs review
damienmckenna’s picture

Status: Needs review » Needs work

Looks like it needs a reroll.

mariacha1’s picture

Status: Needs work » Needs review
StatusFileSize
new12.67 KB

Here's a re-roll of the patch which ignores the code standard stuff and the work from https://www.drupal.org/project/scanner/issues/3196119#comment-14028687

I'm realizing I don't know how to make a merge request based off another person's merge request! So just going with the old-fashioned patch method.

mariacha1’s picture

StatusFileSize
new13.25 KB
new592 bytes

Reroll misses a fix to the Paragraph plugin that applies the parent's entitytype to the id key. Here's that bit as well.

mariacha1’s picture

StatusFileSize
new13.26 KB
new795 bytes

One more bug I found: The undo function was trying to reset a node revision instead of the block revision.

philosurfer’s picture

#9 fails to patch the twig file, might need to be re-rolled.

  - Applying patches for drupal/scanner
    patches/scanner_support-blocks-3203383-9.patch (add support for sar'ing blocks)
patch '-p1' --no-backup-if-mismatch -d 'web/modules/contrib/scanner' < '/Users/marianocrivello/clones/pantheon/d8-ecompromotions/patches/scanner_support-blocks-3203383-9.patch'
patching file 'src/Plugin/Scanner/BlockContent.php'

patching file 'src/Plugin/Scanner/Node.php'

patching file 'src/Plugin/Scanner/Paragraph.php'

patching file 'templates/scanner-results.html.twig'

1 out of 1 hunks failed--saving rejects to 'templates/scanner-results.html.twig.rej'

patch '-p0' --no-backup-if-mismatch -d 'web/modules/contrib/scanner' < '/Users/marianocrivello/clones/pantheon/d8-ecompromotions/patches/scanner_support-blocks-3203383-9.patch'
patching file 'b/src/Plugin/Scanner/BlockContent.php'
a.griff’s picture

StatusFileSize
new12.8 KB

Patch fixed from the latest updates. Should apply again.

gedvan’s picture

StatusFileSize
new13.35 KB
new1.21 KB

#11 does not include #8 and #9 fixes. Here's a new one.

However, if the block is non-reusable (inline), the result's view/edit links point to an "access denied" page. In this case, it should point to the node containing the block. I'll try to implement this and submit a new patch.

dcam’s picture

Status: Needs review » Needs work

This needs an accessCheck() on the entity query in order to be compatible with Drupal 10. See #3372857: Fix access check on query (Drupal 10 compatibility) which adds it for a Node query.

We're using this patch on a site that just got upgraded to D10 and scanner stopped working as a result of the lack of access checks in the scanner plugins.

dcam’s picture

Status: Needs work » Needs review
StatusFileSize
new0 bytes
new586 bytes

I added the accessCheck().

dcam’s picture

StatusFileSize
new13.42 KB

Sorry, I messed up when creating the patch in #14.

dcam’s picture

Status: Needs review » Needs work

The same change needs to be made to the replace() function. I'll try to come back to it again tonight.

dcam’s picture

Status: Needs work » Needs review
StatusFileSize
new13.5 KB
new530 bytes

I added the access check to the replace() function.

euk made their first commit to this issue’s fork.

anybody’s picture

Status: Needs review » Needs work

I think to speed up the fix here, it would be great to:

  • Revert changes on the other entity types and create a separate issue for these changes
  • Only add Block content support here (which totally makes sense as core entity)

Then I think this should be close to RTBC! Could someone do that?

smustgrave’s picture

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

Lets update for 2.0.x and add some test coverage please.

knyshuk.vova made their first commit to this issue’s fork.

knyshuk.vova’s picture

anybody, It's a good idea.

I also suggest resolving the issue with complex IDs {entityType}:{id} and the template first. This will prevent unnecessary work with MR rerolling. We have few issues with changes to the same conflicting files. Like this one 3196119

MR3 removes $query->accessCheck(FALSE);, it was added correctly in #17 patch

joespinelli7’s picture

Hi all! Is #17 patch working to replace text within Layout builder blocks?

damienmckenna’s picture

Title: Add support for search/replace in BlockContent (and other?) entities » Support BlockContent entities
Component: Code » Integration with other module
Issue tags: +Needs tests

Let's focus this on blocks.

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

damienmckenna’s picture

This will need a rewrite after the refactoring work is done - stay tuned for beta2.

smustgrave’s picture

Status: Needs work » Fixed
Issue tags: -Needs tests

We've simplified things so it was a lot easier to add a new entity. Thanks!

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.