Problem/Motivation
With this module enabled, adding any field to any entity type fails with:
AssertionError: "Number" must be defined in MODULE_NAME.field_type_categories.yml in assert() (line 183 of core/lib/Drupal/Core/Field/FieldTypePluginManager.php)
The field type plugins in this module still declare their category as a translatable string, for example category = @Translation("Number"). Since Drupal 10.2 the category key must be the ID of a category defined in core.field_type_categories.yml or in a MODULE_NAME.field_type_categories.yml file. See the change record New API for defining field type categories.
Note that the assertion only fires when assertions are enabled, so this shows as a fatal error on development environments. With assertions disabled the field types are silently dropped into the General group instead of Number.
Steps to reproduce
- Install a current Drupal 11 site with assertions enabled.
- Enable Field Expression 2.0.3.
- Go to any content type and try to add a field.
- The page fails with the error above. Disabling the module makes it go away.
Proposed resolution
Replace the translatable category strings in every field type plugin with the matching core category ID, for example category = "number" instead of category = @Translation("Number"), and category = "general" where the category is General. The core IDs are defined in core.field_type_categories.yml, so no field_expression.field_type_categories.yml is needed.
The category ID form was introduced in Drupal 10.2, so the module's core_version_requirement should be raised to ^10.2 || ^11. On 10.1 and earlier a plain string category is treated as a literal label and would create a separate group.
Remaining tasks
- Audit all field type plugins in the module and fix each category.
- Raise the core version requirement.
- Review and test on Drupal 11 with assertions enabled.
User interface changes
The Expression field types appear under the Number group on the field selection screen instead of triggering an error or falling back to General.
API changes
None.
Data model changes
None.
Issue fork field_expression-3615612
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
orkutmuratyilmazComment #5
orkutmuratyilmazFixed in the MR. The three numeric types now use
category = "number".Two notes from working through it. The legacy
field_expressiontype declares no category at all and needs no change:FieldTypePluginManager::processDefinition()fills an empty category withFieldTypeCategoryManagerInterface::FALLBACK_CATEGORY, which is the valid IDgeneral, so it never reaches the assertion. It continues to appear under General.core_version_requirementis raised to^10.2 || ^11because the category ID form landed in 10.2. This drops support for Drupal 9, 10.0 and 10.1, all of which are end of life. Worth calling out in the release notes.Verified on Drupal 11 with
zend.assertions = 1: the field selection screen loads without the error, and the Expression (integer), Expression (decimal) and Expression (float) types are listed under Number.