TypeError: Drupal\Core\Field\FieldTypeCategory::getDescription(): Return value must be of type Drupal\Core\StringTranslation\TranslatableMarkup, string returned

Created on 18 December 2023, 11 months ago
Updated 14 January 2024, 10 months ago

Description

A TypeError is thrown when attempting to add a new field to any content type, product type, order type, or order item type after updating to Drupal 10.2.0 if Commerce Tax is enabled.

Drupal\Core\Field\FieldTypeCategoryInterface was introduced in Drupal 10.2.0 and getDescription() method is required to return TranslatableMarkup

To fix this issue, the Drupal\commerce_tax\Plugin\Field\FieldType\TaxNumberItem FieldType annotation should be updated to include a description:

/**
 * Plugin implementation of the 'commerce_tax_number' field type.
 *
 * @FieldType(
 *   id = "commerce_tax_number",
 *   label = @Translation("Tax number"),
 *   description = @Translation("Stores a tax number"),
 *   category = @Translation("Commerce"),
 *   default_formatter = "commerce_tax_number_default",
 *   default_widget = "commerce_tax_number_default",
 *   cardinality = 1,
 * )
 */
class TaxNumberItem extends FieldItemBase implements TaxNumberItemInterface {

Backtrace

TypeError: Drupal\Core\Field\FieldTypeCategory::getDescription(): Return value must be of type Drupal\Core\StringTranslation\TranslatableMarkup, string returned in Drupal\Core\Field\FieldTypeCategory->getDescription() (line 26 of core/lib/Drupal/Core/Field/FieldTypeCategory.php).

Drupal\field_ui\Form\FieldStorageAddForm->buildForm(Array, Object, 'commerce_order', 'default')
call_user_func_array(Array, Array) (Line: 536)
Drupal\Core\Form\FormBuilder->retrieveForm('field_ui_field_storage_add_form', Object) (Line: 283)
Drupal\Core\Form\FormBuilder->buildForm(Object, Object) (Line: 73)
Drupal\Core\Controller\FormController->getContentResult(Object, Object)
call_user_func_array(Array, Array) (Line: 123)
Drupal\Core\EventSubscriber\EarlyRenderingControllerWrapperSubscriber->Drupal\Core\EventSubscriber\{closure}() (Line: 627)
Drupal\Core\Render\Renderer->executeInRenderContext(Object, Object) (Line: 121)
Drupal\Core\EventSubscriber\EarlyRenderingControllerWrapperSubscriber->wrapControllerExecutionInRenderContext(Array, Array) (Line: 97)
Drupal\Core\EventSubscriber\EarlyRenderingControllerWrapperSubscriber->Drupal\Core\EventSubscriber\{closure}() (Line: 181)
Symfony\Component\HttpKernel\HttpKernel->handleRaw(Object, 1) (Line: 76)
Symfony\Component\HttpKernel\HttpKernel->handle(Object, 1, 1) (Line: 58)
Drupal\Core\StackMiddleware\Session->handle(Object, 1, 1) (Line: 48)
Drupal\Core\StackMiddleware\KernelPreHandle->handle(Object, 1, 1) (Line: 106)
Drupal\page_cache\StackMiddleware\PageCache->pass(Object, 1, 1) (Line: 85)
Drupal\page_cache\StackMiddleware\PageCache->handle(Object, 1, 1) (Line: 48)
Drupal\Core\StackMiddleware\ReverseProxyMiddleware->handle(Object, 1, 1) (Line: 51)
Drupal\Core\StackMiddleware\NegotiationMiddleware->handle(Object, 1, 1) (Line: 36)
Drupal\Core\StackMiddleware\AjaxPageState->handle(Object, 1, 1) (Line: 51)
Drupal\Core\StackMiddleware\StackedHttpKernel->handle(Object, 1, 1) (Line: 704)
Drupal\Core\DrupalKernel->handle(Object) (Line: 19)

Steps to Reproduce

  1. Install Drupal 10.2.0.
  2. Install Commerce and enable the Commerce Tax module.
  3. Attempt to add a new field to any content type, product type, order type, or order item type.
🐛 Bug report
Status

Fixed

Version

2.36

Component

Tax

Created by

Live updates comments and jobs are added and updated live.
Sign in to follow issues

Comments & Activities

Not all content is available!

It's likely this issue predates Contrib.social: some issue and comment data are missing.

  • Status changed to Fixed 11 months ago
  • 🇮🇱Israel jsacksick

    Committed thanks!

  • Status changed to Active 11 months ago
  • 🇹🇭Thailand Nick Hope

    I'm seeing a nearly-identical error on my local development site in Drupal 10.2.0 / Commerce 8.x-2.36 / Commerce File 8.x-2.1 / PHP 8.3.0 if I click "+ Create a new field" at either...

    /admin/commerce/config/product-types/default/edit/fields
    or
    /admin/commerce/config/product-variation-types/default/edit/fields

    I'm using Commerce License and Commerce File because I want to sell downloads.

    I guess another field type is missing a description, but I'm not sure how to determine which one. I searched \modules\contrib for *item.php and I can't find any missing a description.

    There is a fix 🐛 Error TypeError: Drupal\Core\Field\FieldTypeCategory::getDescription() if a FieldType has 'description' missing in its annotation RTBC in Drupal Core 10.2.x-dev that works around the problem.

    Happy for this to be re-tagged as "Fixed" to open a new issue if preferred.

    The full error message is below. Everything is the same as the error in the OP except Drupal\field_ui\Form\FieldStorageAddForm->buildForm() is empty.

    TypeError: Drupal\Core\Field\FieldTypeCategory::getDescription(): Return value must be of type Drupal\Core\StringTranslation\TranslatableMarkup, string returned in Drupal\Core\Field\FieldTypeCategory->getDescription() (line 26 of core/lib/Drupal/Core/Field/FieldTypeCategory.php).

    Drupal\field_ui\Form\FieldStorageAddForm->buildForm()
    call_user_func_array() (Line: 536)
    Drupal\Core\Form\FormBuilder->retrieveForm() (Line: 283)
    Drupal\Core\Form\FormBuilder->buildForm() (Line: 73)
    Drupal\Core\Controller\FormController->getContentResult()
    call_user_func_array() (Line: 123)
    Drupal\Core\EventSubscriber\EarlyRenderingControllerWrapperSubscriber->Drupal\Core\EventSubscriber\{closure}() (Line: 627)
    Drupal\Core\Render\Renderer->executeInRenderContext() (Line: 121)
    Drupal\Core\EventSubscriber\EarlyRenderingControllerWrapperSubscriber->wrapControllerExecutionInRenderContext() (Line: 97)
    Drupal\Core\EventSubscriber\EarlyRenderingControllerWrapperSubscriber->Drupal\Core\EventSubscriber\{closure}() (Line: 181)
    Symfony\Component\HttpKernel\HttpKernel->handleRaw() (Line: 76)
    Symfony\Component\HttpKernel\HttpKernel->handle() (Line: 58)
    Drupal\Core\StackMiddleware\Session->handle() (Line: 48)
    Drupal\Core\StackMiddleware\KernelPreHandle->handle() (Line: 106)
    Drupal\page_cache\StackMiddleware\PageCache->pass() (Line: 85)
    Drupal\page_cache\StackMiddleware\PageCache->handle() (Line: 48)
    Drupal\Core\StackMiddleware\ReverseProxyMiddleware->handle() (Line: 51)
    Drupal\Core\StackMiddleware\NegotiationMiddleware->handle() (Line: 36)
    Drupal\Core\StackMiddleware\AjaxPageState->handle() (Line: 51)
    Drupal\Core\StackMiddleware\StackedHttpKernel->handle() (Line: 704)
    Drupal\Core\DrupalKernel->handle() (Line: 19)

  • Status changed to Fixed 11 months ago
  • 🇮🇱Israel jsacksick

    You mentioned you're using Commerce 2.36, how would expect it to be fixed there? Since the fix is in dev?

  • 🇹🇭Thailand Nick Hope

    @jsacksick Ah, sorry. I'm used to seeing the dev version in issue metadata, not a specific version, so I got confused. Thanks for putting me right. The patch applies to 8.x-2.36 and solves the issue for me.

  • Automatically closed - issue fixed for 2 weeks with no activity.

Production build 0.71.5 2024