Extract TranslatableMarkup() from PHP attributes

Created on 22 February 2022, over 2 years ago
Updated 24 May 2023, over 1 year ago

Problem/Motivation

PHP and Drupal adopting native attributes to define plugins and so on in 📌 Use PHP attributes instead of doctrine annotations Fixed
Example code instead of annotation is

#[Block(
  id: "test_context_aware",
  admin_label: new TranslatableMarkup("Test context-aware block"),
  context_definitions: [
    'user' => new EntityContextDefinition(
      data_type: 'entity:user',
      label: new TranslatableMarkup("User Context"),
      required: FALSE,
      constraints: [
        "NotNull" => [],
      ]
    ),
  ]
)]

The new way to to provide translatable strings is TranslatableMarkup() inside of attribute

Proposed resolution

- add parsing support for attributes and PHP 8.1 initializers
- port the change to 8.x branch
- file follow-up to deprecate doctrine annotations

Remaining tasks

- create patch
- follow-up
- review/commit

User interface changes

no

API changes

no

Data model changes

no

Release notes snippet

added support for PHP native attributes

📌 Task
Status

Needs work

Version

3.0

Component

Code

Created by

🇫🇷France andypost

Live updates comments and jobs are added and updated live.
  • PHP 8.1

    The issue particularly affects sites running on PHP version 8.1.0 or later.

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.

  • First commit to issue fork.
  • Open in Jenkins → Open on Drupal.org →
    Core: 7.x + Environment: PHP 5.6 & MySQL 5.5
    last update over 1 year ago
    PHPLint Failed
  • @duadua opened merge request.
  • Open in Jenkins → Open on Drupal.org →
    Core: 10.1.x + Environment: PHP 8.1 & MySQL 5.7
    last update over 1 year ago
    18 pass
  • Status changed to Needs review over 1 year ago
  • Status changed to Needs work over 1 year ago
  • 🇭🇺Hungary Gábor Hojtsy Hungary

    Woah how come potx already finds those strings? Also we should have a text case with context too. And format plural indeed as per #3.

  • Woah how come potx already finds those strings?

    Yeah I was very much surprised to find that out as well. It speaks for PHP attributes that they are mostly just PHP itself

    Also we should have a text case with context too.

    Is this test case enough from your point of view?

    And format plural indeed as per #3.

    I posted a comment on the parent ticket 📌 Use PHP attributes instead of doctrine annotations Fixed due to my lack of understanding what the plan is for that.

    @Gábor Hojtsy
    The job for "PHP 5.6 & MySQL 5.5, D7 PHPLint Failed" is failing at the moment, given it introduces PHP 8.1 only language features into the test file.
    Do you consider this as a problem? We could probably split up the test file into a PHP 8.1 only version.
    Let me know what you think

Production build 0.71.5 2024