Make Tamper plugins tell if they require a tamperable item

Created on 16 August 2025, 10 days ago

Problem/Motivation

For the tamper() method passing a tamperable item as the second parameter is optional. There are however a few Tamper plugins that rely on such an item in order to do their job. Some of these even throw an exception if it is not passed.

The module "ECA Tamper Integration" calls tamper() without a tamperable item. The issue is that in their UI they list all Tamper plugins, even the ones that happen to be incompatible with their implementation.

The plugins that require a tamperable item are:

  • absolute_url
  • copy
  • hash
  • rewrite
  • twig

Note: for the hash plugin the usage of an item may become optional in 🐛 Hash Plugin returns unhashed values Active .

📌 Make Tamper plugins tell which properties they use of a tamperable item Active is closely related, but that one is specifically about which properties of an item is used. This one is about if the item is used at all.

Proposed resolution

Introduce a "itemUsage" property for the plugin definition of a Tamper plugin, with the following possible values:

  • required: for plugins that cannot function without an item (and may throw a \Drupal\tamper\MissingItemException because of it)
  • optional: for plugins that use an item, but can still do something meaningful when it is not passed.
  • ignored: for plugins that do not use the item at all.
  • null/omitted: for plugins that haven't specified their item usage yet (Tamper plugins that exist in other modules).

Other modules can check the plugin's definition to see whether or not a tamperable item is required. To make it easier on instantiated plugins, add some methods for it:

  • requiresItem(): to check if tamper() needs a tamperable item.
  • usesItem(): to check if tamper() makes use of a tamperable item.
  • ignoresItem(): to check if tamper() completely ignores a tamperable item.

These methods are added to a new interface called \Drupal\tamper\ItemUsageInterface and implemented in a trait called \Drupal\tamper\ItemUsageTrait. This way Tamper plugins that do not extend \Drupal\tamper\TamperBase can still make use of this functionality.

Remaining tasks

  • Review
  • Merge

User interface changes

None.

API changes

All Tamper plugins that implement \Drupal\tamper\ItemUsageInterface get a few new methods.

Data model changes

Tamper plugins get a new property called "itemUsage".

📌 Task
Status

Active

Version

1.0

Component

Code

Created by

🇳🇱Netherlands megachriz

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

Merge Requests

Comments & Activities

Production build 0.71.5 2024