Hi there,
I just wanted to report, that this module breaks Drupal with this error:
Cannot access offset of type Drupal\\Core\\StringTranslation\\TranslatableMarkup
Drupal Version: 11.3.6
Steps to reproduce:
- Install the module
- In any content type trying to add a new field results in this error
The same issue has been reported numerous times in other modules, e.g.: https://www.drupal.org/project/butils/issues/3486979
I don't really need this module, just wanted to briefly test it. But anyway, you might want to look into this.
Comments
Comment #2
kamiviolet commentedIt looks like to me distantly related to this issue:
https://www.drupal.org/project/drupal/issues/3495587
In general, although annotation-based plugins are backward compatible, it seems translation only works with attributes-based and it is buggy with annotations-based for the current Drupal version.
Using annotations work ONLY if taking down all @Translation() out of the definitions.
Proposed solution
Use attributes to register a plugin
Instead of using annotations
Attributes-based plugin:
https://www.drupal.org/docs/drupal-apis/plugin-api/attribute-based-plugins
Annotations-based plugin:
https://www.drupal.org/docs/drupal-apis/plugin-api/annotations-based-plugins
Comment #3
sujan shrestha commentedFixed in 1.4.x and released in 1.4.0:
https://git.drupalcode.org/project/simple_time_field/-/commit/6cc259ff24...
https://www.drupal.org/project/simple_time_field/releases/1.4.0
I could reproduce this on 1.3.0 with Drupal 11.4: the "Add field" page failed with exactly this error. The cause was the field type's category, which was a translated label (@Translation("General")) instead of the category ID, so Drupal used a TranslatableMarkup object as an array key. See also #3576503.
As @kamiviolet suggested, all plugins now use PHP attributes instead of annotations, and the category is 'general'. A functional test now opens the "Add field" page, so this is covered from now on.
Thanks @marcushenningsen for the report and @kamiviolet for the investigation.