In the back of my mind ... there are always been a problem with my IDE's autocomplete when mucking around with create() methods ...

For view plugins the root interface create() annotation is corrupt.

Just for comedy value I am including a list of classes that extends ViewPluginInterface::create()

Drupal\views\Plugin\views\field\Field, Drupal\views\Plugin\views\PluginBase, Drupal\rest\Plugin\views\display\RestExport, Drupal\views\Plugin\views\row\EntityRow, system\Plugin\views\field\BulkForm, Drupal\datetime\Plugin\views\filter\Date, Drupal\views\Plugin\views\display\Page, Drupal\views\Plugin\views\argument\Date, Drupal\user\Plugin\views\access\Permission, Drupal\views\Plugin\views\cache\Time, Drupal\views\Plugin\views\display\PathPluginBase, Drupal\views\Plugin\views\display\Block, Drupal\taxonomy\Plugin\views\argument_default\Tid, Drupal\taxonomy\Plugin\views\filter\TaxonomyIndexTid, Drupal\views\Plugin\views\field\EntityOperations, Drupal\views\Plugin\views\argument_default\Raw, Drupal\views\Plugin\views\filter\Bundle, Drupal\user\Plugin\views\access\Role, Drupal\user\Plugin\views\field\Permissions, Drupal\block_content\Plugin\views\area\ListingEmpty, comment\Plugin\views\field\NodeNewComments, Drupal\user\Plugin\views\filter\Permissions, Drupal\views\Plugin\views\argument_validator\Entity, Drupal\views\Plugin\views\field\Date, file\Plugin\views\argument\Fid, node\Plugin\views\argument\Vid, Drupal\views\Plugin\views\area\Entity, Drupal\views\Plugin\views\field\LinkBase, Drupal\views\Plugin\views\area\View, Drupal\views\Plugin\views\field\EntityLabel, node\Plugin\views\argument_default\Node, Drupal\rest\Plugin\views\style\Serializer, Drupal\user\Plugin\views\argument_default\User, Drupal\taxonomy\Plugin\views\field\TaxonomyIndexTid, Drupal\taxonomy\Plugin\views\relationship\NodeTermData, Drupal\user\Plugin\views\field\Roles, Drupal\views\Plugin\views\filter\LanguageFilter, comment\Plugin\views\argument\UserUid, node\Plugin\views\area\ListingEmpty, Drupal\user\Plugin\views\argument\RolesRid, Drupal\user\Plugin\views\filter\Roles, Drupal\views\Plugin\views\field\TimeInterval, aggregator\Plugin\views\argument\Fid, aggregator\Plugin\views\argument\Iid, Drupal\taxonomy\Plugin\views\argument\VocabularyVid, Drupal\user\Plugin\views\argument\Uid, node\Plugin\views\argument\Type, node\Plugin\views\argument\Nid, Drupal\views\Plugin\views\row\RssPluginBase, Drupal\user\Plugin\views\field\UserData, Drupal\taxonomy\Plugin\views\argument\IndexTidDepth, Drupal\taxonomy\Plugin\views\argument\Taxonomy, and Drupal\views\Plugin\views\relationship\EntityReverse.

Issue fork drupal-2634022

Command icon 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

martin107 created an issue. See original summary.

martin107’s picture

StatusFileSize
new1008 bytes

added the param type mixed.

martin107’s picture

Category: Task » Bug report
dawehner’s picture

Status: Needs review » Needs work

IMHO we should remove that method from the interface, it simply doesn't belong there.

damiankloip’s picture

Agree, not sure why it is on there now. It shouldn't be. static::create() is the worst kind of injection.

dawehner’s picture

static::create() is the worst kind of injection.

Well, IMHO its okayish, its not worse than annotation based injection, which for some reason some people like, but we don't have it in Drupal.

damiankloip’s picture

Yeah, I mean in Drupal at least. I hope we never have annotation based injection...

martin107’s picture

I also find create() based injection undesirable,

Taking Drupal\views\Plugin\views\field\LinkBase as an example picked at random

The overridden create() injects the accessManager
There is also an implied injection using \Drupal::currentUser()

I prefer create() to \Drupal::xyz()

It is difficult to undo that design decision at this late stage as it represents a mountain of work ... which grows daily as contrib is railroaded into the bad practice.

Speaking constructively, what we need to do is lobby for the pattern to be removed/deprecated in Drupal9 or later.

It would be better to mark it deprecated sooner rather than later.

Anyway for now, I would still recommend this patch, as it is better to reflect reality.

Version: 8.0.x-dev » 8.1.x-dev

Drupal 8.0.6 was released on April 6 and is the final bugfix release for the Drupal 8.0.x series. Drupal 8.0.x will not receive any further development aside from security fixes. Drupal 8.1.0-rc1 is now available and sites should prepare to update to 8.1.0.

Bug reports should be targeted against the 8.1.x-dev branch from now on, and new development or disruptive changes should be targeted against the 8.2.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

Version: 8.1.x-dev » 8.2.x-dev

Drupal 8.1.9 was released on September 7 and is the final bugfix release for the Drupal 8.1.x series. Drupal 8.1.x will not receive any further development aside from security fixes. Drupal 8.2.0-rc1 is now available and sites should prepare to upgrade to 8.2.0.

Bug reports should be targeted against the 8.2.x-dev branch from now on, and new development or disruptive changes should be targeted against the 8.3.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

Version: 8.2.x-dev » 8.3.x-dev

Drupal 8.2.6 was released on February 1, 2017 and is the final full bugfix release for the Drupal 8.2.x series. Drupal 8.2.x will not receive any further development aside from critical and security fixes. Sites should prepare to update to 8.3.0 on April 5, 2017. (Drupal 8.3.0-alpha1 is available for testing.)

Bug reports should be targeted against the 8.3.x-dev branch from now on, and new development or disruptive changes should be targeted against the 8.4.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

martin107’s picture

Status: Needs work » Needs review
StatusFileSize
new23.83 KB

I find myself still wanting to resolve this 2 years later

Maybe I should have marked this "needs review" earlier :(

So from #4

IMHO we should remove that method from the interface, it simply doesn't belong there.

And 2 years ago in #8 when D9 was in the far far future ... I want to skip that step and just let the documentation reflect reality -- and document accurately something no one was happy with.

I am including doxygen inheritance diagram so you can see at a glance the complex dependancy we have here...

I am animated enough to want to fix it properly today ....but the diagram shows it would be a big job

@dawehner, @damiankloip

Can I ask what you 2017 opinion is?

Is is reasonable to fix it properly now?

ViewPluginInterface

martin107’s picture

Version: 8.3.x-dev » 8.4.x-dev
Component: documentation » views.module
Category: Bug report » Task

.

Version: 8.4.x-dev » 8.5.x-dev

Drupal 8.4.0-alpha1 will be released the week of July 31, 2017, which means new developments and disruptive changes should now be targeted against the 8.5.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

Version: 8.5.x-dev » 8.6.x-dev

Drupal 8.5.0-alpha1 will be released the week of January 17, 2018, which means new developments and disruptive changes should now be targeted against the 8.6.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

Version: 8.6.x-dev » 8.7.x-dev

Drupal 8.6.0-alpha1 will be released the week of July 16, 2018, which means new developments and disruptive changes should now be targeted against the 8.7.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

Version: 8.7.x-dev » 8.8.x-dev

Drupal 8.7.0-alpha1 will be released the week of March 11, 2019, which means new developments and disruptive changes should now be targeted against the 8.8.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

Version: 8.8.x-dev » 8.9.x-dev

Drupal 8.8.0-alpha1 will be released the week of October 14th, 2019, which means new developments and disruptive changes should now be targeted against the 8.9.x-dev branch. (Any changes to 8.9.x will also be committed to 9.0.x in preparation for Drupal 9’s release, but some changes like significant feature additions will be deferred to 9.1.x.). For more information see the Drupal 8 and 9 minor version schedule and the Allowed changes during the Drupal 8 and 9 release cycles.

Version: 8.9.x-dev » 9.1.x-dev

Drupal 8.9.0-beta1 was released on March 20, 2020. 8.9.x is the final, long-term support (LTS) minor release of Drupal 8, which means new developments and disruptive changes should now be targeted against the 9.1.x-dev branch. For more information see the Drupal 8 and 9 minor version schedule and the Allowed changes during the Drupal 8 and 9 release cycles.

Version: 9.1.x-dev » 9.2.x-dev

Drupal 9.1.0-alpha1 will be released the week of October 19, 2020, which means new developments and disruptive changes should now be targeted for the 9.2.x-dev branch. For more information see the Drupal 9 minor version schedule and the Allowed changes during the Drupal 9 release cycle.

Version: 9.2.x-dev » 9.3.x-dev

Drupal 9.2.0-alpha1 will be released the week of May 3, 2021, which means new developments and disruptive changes should now be targeted for the 9.3.x-dev branch. For more information see the Drupal core minor version schedule and the Allowed changes during the Drupal core release cycle.

Version: 9.3.x-dev » 9.4.x-dev

Drupal 9.3.0-rc1 was released on November 26, 2021, which means new developments and disruptive changes should now be targeted for the 9.4.x-dev branch. For more information see the Drupal core minor version schedule and the Allowed changes during the Drupal core release cycle.

Version: 9.4.x-dev » 9.5.x-dev

Drupal 9.4.0-alpha1 was released on May 6, 2022, which means new developments and disruptive changes should now be targeted for the 9.5.x-dev branch. For more information see the Drupal core minor version schedule and the Allowed changes during the Drupal core release cycle.

Version: 9.5.x-dev » 10.1.x-dev

Drupal 9.5.0-beta2 and Drupal 10.0.0-beta2 were released on September 29, 2022, which means new developments and disruptive changes should now be targeted for the 10.1.x-dev branch. For more information see the Drupal core minor version schedule and the Allowed changes during the Drupal core release cycle.

dpi’s picture

Ran into this with PHPStan + phpstan/phpstan-strict-rules

The current docblock of {inheritdoc} + create being at the root really confuses PHPStan badly, adding three identical errors for each views plugin with a overriding create method:

phpstan: Parameter #3 $plugin_id (string) of method Drupal\mymodule\Plugin\views\field\MyField::create() should be contravariant with parameter $plugin_id (mixed) of method Drupal\views\Plugin\views\ViewsPluginInterface::create()
phpstan: Parameter #3 $plugin_id (string) of method Drupal\mymodule\Plugin\views\field\MyField::create() should be contravariant with parameter $plugin_id (mixed) of method Drupal\views\Plugin\views\ViewsPluginInterface::create()
phpstan: Parameter #3 $plugin_id (string) of method Drupal\mymodule\Plugin\views\field\MyField::create() should be contravariant with parameter $plugin_id (mixed) of method Drupal\views\Plugin\views\ViewsPluginInterface::create()

Either we should remove \Drupal\views\Plugin\views\ViewsPluginInterface::create, or make \Drupal\views\Plugin\views\ViewsPluginInterface implement \Drupal\Core\Plugin\ContainerFactoryPluginInterface.

I don't think we are permitted to assume projects are always using \Drupal\views\Plugin\views\PluginBase, which already extends ContainerFactoryPluginInterface, and the method already exists. So leaning towards making ViewsPluginInterface extend ContainerFactoryPluginInterface.

dpi’s picture

Assigned: Unassigned » dpi
Issue tags: +PHPStan-Strict

I'll probably add a bunch of things under this tag related to https://github.com/phpstan/phpstan-strict-rules

We already have PHPStan-0 + PHPStan-1

dpi’s picture

Title: ViewsPluginInterface::create() has an invalid dockblock. » ViewsPluginInterface::create() has an invalid dockblock, breaking PHPStan-strict
Assigned: dpi » Unassigned

Pushed MR.

Making this more about PHPStan since its becoming more of a thing.

dpi’s picture

Title: ViewsPluginInterface::create() has an invalid dockblock, breaking PHPStan-strict » ViewsPluginInterface::create() inherits from nothing, breaking PHPStan-strict
smustgrave’s picture

Status: Needs review » Reviewed & tested by the community
Issue tags: +Needs Review Queue Initiative

Seems like a good change.

Only question is if this will need a change record.

  • catch committed 0ce583b1 on 10.1.x
    Issue #2634022 by martin107, dpi: ViewsPluginInterface::create()...
catch’s picture

Status: Reviewed & tested by the community » Fixed

Looks good. No need for a change record IMO, the method is already there.

Status: Fixed » Closed (fixed)

Automatically closed - issue fixed for 2 weeks with no activity.