Control the visibility of your content with Entity Visibility Preview

  • 110
  • 10
  • 10 Aug 2020

Context

 

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.

 

Constraints:

  • 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.

 

Constraints:

  • 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 https://dri.es/drupal-2020-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.

 

Architecture

 

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

 

Limitations

 

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.

 

Conclusion

 

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 https://innovation.smile.eu/videos/2020-02-03-drupal-entity-visibility-preview.html.

 

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.
 

Comments on "Control the visibility of your content with Entity Visibility Preview"

Thank you for recommending, that is one of the great things! I have gained a lot of knowledge after reading your article, please keep updating the good information to everyone. https://minecraft-classic.com

DEQIqVKbUoyNlfpm

BAlxfdivrhTVg

gHAvJdTfOzWDXFZw

QeDHiGWYlkSTagLb

ioVeGPOILTQ

vlJMLKBIZntTVFXS

hollywood casino free slots slots free spins no registration <a href=" http://onlinecasinogameslots.com/# ">play slots online for money </a> free slot games [url=http://onlinecasinogameslots.com/# ]penny slots [/url]

fygVdQAKH

TYaKjsXPBxdLcrZ

Leave a comment

* Required fields

Comments are subject to validation.

The collection of the requested information is necessary for the processing of your application by SMILE, controller. This collected information may be used for prospecting purposes. You have a right to access, rectify, oppose and delete data concerning you. To exercise them, simply contact us by email at the following address marketing@smile.fr or by post to the attention of SMILE - 20 rue des Jardins 92600 Asnieres sur Seine. We invite you to read our data protection policy.

Open source training

Durée : 2 jours
Lieu : Paris