Problem/Motivation
If you add a custom field to an entity type supported by views and the field starts with a number then \Drupal\views\Plugin\views\PluginBase::viewsTokenReplace() will fail it's assertions if you rewrite the output of a field. This because the field starts with a number and fails this regex:
assert(preg_match('/^[a-zA-Z_\x7f-\xff][a-zA-Z0-9_\x7f-\xff]*$/', $token) === 1, 'Tokens need to be valid Twig variables.');
Steps to reproduce
Note this can only occur on base fields as configurable fields will error - see \Drupal\field\Entity\FieldStorageConfig::__construct()
See test added by MR.
Proposed resolution
Either fix views... or deprecate base fields with such names... but renaming base fields for existing sites is not that easy.
Current solution fixes views.
Remaining tasks
User interface changes
None
Introduced terminology
N/a
API changes
None
Data model changes
None
Release notes snippet
N/a
Issue fork drupal-3548695
Show commands
Start within a Git clone of the project using the version control instructions.
Or, if you do not have SSH keys set up on git.drupalcode.org:
Comments
Comment #2
alexpottIn
\Drupal\field\Entity\FieldStorageConfig::__construct()we do:I wonder if we should implement something similar in \Drupal\Core\Field\BaseFieldDefinition::setName() - or consider deprecating support for such field names - so we can remove the foot gun.
Comment #4
alexpottComment #5
alexpottComment #6
smustgrave commentedAppears to have some test failures