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: Views tokens need to be valid Twig variables; subtoken separator now double underscore instead of dash 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.
| Comment | File | Size | Author |
|---|---|---|---|
| #13 | views-field-revision-twig-tokens-2986675-d10.patch | 552 bytes | jessey |
| #12 | image-2018-12-27-11-40-34-458.png | 16.36 KB | Sheenam khunger |
| #12 | views-field-revision-twig-tokens-2986675-12-D8.patch | 529 bytes | Sheenam khunger |
| #6 | views-field-revision-twig-tokens-2986675-6.patch | 548 bytes | johnpitcairn |
Comments
Comment #2
OnkelTem commentedConfirmed. Drupal 8.5.
Comment #3
johnpitcairn commented+1 from me. Getting this in 8.6.x whenever there is a Profile revision relationship in a commerce view. Views will check all available tokens, used or not.
As far as backward compatibility goes, I don't know that the resulting twig variable is usable anyway, is it? Let's at least see if a patch passes tests...
Comment #4
johnpitcairn commentedComment #5
johnpitcairn commentedRelevant change notice
Comment #6
johnpitcairn commentedLet's see what happens...
Comment #7
mpotter commentedThanks for the patch! Tests are passing.
Comment #8
mpotter commentedThe only problem this potentially causes is sites that already have field_name-revision_id exported in a View config will have a Broken Field after this patch and will need to update their view config and re-import. Not sure there is anything that can be done about that, but since the existing config causes the assert warning it's really already a broken field.
Comment #9
alexpottWe also must have missing test coverage of this functionality so we should add some to prove it works and that we don't break it in the future.
@mpotter the upgrade path is interesting. Given that it is already broken I would be inclined to not fix them BUT this gets us into an interesting situation where just saving a view will magically fix it which is also unexpected. How broken is HEAD - do you get the warning but does it still work? If that's the case we should have an upgrade path.
Comment #10
interx commentedThis is addressed in https://www.drupal.org/project/drupal/issues/2831233 with a test and an upgrade path.
Comment #11
alexpottThis is a duplicate of #2831233: Field tokens for "historical data" fields (revisions) contain a hyphen, breaking twig templates and throwing an assertion error
Comment #12
Sheenam khunger commentedhttps://www.drupal.org/project/drupal/issues/2986675#comment-12753486 This patch is working fine with 8.5 .

After upgrading from 8.5.6 to 8.6.2 , this patch do not work as line number changed in the core . It broke the fields in views as its changed the field to field-name-revision_id.
views-field-revision-twig-tokens-2986675-12-D8.patch , changes done here according to the Drupal 8.6 .
Comment #13
jessey commented