Problem/Motivation
We use Doctrine's annotations to add metadata to our classes. For example, Block's use annotations to set the block ID and admin label. PHP 8.0 introduced a new language feature PHP attributes to support such metadata.
Proposed resolution
- Add support for PHP attributes
- Deprecate doctrine annotations for removal in Drupal 11.
Here's an example of a block annotation:
/**
* @Block(
* id = "system_powered_by_block",
* admin_label = @Translation("Powered by Drupal")
* )
*/
class SystemPoweredByBlock extends BlockBase {
// ...
}
PHP attributes options
Use named arguments
#[Block(
id: "system_powered_by_block",
admin_label: "Powered by Drupal"
)]
class SystemPoweredByBlock extends BlockBase {
// ...
}
Use arrays
#[Block(array(
"id" => "system_powered_by_block",
"admin_label" => "Powered by Drupal",
))]
class SystemPoweredByBlock extends BlockBase {
// ...
}
Use individual attributes
[#BlockId("system_powered_by_block")]
[#BlockAdminLabel("Powered by Drupal")]
class SystemPoweredByBlock extends BlockBase {
// ...
}
Problems to solve
- How to support @translation. Nested attribute support was only added in PHP 8.1 - see https://wiki.php.net/rfc/new_in_initializers#nested_attributes
- The unused use sniff we use is problematic - need to move to slevomatic version - #3010032: Add dependency on slevomat/coding-standard