Use Drupal Condition Plugin for visibility options

Created on 18 July 2024, 4 months ago

Problem/Motivation

The current version of the module implements its own visibility options, see https://git.drupalcode.org/project/vwo/-/blob/8.x-1.x/src/Form/Visibilit...
The conditions are checked on vwo.module https://git.drupalcode.org/project/vwo/-/blob/8.x-1.x/vwo.module?ref_typ...
The cache contexts are being set manually.

Problems

  1. Some of the cache contexts are only being set when certain conditions are satisfied
  2. By implementing code that is already part of Drupal core means more code to maintain
  3. It is harder to extend the module to use the same visualisation settings, because it requires duplication of code

Proposed resolution

We should reuse the conditions provided by Drupal out of the box:

Examples of implementation can be found in the Block module

Another example on Google tag module

Example of custom Condition plugin https://git.drupalcode.org/project/google_tag/-/blob/2.0.x/src/Plugin/Co...

Remaining tasks

  1. Replace custom conditions with Drupal core condition plugins
  2. Update the admin form to use the condition plugins
  3. Update the module to use the condition plugins to evaluate if the condition is met or not
  4. Remove code that manually sets cache contexts, as these will be provided by the condition plugins
  5. Migrate configs, if necessary

Make sure the code is compatible with Drupal 11

📌 Task
Status

Active

Version

1.0

Component

Code

Created by

🇬🇧United Kingdom marcelovani London

Live updates comments and jobs are added and updated live.
Sign in to follow issues

Comments & Activities

Production build 0.71.5 2024