Problem/Motivation
This is easily reproducible on simplytest.me:
1. Install Drupal w/ standard profile
2. Add an article node with garbage info
3. Create a view with base table of Content Revisions, displaying fields.
4. Add field "Tags" under category "Content (historical data)"
5. In settings for that field, rewrite the field using "Override the output of this field with custom text" (actually doesn't matter what you pick, you just need something that exposes the replacement tokens)
6. Observe that the replacement token for that field contains a hyphen: "{{ field_tags-revision_id__target_id }}"
Before
![Suggested token names contain a hypen]()
![Field is rendered as 0]()
The problem is that you cannot have hyphens in twig variables like that. I believe it should be two underscores instead based on what I've seen in some other issues.
Proposed resolution
- Use the field alias instead, but don't break things that use field name in the view.
- Views post-update.
- Write a test to assert the problem.
After
![Suggested token names contain no hyphen]()
![Field is rendered as normal tag]()
Remaining tasks
- Add upgrade path test to assert that view config created before the patch is properly updated after the patch per @alexpott's review. @InterX mentions a good start to this in comment #35.
- Change the post-update so that it uses Batch API for scalability per @alexpott's review.
Completed
- Patch #25 with views post-update, fix and test to assert the issue.
- Manual testing (DONE): Add Before/After screenshots.
Original report by bkosborne
This causes a couple issues:
1. There's an assertion in PluginBase::viewsTokenReplace() that checks if tokens are valid twig variables. So if the token replacement is performed for whatever reason, this assertion will fail and cause a 500 error.
2. I believe this would also prevent twig from performing the replacement correctly and/or using the proper field template for the field, but I can't be sure because I didn't test that behavior. The replacement token replaces the string 0 or 1, but not the actual value for the field.
I did a little big of digging and see that the token name for a given field is literally the "id" of the field, see FieldPluginBase::getFieldTokenPlaceholder(). Not sure on the solution here since I'm completely unfamiliar with this code.