paragraphs_library_browser_filter
Note: this module is created by Github Copilot (with LLM model Claude Opus 4.6 - high thinking).
Filters the paragraphs library browser by allowed paragraph types from the
parent entity reference revisions field.
Problem
When adding a "From library" paragraph to an `entity_reference_revisions` field that restricts allowed paragraph types, the library browser modal shows all available library items regardless of the parent field's configuration. The exposed Type dropdown also lists all paragraph types.
Solution
This module ensures the library browser only shows library items whose paragraph type is allowed by the parent field. It also filters the exposed Type dropdown to match.
How it works
- Widget alter — When the `from_library` paragraph's `field_reusable_paragraph` widget renders, the module reads the allowed paragraph types from the parent `entity_reference_revisions` field and injects them into the entity browser's `widget_context`. This data is stored in the entity browser selection storage (keyed by UUID).
- Query alter — When the `paragraphs_library_browser` view executes, the module reads the allowed types from selection storage (via the `uuid` query parameter) and adds a `WHERE type IN (...)` condition to filter results.
- Exposed form alter — The Type dropdown in the exposed filter form is filtered to only show allowed paragraph types.
The `uuid` query parameter is preserved across Views AJAX requests (exposed filter submit, paging) because Drupal core's `ajax_view.js` forwards iframe query parameters to AJAX endpoints.
Requirements
- Drupal 10 or 11
- [Paragraphs](https://www.drupal.org/project/paragraphs) with the
- `paragraphs_library` submodule enabled
- [Entity Browser](https://www.drupal.org/project/entity_browser)
Installation
- Place the module in your modules directory (e.g. `modules/custom/`).
- Enable it:
drush en paragraphs_library_browser_filter - Clear caches:
drush cr
No additional configuration is required. The filtering activates automatically
for any `entity_reference_revisions` field that has allowed paragraph types
configured and includes the `from_library` type.