Problem/Motivation

When an index includes a field like "body:processed", the rendering process uses a different theme when the item is saved and indexed individually or using the index UI to trigger a bulk index. Those processes use the admin theme but using Drush to index uses the default theme.

Steps to reproduce

  1. Create an index for a content type that uses the field's ":processed" value.
  2. Drop a breakpoint in web/core/lib/Drupal/Core/Render/Renderer.php, renderPlain() to see the active theme during the indexing process.
  3. Edit a node and note the active theme at the breakpoint.
  4. Run the full, bulk indexing process using the UI and note the active theme at the breakpoint.
  5. Run the full, bulk indexing process using drush and note the active theme at the breakpoint.

Each of these indexing process should be using the same theme for data integrity.

Proposed resolution

Remaining tasks

Comments

weekbeforenext created an issue. See original summary.

weekbeforenext’s picture

weekbeforenext’s picture

Version: 8.x-1.27 » 8.x-1.x-dev
Status: Active » Needs review
StatusFileSize
new6.19 KB

Attached is a patch. Not sure if it's the best solution, but it's a first attempt that seems to be working.

  • I copied theme switching code from RenderedItem.php, addFieldValues() into FieldHelper.php, extractField() and a new method, themeSwitched().
  • Updated the search_api.services.php to include theme and config services.
  • If TextProcessed is being used to render a field value, and admin is the active theme, the theme is switched before processing and back again when complete.
weekbeforenext’s picture

StatusFileSize
new6.64 KB

New patch that defines the themeSwitched() method in the FieldsHelperInterface.

Status: Needs review » Needs work
weekbeforenext’s picture

Status: Needs work » Needs review
StatusFileSize
new7.88 KB

Added test fixes.

weekbeforenext’s picture

Status: Needs review » Needs work
weekbeforenext’s picture

StatusFileSize
new9.43 KB

Fixed more tests...

weekbeforenext’s picture

Status: Needs work » Needs review
drunken monkey’s picture

StatusFileSize
new18.7 KB

Thanks for reporting this issue and already providing a patch for fixing it!
However, if the code is exactly the same in both places, then we should probably make it reusable in general. Unfortunately, this doesn’t really fit on any of the existing services, so I propose adding a new one. Patch attached, please test/review!

weekbeforenext’s picture

Thanks for the new patch! I like how the theme switching is now abstracted into it's own service.

The patch applies successfully. I verified the test instructions for a project ticket that kicked off this issue and they still pass.

Reviewing the patch itself, the code looks good to me.

Thanks again!

weekbeforenext’s picture

Status: Needs review » Reviewed & tested by the community

drunken monkey’s picture

Status: Reviewed & tested by the community » Fixed

Great to hear, thanks a lot for testing and reviewing!
Merged.
Thanks again!

Status: Fixed » Closed (fixed)

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