Control the visibility of your content with Entity Visibility Preview

  • 151
  • 0
  • 10 Aug 2020



Have you ever needed to display contents or parts of a content differently depending on the user’s segmentation?


Have you ever needed to schedule contents or parts of a content for publication/depublication?


Have you ever needed to preview what your website will look like depending on those visibility conditions?


Being able to address the right piece of information to the right person:

  • reduce the effort to access to the information,
  • increase engagement.


Allowing marketers and content contributors to preview exactly how the website will behave depending on personalization helps greatly those teams to be more effective.


We encountered this problem on a customer project which started in the last trimester of 2017. So keep in mind, this is the state of art from this period and that the website was built around the Paragraphs module.


We are now going to see the requirements we had.


Two main axes of changing content


Scheduled content publication/depublication

In the case of our customer, it was very important to be able to schedule content publication/depublication because of advertisement contracts on certains parts of certain pages.



  • be able to schedule when content will be available or not:
    • visitors should not have access to irrelevant content,
    • contributors can prepare content and schedule publication.


The existing solutions we evaluated were:

  • Scheduler:
    • only for nodes,
    • at this time (end of 2017) no integration with Content Moderation,
    • no preview.
  • Schedules Updates:
    • scheduling is not handled per entity (no element on the entity’s form),
    • no preview.


Both solutions were not satisfying for our needs.


Content segmentation


Show different content depending on the user's segmentation.



  • the website is autonomous: no external services dedicated to that,
  • must work for authenticated users.


The existing solutions we evaluated were:


Both solutions were not satisfying for our needs.


Website preview


Our customer was migrating from a proprietary Java’s CMS from Oracle to Drupal 8. In this CMS, there was the feature to preview exactly how the website will look like at a precise moment in time.


This is the kind of (very advanced) feature, Drupal is lacking currently. But we must recognize that humongous efforts had been made during the last years with Content Moderation in core, Workspaces, etc. So Drupal core is closing the gap with proprietary CMS proposing such advanced features.


Fortunately in the last Drupal product survey, there were options to tell if you want such features in Drupal core.


The existing solution we evaluated was:

  • Workspace:
    • not stable enough at the time,
    • not fined grained,
    • too hard to use for the client,
    • not a preview tool,
    • no temporal dimension.


This solution was not satisfying our needs.


So for our customer’s project we implemented a custom solution.


The Entity Visibility Preview module


Based on this experience, at the end of 2019, we developed a Drupal 8 module called Entity Visibility Preview to have a generic and reusable implementation.


Its goal is to allow site owners to add visibility conditions (date interval, segmentation, other) on content entities to be able to display different contents to visitors depending on their segmentation, the current date or other conditions.


It also allows previewing the website in the combination of conditions you want, to test what you expect your visitors will see.




To provide a generic solution, the module provides:

  • a new field type:
    • inspired from Metatag for the storage and field widget.
  • a new plugin type to:
    • handle access control logic,
    • provide and handle form element on the field widget,
    • provide and handle form element on the preview form and a preview message.
  • a preview form:
    • allow to preview the website depending on conditions,
    • preview values are stored in session.


Website preview form

Provided conditions

Currently the module provides two visibility conditions:

  • Date range
    • start date only: content will be visible from this date,
    • end date only: content will not be visible from this date,
    • start and end dates: content will be visible in this interval only.
  • Taxonomy (segmentation)
    • choose one or several taxonomy terms (OR between terms),
    • configure:
      • which vocabularies to reference terms from,
      • which taxonomy reference fields on the user entity to compare with,
      • set values for the anonymous users on a dedicated form.


Each plugin can be enabled and configured per field instance for flexibility.


Test content




The primary use case of the Entity Visibility Preview module is for authenticated users. There is no distinction between anonymous users.


The implementation of Entity Visibility Preview lies on the hook_entity_access hook which in the case of nodes is only triggered when viewing the node’s page. So a node with visibility conditions will still be accessible if it is in a View’s results for example.


The Node Grant API is not supported in a generic way, so there is no access control in:

  • Views,
  • entity queries,
  • Search API views,
  • ...


Fortunately, we managed to create a sub-module, Entity Visibility Preview Simple Grants, to provide Node Grant API support for the two provided plugins (date range and taxonomy). So if you have to create custom condition plugins, you can take a look at this sub-module how it was done.




With the Entity Visibility Preview module you can change parts of your page, based on paragraphs for example, depending on date and segmentation and other conditions depending on your needs and be able to preview the combinations. All of that with great flexibility in terms of configuration.


You can also see an article with a demonstration video on


At the same time we published the first versions of the module, we had a customer project already requiring it!


We will be very proud if our module could serve as an experiment or example of what people want to be available in Drupal core directly in the future.

Open source training

Durée : 2 jours
Lieu : Paris