Problem/Motivation

Subclasses of PluginBase needlessly access $this->pluginDefinition protected property via $this->getPluginDefinition() method, leading to overly verbose code.

Proposed resolution

Consistently use the protected property

Remaining tasks

Fix

User interface changes

no

API changes

no

CommentFileSizeAuthor
#31 interdiff-28-30.txt967 bytesAnonymous (not verified)
#31 undo_blockbase-2287891-30.patch12.71 KBAnonymous (not verified)
#28 interdiff-27-28.txt566 bytesAnonymous (not verified)
#28 2287891-28.patch13.44 KBAnonymous (not verified)
#27 interdiff-23-27.txt1.66 KBAnonymous (not verified)
#27 2287891-27.patch13.44 KBAnonymous (not verified)
#23 interdiff-18-23.txt1.7 KBAnonymous (not verified)
#23 2287891-23.patch11.99 KBAnonymous (not verified)
#19 2287891-18.patch11.99 KBAnonymous (not verified)
#16 interdiff-2287891-11-16.txt1018 bytesdeepakaryan1988
#16 re-rolling-11-2287891-16.patch13.71 KBdeepakaryan1988
#11 plugins-2287891-11.patch14.13 KBadci_contributor
#6 plugins-2287891-6.patch14.12 KBtadityar
#3 plugins-2287891-3.patch13.16 KBtim.plunkett
#2 blockBase.patch2.47 KBandypost
blockBase.patch586 bytesandypost

Comments

tim.plunkett’s picture

Status: Needs review » Closed (won't fix)

This doesn't really make sense to me.
First, its a simple getter for the plugin definition. Nothing about it will change.
Second, this is a base class, it has the protected property, it should use it.
Third, there are about 100 other places we use $this->pluginDefinition[' directly, I don't know why you would pick this one.

andypost’s picture

Status: Closed (won't fix) » Needs review
Issue tags: +clean-up, +Quick fix
StatusFileSize
new2.47 KB

I pick this one because it confusing to to read this code - because no reason to use different access methods

Here's a opposite patch - convert to direct access to property.

PS: probably it makes sense to check all other places

tim.plunkett’s picture

Title: Use pluginDefinition in BlockBase consistently » Use $this->pluginDefinition directly in plugin classes
Component: block.module » plugin system
Issue summary: View changes
StatusFileSize
new13.16 KB

Not too many, let's just do them all.

andypost’s picture

seems all fixed, just need to check new plugins that was added (context and so on)

znerol’s picture

Status: Needs review » Needs work
Issue tags: +Needs reroll

Does not apply anymore. Potentially affected files include:

$ git grep -l 'this->getPluginDefinition'
core/lib/Drupal/Component/Plugin/ContextAwarePluginBase.php
core/lib/Drupal/Core/Block/BlockBase.php
core/lib/Drupal/Core/Executable/ExecutablePluginBase.php
core/lib/Drupal/Core/Field/WidgetBase.php
core/lib/Drupal/Core/Menu/MenuLinkDefault.php
core/modules/aggregator/src/Plugin/aggregator/processor/DefaultProcessor.php
core/modules/aggregator/tests/modules/aggregator_test/src/Plugin/aggregator/processor/TestProcessor.php
core/modules/menu_link_content/src/Entity/MenuLinkContent.php
core/modules/menu_link_content/src/Plugin/Menu/MenuLinkContent.php
core/modules/rest/src/Plugin/ResourceBase.php
core/modules/rest/src/Plugin/rest/resource/EntityResource.php
core/tests/Drupal/Tests/Core/Plugin/DefaultLazyPluginCollectionTest.php
core/tests/Drupal/Tests/Core/Plugin/DefaultSingleLazyPluginCollectionTest.php
core/tests/Drupal/Tests/Core/Plugin/LazyPluginCollectionTestBase.php
tadityar’s picture

Status: Needs work » Needs review
Issue tags: -Needs reroll
StatusFileSize
new14.12 KB

Re-rolled.

tadityar’s picture

well actually the patch from #6 is not only a re-roll. It also changed some more files.

core/lib/Drupal/Core/Menu/MenuLinkDefault.php
core/modules/menu_link_content/src/Entity/MenuLinkContent.php
core/modules/menu_link_content/src/Plugin/Menu/MenuLinkContent.php
core/tests/Drupal/Tests/Core/Plugin/DefaultLazyPluginCollectionTest.php
core/tests/Drupal/Tests/Core/Plugin/DefaultSingleLazyPluginCollectionTest.php
core/tests/Drupal/Tests/Core/Plugin/LazyPluginCollectionTestBase.php

No changes were made to these files though since they doesn't use $this->getPluginDefinition[

cs_shadow’s picture

Looks good to me. RTBC +1

dawehner’s picture

Status: Needs review » Reviewed & tested by the community

Seems alright.

Status: Reviewed & tested by the community » Needs work

The last submitted patch, 6: plugins-2287891-6.patch, failed testing.

adci_contributor’s picture

Status: Needs work » Needs review
StatusFileSize
new14.13 KB

Reroll

Xano queued 11: plugins-2287891-11.patch for re-testing.

Status: Needs review » Needs work

The last submitted patch, 11: plugins-2287891-11.patch, failed testing.

xano’s picture

Many of the clean-ups just convert things like $definition = $this->getPluginDefinition();$foo = $definition['foo']; to $foo = $this->pluginDefinition['foo'], but in PHP 5.4 we can now do $foo = $this->getPluginDefinition()['foo'] as well.

deepakaryan1988’s picture

Assigned: Unassigned » deepakaryan1988
deepakaryan1988’s picture

Assigned: deepakaryan1988 » Unassigned
Status: Needs work » Needs review
StatusFileSize
new13.71 KB
new1018 bytes

Re-rolling the patch #11 and done the $foo = $this->getPluginDefinition()['foo'] according @Xano who has mentioned his point in #14.

Status: Needs review » Needs work

The last submitted patch, 16: re-rolling-11-2287891-16.patch, failed testing.

Anonymous’s picture

Is it possible to re-run the tests, as qa.drupal.org is no longer in use?

Anonymous’s picture

StatusFileSize
new11.99 KB

Patch #16 could not be applied to the latest dev. I tried manually applying those changes.

Anonymous’s picture

Version: 8.0.x-dev » 8.2.x-dev
jibran’s picture

Status: Needs work » Needs review

Status: Needs review » Needs work

The last submitted patch, 19: 2287891-18.patch, failed testing.

Anonymous’s picture

StatusFileSize
new11.99 KB
new1.7 KB

Please help run tests for this patch.

tim.plunkett’s picture

Status: Needs work » Needs review

Status: Needs review » Needs work

The last submitted patch, 23: 2287891-23.patch, failed testing.

benjy’s picture

+1 to #16, using $this->pluginDefinition directly makes it harder for any child classes that override the getter.

Anonymous’s picture

Status: Needs work » Needs review
StatusFileSize
new13.44 KB
new1.66 KB

Please review this patch. Ignore this, made a silly mistake.

Anonymous’s picture

StatusFileSize
new13.44 KB
new566 bytes

Keeps failing on BlockInterfaceTest.

Anonymous’s picture

The last submitted patch, 27: 2287891-27.patch, failed testing.

Anonymous’s picture

StatusFileSize
new12.71 KB
new967 bytes

Let's see if it works after I undo the changes in BlockBase.php.

The last submitted patch, 28: 2287891-28.patch, failed testing.

Status: Needs review » Needs work

The last submitted patch, 31: undo_blockbase-2287891-30.patch, failed testing.

tim.plunkett’s picture

I think this should be won't fix. None of this patch seems like an improvement.

benjy’s picture

I agree with #34 as well, the changes aren't much of an improvement and they're now different from the original proposal anyway.

xano’s picture

Status: Needs work » Closed (won't fix)

Closing this in accordance with #16, #34, and #35. Nothing is wrong with the code in its current state, and it has been explained that method access is easier to override in case of base classes.