0

So, I am building a faceted search view on my product display, but I cannot add the field for the Flag link. I can get fields that reference the User's who used a flag, but no relationship that I can add, allows me to access my flag link as a field.

There are references to this problem Add Flag link to Search Index and Flag Module Integration, but no obvious solution. Thoughts? Recipies?

2 Answers 2

0

This doesn't work out of the box, but there's a patch for this https://www.drupal.org/node/1362298

0

Here's the answer for Drupal 8/9

This is how I accomplished this task. I'm making the assumption the flag has already been created and that it has "Display link as field" checked in it's configuration. Also this howto is tailored to nodes, but it can be used on any other entity type as well with a few adjustments to urls and pathways to where the display modes are edited:

  1. To make the Title field configurable on nodes, in a custom module add the following hook as defined over at https://drupal.stackexchange.com/a/178476/5638. This only applies if the content you are working on are nodes. Custom entities can usually skip this step.
function mymodule_entity_base_field_info_alter(&$fields, $entity_type) {
  if ($entity_type->id() == 'node') {
    if (isset($fields['title'])) {
      $fields['title']->setDisplayConfigurable('view', TRUE);
    }
  }
}
  1. Navigate to Structure -> Display Modes (/admin/structure/display-modes)
  2. Click on "View Modes" (/admin/structure/display-modes/view)
  3. Scroll down and click on Add new Content view mode (/admin/structure/display-modes/view/add/node)
  4. Type in the name "Favorite Field" and click Save
  5. Navigate back to Structure -> Content Types (/admin/structure/types)
  6. Click Manage display next to a content type you want to show the favorite field for in your view.
  7. Click on Custom Display Settings to expand it
  8. Select "Favorite Field"
  9. Click Save
  10. Select the "Favorite Field" tab from the top
  11. Remove all fields except your favorite field
  12. click Save.
  13. Repeat steps 6-13 for each content type you wish to display in your search API View.
  14. Navigate to Structure -> Views
  15. Click Edit next to your view
  16. In the fields section of your view click "Add"
  17. Make sure to Check the "For" drop down incase you want it only for this display
  18. In the search, type "rendered"
  19. Choose "Rendered Item"
  20. Click Apply
  21. Choose your options as you wish to format this field
  22. Make sure you choose "Favorite Flag" from Display Mode.
  23. Click Apply

At this point, if your content is indexed, you should see in the preview, the "I Like" link show up and should be have as configured. Here is a quick screenshot of a test view I did Node with Favorite flag

And another instance in the wild with a custom entity using the OpenKJ module and the table display plugin instead of unformatted list. Flag's Javascript links work and everything. enter image description here

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.