Select Text Format in Views Field for textual content with values from search index

Created on 1 May 2017, over 7 years ago
Updated 21 March 2023, over 1 year ago

Problem/Motivation

When pulling views fields from the search index (as opposed to via entity render), the default from \Drupal\search_api\PluginviewsfieldSearchApiStandard imposes the plain text format. However, when HTML content has been pushed into the index for the specific purpose of pulling it out with intact HTML, this escapes the HTML.

Proposed resolution

Use the 'plain' escaoe as a default, but allow views field configuration of text and string fields to select an escape approach from the Drupal system through which to process the values.

Naming this might be tricky, as we have both string and text types that are distinctly used elsewhere. Maybe SearchApiMarkup or SearchApiTextual which is specific in the views data for both types.

Remaining tasks

TBD

User interface changes

Additional select drop-down of existing text formats on Views field configuration modal.

API changes

N/A

Data model changes

N/A

✨ Feature request
Status

Needs work

Version

1.0

Component

Views integration

Created by

πŸ‡ΊπŸ‡ΈUnited States Grayside

Live updates comments and jobs are added and updated live.
  • Needs tests

    The change is currently missing an automated test that fails when run with the original code, and succeeds when the bug has been fixed.

Sign in to follow issues

Merge Requests

Comments & Activities

Not all content is available!

It's likely this issue predates Contrib.social: some issue and comment data are missing.

  • πŸ‡ΊπŸ‡ΈUnited States jhedstrom Portland, OR

    The patch in #35 works as expected, but I'm a bit reluctant to render HTML content with the xss_admin filter (should be safe, but could still allow huge images, etc, that break layouts...)

    I didn't dig too deeply, but is it possible to instead simply use the format that is stored with the text field value? This presumably gets indexed, but perhaps not?

  • πŸ‡ΊπŸ‡ΈUnited States jhedstrom Portland, OR

    Somewhat related here, what's particularly odd about this behavior is that correct formatting is used if a highlighted search term is in play (the associated filter format), but when no highlighting occurs, the default xss filter is used, stripping tags such as <p>...

  • πŸ‡¨πŸ‡¦Canada ryanrobinson_wlu

    Possibly related, the issue I found yesterday was that our results would show the HTML formatting, and would show highlighted search terms, but it would lose the spaces on both sides. So "this is bold text in the middle of a sentence" would become "this isbold textin the middle of a sentence."

    What I discovered is that it did that if the setting on the field in the view for "use entity field rendering" was unchecked, I got this behaviour with losing spaces. If I checked "use entity field rendering", the spaces would be maintained, but I lost the search term highlighting. For now I've opted to maintain spaces at the cost of highlighting, but it would be ideal if we could have both.

  • πŸ‡ΊπŸ‡ΈUnited States jhedstrom Portland, OR

    I figured out why when text fields are highlighted that this isn't an issue. It turns out that xss_admin is being used anyway for highlighted fields. In SearchApiFieldTrait::combineHighlightedValues:

        // Pre-sanitize the highlighted values with a very permissive setting to
        // make sure the highlighting HTML won't be escaped later.
        foreach ($highlighted_values as $i => $value) {
          if (!($value instanceof MarkupInterface)) {
            $highlighted_values[$i] = $this->sanitizeValue($value, 'xss_admin');
          }
        }
    
    
  • πŸ‡©πŸ‡°Denmark ressa Copenhagen

    This would be a great enhancement of Search API and Views integration, thanks to everyone here for working on it. It works well, and here's a re-roll. I guess we're still waiting for tests?

  • πŸ‡ΊπŸ‡ΈUnited States andyg5000 North Carolina, USA

    @ressa, thanks for the re-roll. The patch works for my needs and I agree this is a great feature to have for a fast and interactive search experience.

  • πŸ‡ΊπŸ‡¦Ukraine artemboiko Lviv

    Let's finally add this cool feature to the module. It is really helpfull. Used patches from this issue in a lot of projects :)

    Also, I like descriptions to the options this is very informative.

  • πŸ‡©πŸ‡ͺGermany Knurg

    Works well for me - lets add this! +1!!! :)

  • πŸ‡©πŸ‡ͺGermany Knurg

    This patch really is essential for nearly all my systems and I am really tired to apply it every time. Can we please add it? it works great!

  • πŸ‡§πŸ‡ͺBelgium borisson_ Mechelen, πŸ‡§πŸ‡ͺ

    I guess we already have a test, so we're no longer waiting for that, we should make this into a merge request to see if the test actually passes.

    This patch really is essential for nearly all my systems and I am really tired to apply it every time. Can we please add it? it works great!

    @knurg, this issue is in the "needs work" status, for it to be committed, it should at least get to the "Reviewed and Tested by the Community" status.

    A comment like the ones in #42, #43 and #44 could also put this into rtbc, if you feel safe enough that this will not break any other installations of the module.

    So in this case the next steps are:

    • Make the patch into a merge Request
    • Get a code review on the code and tests
    • Get this into RTBC state
  • Merge request !196Resolve #2874641 "Select text format" β†’ (Open) created by Knurg
  • πŸ‡©πŸ‡ͺGermany Knurg

    I've done my best :)

  • Pipeline finished with Failed
    8 days ago
    Total: 599s
    #364183
  • πŸ‡§πŸ‡ͺBelgium borisson_ Mechelen, πŸ‡§πŸ‡ͺ
  • πŸ‡§πŸ‡ͺBelgium borisson_ Mechelen, πŸ‡§πŸ‡ͺ

    Thanks @knurg!

    Looks like the latest merge request broke all tests, because of a missing ".ignored-deprecations.txt", I don't think this is because of this MR though. I wonder if this is something more general that's going on. I asked in #gitlab on Slack.

  • πŸ‡¦πŸ‡ΉAustria drunken monkey Vienna, Austria

    Pipelines now pass again, thanks!
    I just added return type hints to the new methods.
    If a few people could give this a try and tell us whether it still works for them I can merge it.

Production build 0.71.5 2024