Problem/Motivation

The plugin system allows plugins to specify a class to provide plugin definitions based on the definition of the original plugin class. These definitions are called derivative plugin definitions. However, the class that provides them is called the derivative class, while it itself is not a derivative at all.

This confusion makes it hard to explain how the plugin system works, and to provide exceptions that are specific to derivative plugins or those classes that provide their definitions.

Proposed resolution

Rename derivative classess to derivers, as what they do is derive plugin definitions.

Remaining tasks

None.

User interface changes

None.

API changes

  • The derivative plugin definition key is renamed to deriver.
  • DerivativeInterface is renamed to DeriverInterface.
  • ContainerDerivativeInterface is renamed to ContainerDeriverInterface.
  • DerivativeBase is renamed to DeriverBase.

These are all naming changes. There are no functional changes.

Original report by @username

Posted by xjm

Problem/Motivation

This is a followup for #1535868: Convert all blocks into plugins.

  • Currently, the plugin system has the convention that derivative classes have the same name as the class for which they provide derivative definitions, e.g.,
    Drupal\custom_block\Plugin\block\block\CustomBlock
    and
    Drupal\custom_block\Plugin\Derivative\CustomBlock
  • This is merely a naming convention and not a requirement, since the derivative class is specified in the plugin definition (e.g. in the annotation with annotated discovery).
  • The OO naming conventions specify that:

    Classes and interfaces should have names that stand alone to tell what they do without having to refer to the namespace, read well, and are as short as possible without losing functionality information or leading to ambiguity

    Having two closely related classes with exactly the same name does not meet this requirement.

  • It's especially confusing when one does not already have a thorough understanding of the plugin system. I was reviewing #1535868: Convert all blocks into plugins for weeks before I "got" it. If the classes had been named differently, it would have saved me some time.

Proposed resolution

  • Come up with a different naming convention for derivative classes, something like, e.g., CustomBlockDerivative.
  • Rename derivative classes according to this standard.
CommentFileSizeAuthor
#117 drupal_1875996_117.patch80.05 KBneclimdul
#116 drupal_1875996_116.patch0 bytesneclimdul
#112 drupal_1875996_112.patch80.05 KBxano
#111 drupal_1875996_111.patch84.81 KBxano
#111 interdiff.txt5.22 KBxano
#108 interdiff.txt2.99 KBtim.plunkett
#108 deriver-1875996-108.patch80.3 KBtim.plunkett
#102 drupal_1875996_102.patch79.81 KBxano
#102 interdiff.txt1.54 KBxano
#99 drupal_1875996_99.patch79.87 KBxano
#99 interdiff.txt49.62 KBxano
#97 drupal_1875996_97.patch80.34 KBxano
#91 drupal_1875996_91.patch78.72 KBxano
#88 drupal_1875996_88.patch86.18 KBxano
#83 drupal_1875996_83.patch80.97 KBxano
#73 drupal8-reconsider_naming_conventions_for_derivative_classes-1875996-73.patch81.01 KBrajendar reddy
#65 drupal8-reconsider_naming_conventions_for_derivative_classes-1875996-65.patch81.01 KBJalandhar
#62 interdiff.txt2.93 KBxano
#62 drupal_1875996_62.patch81 KBxano
#60 interdiff.txt1.67 KBxano
#60 drupal_1875996_60.patch78.07 KBxano
#58 drupal_1875996_58.patch78.27 KBxano
#56 drupal_1875996_56.patch77.48 KBxano
#46 interdiff.txt3.11 KBxano
#46 drupal_1875996_46.patch73.6 KBxano
#40 drupal_1875996_40.patch75.32 KBxano
#40 interdiff.txt0 bytesxano
#38 interdiff.txt5.79 KBxano
#38 drupal_1875996_38.patch75.32 KBxano
#33 drupal_1875996_33.patch68.93 KBxano
#26 drupal_1875996_26.patch74.18 KBxano
#24 interdiff.txt2.09 KBxano
#24 drupal_1875996_24.patch74.02 KBxano
#21 drupal_1875996_21.patch75.06 KBxano
#10 deriver-1875996-10.patch37.98 KBtim.plunkett
#6 plugin-1875996-6.patch19.07 KBtim.plunkett
#4 plugin-1875996-4.patch10.39 KBtim.plunkett

Comments

xjm’s picture

Issue tags: +Block plugins
tim.plunkett’s picture

This wreaks havoc on my vim ctags. I'm +1 to adding 'Derivative' as a suffix

jhodgdon’s picture

We do have an issue somewhere about reviewing all class names and making sure they follow the standards. There are a ton with problems... this should probably be put as a sub-issue or duplicate of that other issue... Let's see, where is it?
#1809930: [meta] Many core class names violate naming standards

tim.plunkett’s picture

Status: Active » Needs review
Issue tags: -VDC
StatusFileSize
new10.39 KB

There were already several classes suffixed with "Deriver", which is more correct, since this class does the deriving, it itself is not the derivative.

Status: Needs review » Needs work

The last submitted patch, plugin-1875996-4.patch, failed testing.

tim.plunkett’s picture

Status: Needs work » Needs review
StatusFileSize
new19.07 KB

I forgot there were string references to those files.

jhodgdon’s picture

Um... What do these "Deriver" classes actually do? The name "Deriver" to me says that the function of the class is to derive something. Is that the case? I really don't know what these classes are. What are they derivatives of or what are they deriving?

Anyway, lines like this just seem very odd to me:

+class AggregatorCategoryBlockDeriver implements DerivativeInterface {

The interface is called "Derivative" and the class is called "Deriver"... Hm...

tim.plunkett’s picture

I intend to open up an issue to rename DerivativeInterface to DeriverInterface.
An example of a Deriver is MenuBlock (now MenuBlockDeriver). It loops through all of the menus on a site, and provides a derivative block plugin, one per menu.
The idea is that you don't need to write a whole new plugin for each menu you add, you have one deriver that has its own logic for determining its derivatives.

jhodgdon’s picture

OK, then the name Deriver makes sense to me. Can't we do the interface in this same patch?

tim.plunkett’s picture

StatusFileSize
new37.98 KB

Sure!

jhodgdon’s picture

The only slightly weird thing left that I see is that the namespaces still have "Derivative" in them:

+ * Definition of Drupal\Component\Plugin\Derivative\DeriverInterface.
...
+ * Contains \Drupal\aggregator\Plugin\Derivative\AggregatorCategoryBlockDeriver.

The method names also confused me, but when I read the documentation I think I agreed that they should still have Derivative in them, not Deriver. But I will add that the docs are using "id" all over, and I don't think they are talking about psychology (look it up: "id" is like ego, superego, id, and "ID" means identifier, one of my pet documentation peeves, but anyway that is a separate issue.)

jhodgdon’s picture

Component: documentation » plugin system

This is not really a docs issue.

neclimdul’s picture

+++ b/core/lib/Drupal/Component/Plugin/Derivative/DeriverInterface.phpundefined
@@ -2,7 +2,7 @@
- * Definition of Drupal\Component\Plugin\Derivative\DerivativeInterface.
+ * Definition of Drupal\Component\Plugin\Derivative\DeriverInterface.

I had the reverse reaction of jhodgdon. The namespace is Derivative and the interface is Deriver?

xjm’s picture

Yeah the word "Deriver" seems a little goofy to me in general.

tim.plunkett’s picture

Well the classes do the deriving. The derivatives themselves are whatever those classes find, like the values in the database that represent a custom block.
So both the namespace and the interface should be changed...

jhodgdon’s picture

Wait a minute. The main purpose of a particular Block derivative class is to define/provide a block, correct? So it seems like the class name shouldn't have derivative or deriver or anything else like that in it. It should just be called the FooBarReallyCoolBlock class or something like that? I mean, it's possible that the way that the class manages to provide a block for use in a site is by being a derivative of another class, but class names should tell the purpose of the class (why it exists), not some detail of the internal mechanisms by which it gets its work done, right?

xjm’s picture

No, the purpose of a derivative class is to extend an existing plugin to provide multiple definitions. So, for example, we have a MenuBlock plugin that provides the basic menu block plugin definition. And then the MenuBlockDerivatives (or whatever) class returns definitions of MenuBlock for each menu. Not all plugins need derivatives, though--for example, the system Powered By Drupal block is only ever one thing.

jhodgdon’s picture

Ah, OK. For the situation in #17, it seems like there should be:
MenuBlock (defines the plugin type for blocks displaying menus)
MenuBlockGenerator (generates a menu block definition for each defined menu)

Generator sounds like a reasonable name to me, but maybe there is a standard computer science term for this pattern that we should use instead?

Crell’s picture

I don't know of a standard CS term, but would that get confused with the UrlGenerator, which is colloquially just called "the generator"?

(Once again, English has insufficient nouns to keep up with Drupal.)

jhodgdon’s picture

I am not sure why it would get confused.

jhodgdon’s picture

Issue summary: View changes

Updated issue summary.

xjm’s picture

Issue summary: View changes

Removing myself from the author field so that I can unfollow issues. --xjm

xano’s picture

StatusFileSize
new75.06 KB

Re-roll, and using deriver instead of the current inconsistent derivative and derivative fetcher.

jhodgdon’s picture

Not all of the files got renamed the same as the classes in that patch. For instance, the first one at the top.

Status: Needs review » Needs work

The last submitted patch, 21: drupal_1875996_21.patch, failed testing.

xano’s picture

Status: Needs work » Needs review
StatusFileSize
new74.02 KB
new2.09 KB

Status: Needs review » Needs work

The last submitted patch, 24: drupal_1875996_24.patch, failed testing.

xano’s picture

StatusFileSize
new74.18 KB

Re-roll.

xano’s picture

Status: Needs work » Needs review

Status: Needs review » Needs work

The last submitted patch, 26: drupal_1875996_26.patch, failed testing.

xano’s picture

Status: Needs work » Needs review

26: drupal_1875996_26.patch queued for re-testing.

Status: Needs review » Needs work

The last submitted patch, 26: drupal_1875996_26.patch, failed testing.

xano’s picture

Status: Needs work » Needs review

26: drupal_1875996_26.patch queued for re-testing.

xano’s picture

26: drupal_1875996_26.patch queued for re-testing.

xano’s picture

StatusFileSize
new68.93 KB

Re-roll, and I renamed getBasePluginId() to getBaseId() and getDerivativePluginId() to getDerivativeId() on \Drupal\Core\Plugin\Discovery\ContainerDeriverInterface per @EclipseGc's request.

Status: Needs review » Needs work

The last submitted patch, 33: drupal_1875996_33.patch, failed testing.

The last submitted patch, 33: drupal_1875996_33.patch, failed testing.

xano’s picture

Status: Needs work » Needs review

33: drupal_1875996_33.patch queued for re-testing.

Status: Needs review » Needs work

The last submitted patch, 33: drupal_1875996_33.patch, failed testing.

xano’s picture

Status: Needs work » Needs review
StatusFileSize
new75.32 KB
new5.79 KB

Status: Needs review » Needs work

The last submitted patch, 38: drupal_1875996_38.patch, failed testing.

xano’s picture

Status: Needs work » Needs review
StatusFileSize
new0 bytes
new75.32 KB

Status: Needs review » Needs work

The last submitted patch, 40: drupal_1875996_40.patch, failed testing.

xano’s picture

Status: Needs work » Needs review
xano’s picture

40: drupal_1875996_40.patch queued for re-testing.

Status: Needs review » Needs work

The last submitted patch, 40: drupal_1875996_40.patch, failed testing.

xano’s picture

Hmmz. I can't reproduce any of these errors locally and the code looks fine too.

xano’s picture

Status: Needs work » Needs review
StatusFileSize
new73.6 KB
new3.11 KB

Meh, wrong .gitignore configuration locally.

Status: Needs review » Needs work

The last submitted patch, 46: drupal_1875996_46.patch, failed testing.

xano’s picture

46: drupal_1875996_46.patch queued for re-testing.

Re-testing, as I cannot reproduce the failures locally.

xano’s picture

Status: Needs work » Needs review

Tests pass now.

neclimdul’s picture

Can we update the summary? 73k is a lot to review without direction.

xano’s picture

Issue summary: View changes
xano’s picture

neclimdul’s picture

I've run out of time today to look at the code but I agree with the documented API changes. +1

xano’s picture

46: drupal_1875996_46.patch queued for re-testing.

Status: Needs review » Needs work

The last submitted patch, 46: drupal_1875996_46.patch, failed testing.

xano’s picture

Status: Needs work » Needs review
StatusFileSize
new77.48 KB

Status: Needs review » Needs work

The last submitted patch, 56: drupal_1875996_56.patch, failed testing.

xano’s picture

Status: Needs work » Needs review
StatusFileSize
new78.27 KB

Re-roll because of changes in \Drupal\Tests\Core\Plugin\Discovery\DerivativeDiscoveryDecoratorTest.

Status: Needs review » Needs work

The last submitted patch, 58: drupal_1875996_58.patch, failed testing.

xano’s picture

Status: Needs work » Needs review
StatusFileSize
new78.07 KB
new1.67 KB

Status: Needs review » Needs work

The last submitted patch, 60: drupal_1875996_60.patch, failed testing.

xano’s picture

Status: Needs work » Needs review
StatusFileSize
new81 KB
new2.93 KB
xano’s picture

62: drupal_1875996_62.patch queued for re-testing.

Status: Needs review » Needs work

The last submitted patch, 62: drupal_1875996_62.patch, failed testing.

Jalandhar’s picture

Status: Needs work » Needs review
StatusFileSize
new81.01 KB

Updating with reroll. Please review.

xano’s picture

Which parts did not apply?

Jalandhar’s picture

@xano,

For below.

-----------------------------
diff --git a/core/modules/system/lib/Drupal/system/Plugin/Block/SystemMenuBlock.php b/core/modules/system/lib/Drupal/system/Plugin/Block/SystemMenuBlock.php
index 15cb1d8..983d84f 100644
--- a/core/modules/system/lib/Drupal/system/Plugin/Block/SystemMenuBlock.php
+++ b/core/modules/system/lib/Drupal/system/Plugin/Block/SystemMenuBlock.php
@@ -17,7 +17,7 @@
* id = "system_menu_block",
* admin_label = @Translation("Menu"),
* category = @Translation("Menus"),
- * derivative = "Drupal\system\Plugin\Derivative\SystemMenuBlock"
+ * deriver_class = "Drupal\system\Plugin\Derivative\SystemMenuBlock"
* )
*/
class SystemMenuBlock extends BlockBase {
diff --git a/core/modules/system/lib/Drupal/system/Plugin/Derivative/SystemMenuBlock.php b/core/modules/system/lib/Drupal/system/Plugin/Derivative/SystemMenuBlock.php
index 72a4c49..39cef36 100644
--- a/core/modules/system/lib/Drupal/system/Plugin/Derivative/SystemMenuBlock.php
+++ b/core/modules/system/lib/Drupal/system/Plugin/Derivative/SystemMenuBlock.php
@@ -7,9 +7,9 @@

namespace Drupal\system\Plugin\Derivative;

-use Drupal\Component\Plugin\Derivative\DerivativeBase;
+use Drupal\Component\Plugin\Deriver\DeriverBase;
use Drupal\Core\Entity\EntityStorageControllerInterface;
-use Drupal\Core\Plugin\Discovery\ContainerDerivativeInterface;
+use Drupal\Core\Plugin\Discovery\ContainerDeriverInterface;
use Symfony\Component\DependencyInjection\ContainerInterface;

/**
diff --git a/core/modules/views/lib/Drupal/views/Plugin/Derivative/ViewsBlock.php b/core/modules/views/lib/Drupal/views/Plugin/Derivative/ViewsBlock.php
index 9541124..05c7dc4 100644
--- a/core/modules/views/lib/Drupal/views/Plugin/Derivative/ViewsBlock.php
+++ b/core/modules/views/lib/Drupal/views/Plugin/Derivative/ViewsBlock.php
@@ -8,7 +8,7 @@
namespace Drupal\views\Plugin\Derivative;

use Drupal\Core\Entity\EntityStorageControllerInterface;
-use Drupal\Core\Plugin\Discovery\ContainerDerivativeInterface;
+use Drupal\Core\Plugin\Discovery\ContainerDeriverInterface;
use Symfony\Component\DependencyInjection\ContainerInterface;

/**
diff --git a/core/modules/views/lib/Drupal/views/Plugin/Derivative/ViewsExposedFilterBlock.php b/core/modules/views/lib/Drupal/views/Plugin/Derivative/ViewsExposedFilterBlock.php
index 29439a6..3e08fd0 100644
--- a/core/modules/views/lib/Drupal/views/Plugin/Derivative/ViewsExposedFilterBlock.php
+++ b/core/modules/views/lib/Drupal/views/Plugin/Derivative/ViewsExposedFilterBlock.php
@@ -7,7 +7,7 @@

namespace Drupal\views\Plugin\Derivative;

-use Drupal\Core\Plugin\Discovery\ContainerDerivativeInterface;
+use Drupal\Core\Plugin\Discovery\ContainerDeriverInterface;
use Drupal\Core\Entity\EntityStorageControllerInterface;
use Symfony\Component\DependencyInjection\ContainerInterface;
--------------------------------------

xano’s picture

Status: Needs review » Reviewed & tested by the community

Thanks! Next time you can also use the <code> tag when you paste code, or use http://pastebin.com if the code is more than a few lines.

damiankloip’s picture

+++ b/core/lib/Drupal/Component/Plugin/DerivativeInspectionInterface.php
@@ -18,7 +18,7 @@
-  public function getBasePluginId();
+  public function getBaseId();

How come this is a part of this issue? Doesn't seem like a requirement for the derivative > deriver change?

xano’s picture

Someone asked me to make that consistent in this issue, as we have getDerivativeId() as well. That person may have been EclipseCG, but I am not sure.

neclimdul’s picture

alexpott’s picture

Status: Reviewed & tested by the community » Needs work
Issue tags: +Needs reroll

drupal8-reconsider_naming_conventions_for_derivative_classes-1875996-65.patch no longer applies.

error: patch failed: core/modules/views/lib/Drupal/views/Plugin/Derivative/ViewsLocalTask.php:8
error: core/modules/views/lib/Drupal/views/Plugin/Derivative/ViewsLocalTask.php: patch does not apply

rajendar reddy’s picture

Status: Needs work » Needs review
StatusFileSize
new81.01 KB

Updating patch with reroll. Please review.

xano’s picture

Status: Needs review » Reviewed & tested by the community

Status: Reviewed & tested by the community » Needs work
Jalandhar’s picture

Status: Needs work » Needs review
Jalandhar’s picture

Status: Needs review » Reviewed & tested by the community

There might be a bot issue. Back to RTBC, as per #74.

xjm’s picture

Status: Reviewed & tested by the community » Needs work
Issue tags: -Needs reroll +Needs change record

This absolutely needs some change record action. I think we both want a draft change record here, and a list of all the existing change records that need to be updated for this so we can update them after this goes in. Thanks!

xjm’s picture

xano’s picture

The change records that will need to be changed are https://drupal.org/node/2165243 and https://drupal.org/node/2044515.

xano’s picture

Status: Needs work » Needs review

73: drupal8-reconsider_naming_conventions_for_derivative_classes-1875996-73.patch queued for re-testing.

I also added a change record draft.

Status: Needs review » Needs work
xano’s picture

Status: Needs work » Needs review
Issue tags: -Needs change record
StatusFileSize
new80.97 KB

Re-roll.

xjm’s picture

Thanks @Xano!

xano’s picture

83: drupal_1875996_83.patch queued for re-testing.

xano’s picture

83: drupal_1875996_83.patch queued for re-testing.

Status: Needs review » Needs work

The last submitted patch, 83: drupal_1875996_83.patch, failed testing.

xano’s picture

Status: Needs work » Needs review
StatusFileSize
new86.18 KB

Re-roll.

xjm’s picture

Issue tags: +beta target
xano’s picture

Marking this as a DX improvement, because we currently do not properly distinguish between derivative plugins and derivers in terms of jargon.

xano’s picture

StatusFileSize
new78.72 KB

Re-roll.

xano’s picture

91: drupal_1875996_91.patch queued for re-testing.

neclimdul’s picture

So I've actively been trying to avoid driving this issue and let the community figure out how to name this. It feels like we're getting to a consensus but before we move to RTBC I want to go ahead and get this out.

+++ b/core/lib/Drupal/Component/Plugin/Deriver/DeriverBase.php
@@ -2,20 +2,15 @@
- * Contains Drupal\Component\Plugin\Derivative\DerivativeBase.
+ * Contains \Drupal\Component\Plugin\Deriver\DeriverBase.

I'm don't think this namespace change is useful. When listening to people talk about plugins outside this discussion, I've heard things like "use Derivatives" and "those are implemented by Derivatives." They aren't talking about the class, they're talking about the concept. Derivers are the tool and that does seem to make the language better, but Derivative is the concept. I don't think we'll probably have any other classes in the namespace, but I do think it would be better to leave the namespace the conceptual term even if it doesn't match the class.

xano’s picture

That makes sense.

tim.plunkett’s picture

+1 for #93

xano’s picture

Assigned: Unassigned » xano

Let's also get rid of the _class suffix of deriver_class, as we don't do that anywhere else. For all we know we'll support derivers to be services in the future.

xano’s picture

StatusFileSize
new80.34 KB

Re-roll. Will fix the naming issues in the following patch.

Status: Needs review » Needs work

The last submitted patch, 97: drupal_1875996_97.patch, failed testing.

xano’s picture

Status: Needs work » Needs review
StatusFileSize
new49.62 KB
new79.87 KB

Fixed the test failure, the namespace, and the annotation property name.

xano’s picture

Issue summary: View changes

Status: Needs review » Needs work

The last submitted patch, 99: drupal_1875996_99.patch, failed testing.

xano’s picture

Status: Needs work » Needs review
StatusFileSize
new1.54 KB
new79.81 KB
xano’s picture

102: drupal_1875996_102.patch queued for re-testing.

neclimdul’s picture

Status: Needs review » Reviewed & tested by the community

Looks good to me. I'd say the change record updates can happen after commit? I could be wrong but going to be bold and RTBC it.

xjm’s picture

Yep, I think so: Per @Xano:

The change records that will need to be changed are https://drupal.org/node/2165243 and https://drupal.org/node/2044515.

Those are just minor corrections that can be made once the patch is committed and we publish https://www.drupal.org/node/2257811.

Status: Reviewed & tested by the community » Needs work

The last submitted patch, 102: drupal_1875996_102.patch, failed testing.

chx’s picture

tim.plunkett’s picture

Assigned: xano » neclimdul
Status: Needs work » Needs review
StatusFileSize
new80.3 KB
new2.99 KB

In #2287097: Use block template to render blocks, we're having problems because BlockPluginInterface does not implement DerivativeInspectionInterface.
However, we call it indiscriminately, and BlockBase implements all of the methods.

So instead of cheating in all of those docs, I'l like to see this fixed in place.

Assigning to @neclimdul for final sign off.

neclimdul’s picture

Status: Needs review » Needs work

There are a ton of @var comments in here. I'm not sure we need all them but we don't have guidelines so what ever.

  1. +++ b/core/lib/Drupal/Component/Plugin/Discovery/DerivativeDiscoveryDecorator.php
    @@ -19,14 +19,25 @@ class DerivativeDiscoveryDecorator implements DiscoveryInterface {
    +   * Creates a new class instance.
    

    "Creates a new instance" should be sufficient. It confuses me if only because its creating a new object, not a class. #nitpickofthemonth

  2. +++ b/core/lib/Drupal/Core/Plugin/Discovery/ContainerDerivativeDiscoveryDecorator.php
    @@ -14,22 +14,22 @@ class ContainerDerivativeDiscoveryDecorator extends DerivativeDiscoveryDecorator
    +        if (is_subclass_of($class, '\Drupal\Core\Plugin\Discovery\ContainerDeriverInterface')) {
    +          /** @var \Drupal\Core\Plugin\Discovery\ContainerDeriverInterface $class */
    +          $this->derivers[$base_plugin_id] = $class::create(\Drupal::getContainer(), $base_plugin_id);
             }
    

    I'm going to make an exception for this @var which seems a bit useless. I'm aware phpstorm doesn't parse that which is unfortunate but its one method call and its really obvious what's happening so I don't see the point. It doesn't actually document anything useful.

  3. +++ b/core/modules/search/src/Plugin/Derivative/SearchLocalTask.php
    @@ -7,15 +7,15 @@
    +class SearchLocalTask extends \Drupal\Component\Plugin\Derivative\DeriverBase implements ContainerDeriverInterface {
    

    Fully qualified?

  4. +++ b/core/modules/system/src/Plugin/Derivative/SystemMenuBlock.php
    @@ -17,7 +17,7 @@
    +class SystemMenuBlock extends \Drupal\Component\Plugin\Derivative\DeriverBase implements ContainerDeriverInterface {
    

    Fully qualified?

  5. +++ b/core/modules/system/tests/modules/menu_test/src/Plugin/Derivative/LocalTaskTest.php
    @@ -6,9 +6,9 @@
    +class LocalTaskTest extends \Drupal\Component\Plugin\Derivative\DeriverBase {
    

    Again...

xano’s picture

I'm going to make an exception for this @var which seems a bit useless. I'm aware phpstorm doesn't parse that which is unfortunate but its one method call and its really obvious what's happening so I don't see the point. It doesn't actually document anything useful.

It does, as it lets PhpStorm (and perhaps other IDEs) know the variable type. Without the comment, PhpStorm wouldn't know, and it would mark subsequent method calls as invalid.

Again...

I blame the system...

xano’s picture

Status: Needs work » Needs review
StatusFileSize
new5.22 KB
new84.81 KB
xano’s picture

StatusFileSize
new80.05 KB

Here is the same patch, but with renames, so it should be slightly smaller and easier to read.

neclimdul’s picture

Status: Needs review » Reviewed & tested by the community

It does, as it lets PhpStorm (and perhaps other IDEs) know the variable type. Without the comment, PhpStorm wouldn't know, and it would mark subsequent method calls as invalid.

So, like I said, there are no guidelines but I still want to be clear. My view is your IDE is there to help the developer read code and we don't need help reading is_subclass_of.

I guess I see this as doing something like this which would never fly.

if (is_bool($foobar)) {
  // This is bool!
  return $foobar;
}

I'm not going to stop this issue on such a unclear doc issue though, RTBC.

xano’s picture

This is indeed not part of our docs. However, PhpStorm doesn't use is_subclass_of() for type hints, so I tend to add @var comments to help me see if the code is correct in the blink of an eye. I've found doing this helps me find problems much more quickly.

Status: Reviewed & tested by the community » Needs work

The last submitted patch, 112: drupal_1875996_112.patch, failed testing.

neclimdul’s picture

Status: Needs work » Needs review
StatusFileSize
new0 bytes

straight reroll

neclimdul’s picture

StatusFileSize
new80.05 KB

a patch with some content...

tim.plunkett’s picture

Status: Needs review » Reviewed & tested by the community

Looks good to me!

  • Dries committed 41576e1 on 8.x
    Issue #1875996 by Xano, tim.plunkett, neclimdul, Rajendar Reddy,...
dries’s picture

Status: Reviewed & tested by the community » Fixed
Issue tags: +Needs followup

Good first step so committed to 8.x. Thanks everyone! This patch didn't rename Drupal\block_content\Plugin\Derivative\BlockContent. Per the original issue summary, do we still want to do that, since there's also a Drupal\block_content\Entity\BlockContent? Would generically adding a Deriver suffix to all deriver classes make sense?

tstoeckler’s picture

Follow-up: #2295571: Bogus CustomBlock class in repo

(This is not the follow-up so not removing the "needs follow-up" tag.)

Status: Fixed » Closed (fixed)

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