I followed this tutorial (https://ws.agency/blog/indexing-flags-drupal-8-flag-search-api), but rather than use the flag as a contextual filter, I wanted the flag available as a field, so that users can look through the view and flag content that interests them.

Is there currently a way to do this with the module? It doesn't seem like it--I've tried many configurations and nothing has worked.

Comments

andileco created an issue. See original summary.

johnny5th’s picture

I noticed this issue as well. For some reason there's not any output on the field, but filters work on it. I'd imagine, even if it did work the way it's set up, it would just output user IDs. We probably need to make a special formatter to show the flag link.

johnny5th’s picture

StatusFileSize
new2.09 KB

I took a stab at fixing this. TBH I'm not 100% sure why it works, but I just followed the documentation for creating a custom processor.
Switched from preprocessIndexItems to addFieldValues to inject the flag values into the index. Can anyone confirm that this is a proper way of fixing the issue?

johnny5th’s picture

StatusFileSize
new4.37 KB

To build on the last patch, I also added a rudimentary view field handler to expose a flagging link.
I spent a few days trying to figure out how to avoid making extra DB calls, but I came up short. This just overrides the field output with a flag lazy builder. Ideally, I'd like to figure out how to create a relationship on the view to get better performance.

xsdx’s picture

Reviewed and tested.

xsdx’s picture

Status: Active » Reviewed & tested by the community

  • johnny5th authored 34b1a13 on 8.x-1.x
    Issue #2908924 by johnny5th, xSDx, andileco: Flag field blank when added...
xsdx’s picture

Status: Reviewed & tested by the community » Fixed
xsdx’s picture

Status: Fixed » Closed (fixed)