Drupal

Ask your agent to find the Drupal template or module that renders your button, link, or menu. It can mark that control for a goal, or compare its wording, while keeping the content editable and its action unchanged.

Mark a native control

If reaching a destination is the result you care about, reuse a page goal. To count an action such as opening delivery details, create a named interaction with the exact event name show-details. Keep your existing Version Compare script. The goal name goes on the actual control in data-vc-goal.

In an owned Twig template or a scoped theme override, add data-vc-goal="show-details" to the existing <button> or <a>. If that tag already prints its own Drupal attribute object, use its setAttribute('data-vc-goal', 'show-details') method. Keep the classes and other attributes. A block's wrapper attributes do not mark a button inside the block.

For example, in a menu template such as menu--main.html.twig, item.attributes belongs to the <li>. For the intended item only, pass the goal attribute to link() instead. Match the menu item by stable identity, not its visible title. Keep its existing title and URL:

{{ link(item.title, item.url, {'data-vc-goal': 'show-details'}) }}

Use the event that describes the action. If the menu link leads to a page and arrival is the goal, use the page goal instead.

Mark a control Drupal inserts later

If a module renders the control and you cannot set its attributes at the source, mark it in place. For example, add attributes.addClass('vc-delivery-block') where your dedicated block template prints the existing wrapper attributes. Confirm that the real toggle is button.delivery-details-toggle inside that wrapper. For a generated menu toggle, use the same approach with a hook on just that menu and the toggle selector from your theme.

For a theme called my_theme, add this entry to my_theme.libraries.yml. Attach it in the block template with {{ attach_library('my_theme/vc-delivery') }}. See Drupal theme libraries.

vc-delivery:
  js:
    js/vc-delivery.js: {}
  dependencies:
    - core/drupal

In the theme's js/vc-delivery.js, use Drupal behaviours to check the initial document and content inserted by Drupal AJAX or BigPipe:

(function (Drupal) {
  const selector = '.vc-delivery-block button.delivery-details-toggle:not([data-vc-goal])';
  const mark = (button) => { button.dataset.vcGoal = 'show-details'; };

  Drupal.behaviors.vcDelivery = {
    attach(context) {
      if (context.matches?.(selector)) mark(context);
      context.querySelectorAll(selector).forEach(mark);
    },
  };
})(Drupal);

The behaviour checks the context itself and its descendants. It skips marked controls, so this attribute change needs no once() call or click listener. If you use a behaviour to build version spans, use core/once on the label element to avoid adding them twice.

Compare the wording

Keep the fallback in the current node or block field, or in the menu link title. Store the alternative in a separate plain-text field. In the template that renders the label, use the wording recipe inside the same heading or control. For a Twig link() call, capture the version spans in a {% set %} block and pass that markup as the link text. Put data-vc in the link's attributes. Keep the existing Drupal Url object and options. Print the text with normal Twig escaping, never |raw. Leave icons and other controls outside the version spans.

Render wording visible on load in the initial HTML. Keep field editing with the usual editor role. Have the theme maintainer add the markup and assets rather than widening access to text formats such as Full HTML.

Preview and publish

  1. Use the content form's Preview if enabled. In a recognised node preview, try both labels in Show versions. Activate the marked control with mouse and keyboard. Inspect the real control for data-vc-goal="show-details" and look for Version Compare preview: not recorded in the console.
  2. Use test mode with data-vc-test on the hosted script for ordinary pages. After the owner approves publishing, rebuild Drupal caches for the template or library changes. Check the public page while signed out, including the control after an AJAX refresh or BigPipe insertion if it uses one. Check that focus and the original action still work. Leave test mode on every page until the owner separately approves removing the attribute. Reload after removal.