Document use of PHP Attributes for plugins

Created on 26 October 2023, over 1 year ago
Updated 28 August 2024, 8 months ago

Problem/Motivation

Core is in the process of converting from Annotation to PHP Attributes for plugins. We need to document the usage of this feature.

Benefits

If we adopted this change, the Drupal Project would benefit by ...

Three supporters required

  1. {link to user}
  2. {link to user}
  3. {link to user}

Proposed changes

Provide all proposed changes to the Drupal Coding standards β†’ . Give a link to each section that will be changed, and show the current text and proposed text as in the following layout:

1. {link to the documentation heading that is to change}

Add current text in blockquotes

Plugin

Plugin type class

{Some text here}

// Attribute class
#[\Attribute(\Attribute::TARGET_CLASS)]
class Action extends Plugin {
…
}

// Plugin manager
 public function __construct(\Traversable $namespaces, CacheBackendInterface $cache_backend, ModuleHandlerInterface $module_handler) {
   parent::__construct('Plugin/Action', $namespaces, $module_handler, 'Drupal\Core\Action\ActionInterface', 'Drupal\Core\Annotation\Action', [], Action::class);
}

Plugin class

{Some text here}

namespace Drupal\Core\Action\Plugin\Action;

use Drupal\Core\Action\Plugin\Action\Derivative\EntityPublishedActionDeriver;
use Drupal\Core\Action\Attribute\Action;
use Drupal\Core\Session\AccountInterface;
use Drupal\Core\StringTranslation\TranslatableMarkup;

/**
 * Publishes an entity.
 */
#[Action(
  id: 'entity:publish_action',
  action_label: new TranslatableMarkup('Publish'),
  deriver: EntityPublishedActionDeriver::class
)]
class PublishAction extends EntityActionBase {], Action::class);
}

2. Repeat the above for each page or sub-page that needs to be changed.

Remaining tasks

  1. List three supporters
  2. Create a Change Record
  3. Review by the Coding Standards Committee
  4. Coding Standards Committee takes action as required
  5. Tagged with 'Needs documentation edits' if Core is not affected
  6. Discussed by the Core Committer Committee, if it impacts Drupal Core
  7. Documentation updates
    1. Edit all pages
    2. Publish change record
    3. Remove 'Needs documentation edits' tag
  8. If applicable, create follow-up issues for PHPCS rules/sniffs changes

For a fuller explanation of these steps see the Coding Standards project page β†’

πŸ“Œ Task
Status

Active

Component

Coding Standards

Created by

πŸ‡³πŸ‡ΏNew Zealand quietone

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

Comments & Activities

Production build 0.71.5 2024