Overview
This patch adds a new filter to Flag Search API that allows filtering Search API views based on whether entities have been flagged by the current user.
What This Patch Does
Adds a new Views filter that enables users to display:
- Only flagged entities
- Only non-flagged entities
- All entities (no filter)
Key Features
- Dynamic Flag Selection: The filter provides a dropdown to select which flag to check against
- User-Specific Filtering: Filters based on the current user's flagging actions
- Search API Compatible: Works seamlessly with Search API indexes
Technical Implementation
1. Views Data Alter Hook
Iterates through each datasource in the Search API index
Loads flags configured for each entity type
Registers a new entity_flagged filter in Views data for each Search API index
2. Filter Plugin (EntityFlagged.php)
Queries the flagging table to get entity IDs flagged by the current user
Applies IN or NOT IN conditions to the Search API query based on filter selection
Handles empty result sets appropriately
Automatically detects the entity type from the Search API index datasource
Dynamically determines the entity ID field (e.g., nid for nodes, uid for users)
Requires an ID field to be present in the Search API index
Use Cases
- User Dashboard: Display content a user has bookmarked/favorited
- Content Recommendations: Show only content the user hasn't flagged yet
- Volunteer Management: Filter assignments based on user enrollment status
- Personalized Views: Create user-specific filtered lists
Requirements
The Search API index must include an ID field (the entity's primary key)
Flags must be configured for the entity type being indexed
For Flag 8.x-4.0-beta6 i made a second patch
User Experience
Administrators configuring a view will see:
A new "Entity Flagged" filter option
Radio buttons to choose: All / Flagged / Not flagged
A dropdown to select which flag to filter by
Limitations & Future Improvements
Currently supports indexes with a single entity type datasource
Multi-entity type indexes are noted as a TODO for future development
| Comment | File | Size | Author |
|---|---|---|---|
| add-entity-flagged-filter-for-search-api.patch | 4.86 KB | johaziel |
Comments