Usage of "new self" in static ContainerFactoryPluginInterface::create function

Created on 16 December 2024, 7 days ago

Problem/Motivation

The static

  • \Drupal\authorization_drupal_roles\Plugin\authorization\Consumer\DrupalRolesConsumer::create
  • \Drupal\authorization\Form\AuthorizationProfileAddForm::create
  • \Drupal\authorization\Form\AuthorizationProfileEditForm::create

functions use new self instead of new static to create an instance of the class.

A new plugin class which extends one of these classes will never be instantiated if it does not override the create function because with new self only the parent class will be instantiated.

Steps to reproduce

  1. implement an authorization consumer extending \Drupal\authorization_drupal_roles\Plugin\authorization\Consumer\DrupalRolesConsumer without overriding create
  2. configure an authorization profile to use the new consumer
  3. witness the new consumer not being used and instead the original consumer being used

Proposed resolution

Use new static instead of new self.

Remaining tasks

  • implement proposed resolution

User interface changes

There are no user interface changes.

API changes

The mentioned classes become extendable without overriding the create function.

Data model changes

There are no data model changes.

🐛 Bug report
Status

Active

Version

1.0

Component

Code

Created by

🇩🇪Germany tgauges

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

Merge Requests

Comments & Activities

Production build 0.71.5 2024