Problem/Motivation
Since Drupal 11.3 and https://www.drupal.org/node/3542837 the Drupal\Core\Plugin\PluginBase class has been extended with a generic version of the create() method suitable for most plugins with dependency injection.
The ExtraFieldDisplayBase and ExtraFieldFormBase classes could extend Drupal\Core\Plugin\PluginBase instead of Drupal\Component\Plugin\PluginBase and allow for the autowiring of services to the plugins which extend it (provided they implement \Drupal\Core\Plugin\ContainerFactoryPluginInterface).
Steps to reproduce
N/a.
Proposed resolution
Make the code change which should be as simple as switching between the two classes.
Remaining tasks
Create MR, review, merge.
User interface changes
None.
API changes
None.
Data model changes
None.
Issue fork extra_field-3579974
Show commands
Start within a Git clone of the project using the version control instructions.
Or, if you do not have SSH keys set up on git.drupalcode.org:
Comments
Comment #3
arousseau commentedComment #4
pcambraAh good to know, thanks @arousseau, but 3.x needs to support both 10.x and 11.x, how do you suggest we can add this while keeping BC?
Comment #5
arousseau commentedHello pcambra. It should be safe to use in 10.x since the
Drupal\Core\Plugin\PluginBasealready exists in that version, and be useful for people using Extra Field with 11.3.xSee https://git.drupalcode.org/project/drupal/-/blob/10.0.x/core/lib/Drupal/... and https://git.drupalcode.org/project/drupal/-/blob/11.3.x/core/lib/Drupal/...
Comment #6
idebr commentedDrupal\Core\Plugin\PluginBase use a number of Traits that are also used in Extra Field plugins:
https://git.drupalcode.org/project/drupal/-/blob/10.0.x/core/lib/Drupal/...
Let's remove those traits from Extra Field plugins to remove duplicates
Comment #8
hitchshockAgree that we need to use
Drupal\Core\Plugin\PluginBaseThis is important for D11+, and it is supported by D10
Switched base class for both types of plugins: ExtraFieldDisplayBase.php and ExtraFieldFormBase.php and did a small code clean up
Comment #9
arousseau commentedComment #10
arousseau commentedThank you hitchshock, I updated the issue summary and title to reflect the changes.
Comment #11
pcambraAre we sure this is the correct change?
Comment #12
hitchshock@pcambra why not?
Most of Drupal plugins extend Drupal\Core\Plugin\PluginBase because of autowiring, e.g. Block plugins and others. It allows to use dependency injections easier. So I don't see any reason to ignore this
Comment #13
pcambraApologies, that's not what I was trying to say, the changes I see in https://git.drupalcode.org/project/extra_field/-/merge_requests/34/diffs are mostly removing stringtranslationtrait?
Comment #14
idebr commentedThe removed traits are redundant because Drupal\Core\Plugin\PluginBase already uses them, see #6
Comment #15
pcambraYeah but those files have no other changes, does PluginBase already use them in Drupal 10? I'd like not to introduce breaking changes if we can avoid them
Comment #16
hitchshock@pcambra everything is ok, even Drupal 10.0.x has traits I cleaned up
https://git.drupalcode.org/project/drupal/-/blob/10.0.x/core/lib/Drupal/...
Comment #18
pcambraThanks all for the clarifications :)