Update PHPDoc for DataDefinition

Created on 5 October 2020, over 3 years ago
Updated 30 April 2023, about 1 year ago

Problem/Motivation

PHPStan reports an error when using DataDefinition::setLabel with a TranslatableMarkup.

Parameter #1 $label of method Drupal\Core\TypedData\DataDefinition::setLabel() expects string, Drupal\Core\StringTranslation\TranslatableMarkup given.

Steps to reproduce

  • Create new field type
  • On the function propertyDefinitions add a field definition with a TranslatableMarkup as label like:
return [
      'value' => DataDefinition::create('string')
        ->setLabel(\t('Value'))
        ->setRequired(FALSE),
    ];
  • Analyse it with PHPStan
  • In a custom module, use BaseFieldDefinition::create() to make a field with a translatable label/description.

            BaseFieldDefinition::create('path')
              ->setLabel(t('URL alias'))
              ->setTranslatable(TRUE)
              ->setDisplayOptions('form', [
                'type' => 'path',
                'weight' => 30,
              ])
              ->setDisplayConfigurable('form', TRUE)
              ->setComputed(TRUE);
    

    Proposed resolution

    Update DataDefinition PHPDoc to support this.

    Remaining tasks

    • Create the patch
    πŸ“Œ Task
    Status

    Fixed

    Version

    10.1 ✨

    Component
    Typed dataΒ  β†’

    Last updated 16 days ago

    • Maintained by
    • πŸ‡¦πŸ‡ΉAustria @fago
    Created by

    πŸ‡«πŸ‡·France CurriedN

    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.

    Production build 0.69.0 2024