Convert the ConfigEntityType classes to use PHP Attributes

Created on 23 May 2025, 15 days ago

System information

  • Drupal Core Version: ^10.2 && ^11
  • Menu Migration Version: 4.0.1
  • PHP Version: >= 8.1 && <=8.3

Problem/Motivation

The current implementation of ExportType and ImportType classes (both being config entity types) in the module relies on Annotation (@ConfigEntityType) to define their metadata. While functional, the modern PHP approach for such metadata declaration is through PHP Attributes (introduced in PHP 8.0). Drupal Core has adopted this change for config entity types in version 11.1.0: https://www.drupal.org/node/3505422 .

Adopting PHP Attributes offers several benefits, including improved code readability, better IDE support (e.g., easier navigation and refactoring), and a more declarative syntax that is native to the PHP language.

However, a direct replacement of Annotations with Attributes would break backwards compatibility for Drupal installations running on older versions than 11.1.0.

Proposed resolution

To address this, we should update the ExportType and ImportType ConfigEntityType definitions to utilize PHP Attributes while retaining the existing Annotation definitions for backwards compatibility.

This approach ensures that:
- PHP Attributes for defining the ConfigEntityType metadata will be available for Drupal sites running on version 11.1.0 and above.
- For sites running on Drupal versions 10.2.x and above, the existing Annotation-based metadata definition will continue to be used as a fallback, ensuring backwards compatibility.

📌 Task
Status

Active

Version

4.0

Component

Code

Created by

🇷🇴Romania bbu23

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

Comments & Activities

Production build 0.71.5 2024