Quantcast
Channel: Issues for Drupal core
Viewing all articles
Browse latest Browse all 299604

Use PHP attributes instead of doctrine annotations

$
0
0

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

Remaining tasks

User interface changes

API changes

Data model changes

Release notes snippet


Viewing all articles
Browse latest Browse all 299604

Latest Images

Trending Articles



Latest Images

<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>