Support for Drupal 7 is ending on 5 January 2025—it’s time to migrate to Drupal 10! Learn about the many benefits of Drupal 10 and find migration tools in our resource center.
Problem/Motivation
abstract class FormatterBase extends PluginSettingsBase implements FormatterInterface, ContainerFactoryPluginInterface {
class LinkFormatter extends FormatterBase implements ContainerFactoryPluginInterface {
class StringFormatter extends FormatterBase implements ContainerFactoryPluginInterface {
...
Proposed resolution
Remove redundant ContainerFactoryPluginInterface
Comment | File | Size | Author |
---|---|---|---|
#12 | raw-interdiff-2-11.txt | 265 bytes | jungle |
#12 | 3112328-9.0.x-11.patch | 10.04 KB | jungle |
#2 | redundant-interface-3112328-2.patch | 10.06 KB | jungle |
Comments
Comment #2
jungleChecked and removed from files below. It might happen in other similar subclasses of non-FormatterBase. But as the title indicated, let this issue focus on subclasses of FormatterBase unless changing the title.
Comment #3
jungleComment #4
jungleComment #5
hash6 CreditAttribution: hash6 at QED42 for Drupal India Association commentedComment #6
hash6 CreditAttribution: hash6 at QED42 for Drupal India Association commentedSince
FormatterBase
already implementsContainerFactoryPluginInterface
, we don't need to implement it in the following classes which extends FormatterBase(or extends class which ultimately extends FormatterBase)Comment #7
andypostRTBC +1 (all formatters are fixed)
PS: would be great to automate detection of that for other plugins
Comment #8
andypostComment #10
xjmComment #11
xjmNice catch!
I checked the inheritance on all those and confirmed that they're descended from FormatterBase one way or another.
I can't think of anything this would disrupt. I did some archaeology as to why we have this state to begin with and it looks like #3051633: Add ContainerFactoryPluginInterface to Drupal\Core\Field\WidgetBase and Drupal\Core\Field\FormatterBase was only committed last summer, but the various implementations added the interface much earlier, for example:
StringFormatter
in #2387019: String field formatters cannot link to their parent entity.EntityReferenceEntityFormatter
in #2404021: entity_reference formatters should be in Core.So this seems fine as a cleanup.
That said, it does not apply to 9.1.x, so we need a D9 version.
Thanks!
Comment #12
jungleThanks @hash6, @andypost and @xjm for reviewing!
A patch rerolled from #2 against 9.0.x
Comment #13
jungleIdeally, this could be done by a phpcs sniffer, but it would take longer to land, So I just filed an issue for further discussion of the policy of handling such kind of issues. #3133122: [policy][no patch] Adjust policy of handling coder relevant Drupal Core issues
Comments are welcome! Thanks!
Comment #14
andypostBack to RTBC
Comment #16
xjmAlright, pushed to 9.1.x. This change is theoretically BC, but we might want to make it 9.1.x-only and create a CR explaining why this change was made, referencing #3051633: Add ContainerFactoryPluginInterface to Drupal\Core\Field\WidgetBase and Drupal\Core\Field\FormatterBase
Leaving at 9.1.x now for commit. Thanks!