Views creates invalid revision id twig token variable

Created on 18 July 2018, over 6 years ago
Updated 23 August 2023, over 1 year ago

I created a View of content revisions. We added a field to the view (a taxonomy reference in this case) and selected the "historical data" value (to show the revision value vs the current node value). We also added an Edit link for the node.

When displaying the view we get the following warning:

Warning: assert(): Tokens need to be valid Twig variables. failed in Drupal\views\Plugin\views\PluginBase->viewsTokenReplace() (line 371 of core/modules/views/src/Plugin/views/PluginBase.php).

When debugging this, we discovered the token it is complaining about is "field_category-revision_id". This is not a valid Twig variable because of the "-". In [#2548291] core changed usage of "-" to "__". However, Views still uses a "-" when adding "revision_id" to a field.

Tracked this down to core/modules/views/views.views.inc in views_field_default_views_data() (using 8.5.x core here):

    if ($type == EntityStorageInterface::FIELD_LOAD_CURRENT) {
      $group = $group_name;
      $field_alias = $field_name;
    }
    else {
      $group = t('@group (historical data)', ['@group' => $group_name]);
      $field_alias = $field_name . '-revision_id';
    }

This needs to be changed to "__revision_id" but not sure what else in core or contrib relies on this.

πŸ› Bug report
Status

Closed: duplicate

Version

10.0 ✨

Component
ViewsΒ  β†’

Last updated about 6 hours ago

Created by

πŸ‡ΊπŸ‡ΈUnited States mpotter

Live updates comments and jobs are added and updated live.
  • Needs tests

    The change is currently missing an automated test that fails when run with the original code, and succeeds when the bug has been fixed.

Sign in to follow issues

Comments & Activities

Not all content is available!

It's likely this issue predates Contrib.social: some issue and comment data are missing.

Production build 0.71.5 2024