Smart date value custom format tokens empty

Created on 24 March 2024, 9 months ago
Updated 4 May 2024, 8 months ago

Problem/Motivation

On a Drupal 9 site with smart_date 3.6 and tokens 8.x-1.13 and the auto_entitylabel module enabled, some tokens end up empty.

This is because the Token module passes last.

Remplacement from Smart Date work correctly, but it then get equal to NULL because of the hook_tokens() from Tokens.

Steps to reproduce

  • Create node type
  • Add a smart date field (e.g. field_smartdates)
  • Enable automatic label generation for this bundle with this pattern:
    Astreinte [node:field_smartdates:0:format:compact]
  • Save a node: the token is removed/empty

Proposed resolution

Add a hook_module_implements_alter() to ensure Smart Date tokens are called last.

/**
 * Implements hook_module_implements_alter().
 *
 * Move smart_date hook_tokens() implementation to the end of the list.
 */
function smart_date_module_implements_alter(&$implementations, $hook) {
  switch ($hook) {
    case 'tokens':
      $group = $implementations['smart_date'];
      unset($implementations['smart_date']);
      $implementations['smart_date'] = $group;
      break;
  }
}

Remaining tasks

Review MR and merge if possible.

πŸ› Bug report
Status

Fixed

Version

3.6

Component

Code

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