Filter the list of entities referenced by "Entity reference revisions" field I have a content type &quot;Slider&quot; which uses an Entity reference revisions field named &quot;Slides&quot; to save reference to various paragraphs that are then displayed on the frontend as a hero slider.
Everything works fine but now we have received a request of filtering out the slides by a show/hide boolean flag in the slide paragraph. Adding a boolean field to each such paragraph is straightforward but how do I filter those paragraphs based on it? I'm assuming a Drupal hook that allows a function to filter out the referenced entities by some arbitrary criterion but I've been unable to find it.
I understand that this question relates to a 3rd party module but it is quite possible that a core Drupal hook could be used in this context.
Any help will be greatly appreciated.
Thanks.
I'd recommend doing this by creating a new Field Formatter by extending the default EntityReferenceRevisionsEntityFormatter (or extending whichever formatter you're using to display the paragraphs). If you're not sure how to create a field formatter, review the Create a custom field formatter documentation on d.o.
Specifically, you'll need to override the getEntitiesToView() method, something like this:
protected function getEntitiesToView(EntityReferenceFieldItemListInterface $items, $langcode) {
  $entities = parent::getEntitiesToView($items, $langcode);
  $allowed_entities = [];

  foreach($entities as $entity) {
    // Check if your show/hide checkbox is checked.
    // Note: I can't remember if this check is sufficient by itself.
    if (!$entity-&gt;my_show_hide_field-&gt;isEmpty()) {
      $allowed_entities[] = $entity;
    }
  }

  return $allowed_entities;
}

Lastly, you'll need to configure your entity reference revisions field to use this new formatter.