Problem/Motivation

The concept of PluginBags was introduced by views and then expanded to a half dozen other entity types.
They provide a way to lazily instantiate a set of plugin instances.
The suffix Bag was chosen due to its assumed similarity to ParameterBag, FlashBag, etc.
However, it is supposed to mean that the object contains a set of variables or parameters (values).

A Collection is an ordered map of values or other objects.

Additionally, PluginBag (or PluginCollection) doesn't explain its true feature, the laziness.

Proposed resolution

  • Rename PluginBag to LazyPluginCollection
  • Rename classes that extend LazyPluginCollection accordingly. See #28.

Remaining tasks

  • get feedback on release management (can it go in during this phase of the beta?)
  • Finish items found in review.

before

PluginBag
-- DefaultPluginBag
---- ConditionPluginBag
---- FilterBag
---- ImageEffectBag
---- TipsBag
---- DisplayBag
-- DefaultSinglePluginBag
---- ActionBag
---- BlockPluginBag
---- SearchPluginBag
-- TestPluginBag
PluginBagTestBase
-- ConfigurablePluginBagTest
-- DefaultPluginBagTest
-- DefaultSinglePluginBagTest
EntityWithPluginBagsInterface
ConfigEntityBaseWithPluginBags
SearchPluginBagTest

after

LazyPluginCollection
-- DefaultLazyPluginCollection
---- ConditionPluginCollection
---- FilterPluginCollection
---- ImageEffectPluginCollection
---- TipsPluginCollection
---- DisplayPluginCollection
-- DefaultSingleLazyPluginCollection
---- ActionPluginCollection
---- BlockPluginCollection
---- SearchPluginCollection
-- TestLazyPluginCollection
LazyPluginCollectionTestBase
-- ConfigurablePluginCollectionTest
-- DefaultLazyPluginCollectionTest
-- DefaultSingleLazyPluginCollectionTest
EntityWithPluginCollectionInterface
ConfigEntityBaseWithPluginCollections
SearchPluginCollectionTest

User interface changes

N/A

API changes

Yes, all existing base classes and interfaces will change. See the change record.

Comments

tim.plunkett’s picture

Status: Active » Needs review
StatusFileSize
new82.35 KB

Performed renames with phpstorm. Also found some vestigial code.

xjm’s picture

Issue tags: +Needs change record

For what it's worth, PluginBag always terrified me, because suddenly I thought there was some deep Symfony concept I was missing to know how Views plugins worked. LazyPluginCollection is a much more self-explanatory name. :) So +1 for the rename, even though it's kinda a disruptive patch.

There's a few change records that would need updates:
https://drupal.org/list-changes/published/drupal?keywords_description=ba...

And plus we'd want one for this issue itself.

xjm’s picture

Issue tags: +VDC
yesct’s picture

StatusFileSize
new2.78 KB
new82.51 KB

I read the whole patch.

Places that are not simple renames look totally fine. So (for what it is worth) all these changes are good to me.

  1. nit.
    +++ b/core/lib/Drupal/Core/Config/Entity/ConfigEntityBase.php
    @@ -296,13 +296,13 @@ public function calculateDependencies() {
    -    // @todo When \Drupal\Core\Config\Entity\EntityWithPluginBagInterface moves
    +    // @todo When \Drupal\Core\Config\Entity\EntityWithPluginCollectionInterface moves
         //   to a trait, switch to class_uses() instead.
    

    other comment blocks are re-wrapped, so wrapping this one also.

    and in 2 other places. see interdiff.

  2. just checking. this is fine.
    +++ b/core/tests/Drupal/Tests/Core/Plugin/DefaultSingleLazyPluginCollectionTest.php
    @@ -0,0 +1,57 @@
    + * Contains \Drupal\Tests\Core\Plugin\DefaultSingleLazyPluginCollectionTest.
    
    +++ /dev/null
    @@ -1,57 +0,0 @@
    - * Contains \Drupal\Tests\Core\Plugin\DefaultSinglePluginBagTest.
    

    new test? or a rename that didn't match enough?
    ah, I see, a move. ok.

  3. Question:

    core/modules/image/lib/Drupal/image/Entity/ImageStyle.php
    84: protected $effectsBag;
    350: if (!$this->effectsBag) {
    351: $this->effectsBag = new ImageEffectCollection(\Drupal::service('plugin.manager.image.effect'), $this->effects);
    352: $this->effectsBag->sort();
    354: return $this->effectsBag;

    These should have been renamed also?

dawehner’s picture

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

Is this still on the table? We use Bag and Collection in various places, but I really like the "Lazy"-ness here, as it tells you more what this is actually about.

mfernea’s picture

Issue tags: +Amsterdam2014

I'll try to do the reroll.

mfernea’s picture

It's a "little bit" too much for me. :)

cilefen’s picture

Status: Needs work » Needs review
StatusFileSize
new88.87 KB

Rerolled by hand because so much has changed.

yesct’s picture

Issue tags: -Needs reroll
yesct’s picture

reviewing this.

fabianx’s picture

Status: Needs review » Reviewed & tested by the community
Issue tags: +BC break

RTBC from my POV, but this is a BC break, so justifying that:

- PluginBag is not only a strange name, but this is _not_ a bag, but a collection, such it is a violation of Symfony standards, which we try to apply to and can be very misleading if people try to use it as a bag.

Therefore the rename is well worth it. It is also easy to do the same in contrib/ modules that might be broken by that change as it is mainly a simple string / replace.

So while the rename is very broad, it is simple to port as the overall API remains the same.

yesct’s picture

Issue summary: View changes
Status: Reviewed & tested by the community » Needs review

Started looking at this. As I got more and more into it, I wondered if 'beta target' was accurate. This seems like it might not be allowed in at this point.

discussed with xjm. based on where we are in the beta, the benefit here may not outweigh the disruption, and we need some maintainer feedback to clarify that. let's wait for input here, and also maybe a post about beta changes criteria generally.

But did finish looking through it... posting the nits (I would normally have just fixed them). Let's hold off actually fixing this stuff until we get feedback on doing it at all.

I put a note in the issue summary.

  1. +++ b/core/lib/Drupal/Core/Action/ActionCollection.php
    @@ -2,17 +2,17 @@
    -class ActionBag extends DefaultSinglePluginBag {
    +class ActionCollection extends DefaultSingleLazyPluginCollection {
    
    +++ b/core/lib/Drupal/Core/Block/BlockBase.php
    @@ -13,7 +13,7 @@
    -use Drupal\Core\Condition\ConditionPluginBag;
    +use Drupal\Core\Condition\ConditionPluginCollection;
    

    why is the rename of ConditionPluginBag not using the ..Lazy.. pattern like other rename?

  2. +++ b/core/lib/Drupal/Core/Config/Entity/ConfigEntityBase.php
    @@ -43,7 +43,7 @@
    -   * This is needed when the entity utilizes a PluginBag, to dictate where the
    +   * This is needed when the entity utilizes a LazyPluginCollection, to dictate where the
    

    this needs to be wrapped to 80 chars.

    but the previous patch in #4 did this...

    So I think there are some changes from #4 that might have been missed in this one... ?

  3. +++ b/core/lib/Drupal/Core/Entity/EntityWithPluginCollectionInterface.php
    @@ -2,27 +2,27 @@
    -   * Returns the plugin bags used by this entity.
    +   * Returns the plugin collectionss used by this entity.
    

    typo in collectionss

  4. +++ b/core/modules/editor/src/Entity/Editor.php
    @@ -102,7 +102,7 @@ public function calculateDependencies() {
    -    // @todo use EntityWithPluginBagsInterface so configuration between config
    +    // @todo use EntityWithPluginCollectionInterface so configuration between config
         //   entity and dependency on provider is managed automatically.
    

    this needs 80 char wrap also.

  5. +++ b/core/modules/filter/src/Plugin/FilterBase.php
    @@ -44,8 +44,6 @@
        * The weight of this filter compared to others in a filter collection.
        *
    -   * @see FilterBase::$filterBag
    -   *
        * @var int
    
    @@ -60,9 +58,9 @@
    -  protected $bag;
    +  protected $collection;
    

    I wonder why this change in this issue? why not @see FilterBase::$filterCollection ... maybe because there is no filterBag property anyway... so instead of search and replace, just taking out the wrong @see. OK.

    or... it was referring to FilterBase::$bag which is now $collection.

    Noting for now, for later thinking.

  6. +++ b/core/modules/system/core.api.php
    @@ -1155,19 +1155,19 @@
    - * A plugin bag is a class that extends \Drupal\Component\Plugin\PluginBag or
    + * A plugin collection is a class that extends \Drupal\Component\Plugin\LazyPluginCollection or
      * one of its subclasses; there are several examples in Drupal Core. If your
    

    needs 80 char wrap again.

  7. +++ b/core/modules/views_ui/src/Tests/DisplayFeedTest.php
    @@ -49,7 +49,7 @@ protected function checkFeedViewUi($view_name) {
    -    // check whether a DisplayBag was returned in iterating over all displays.
    +    // check whether a DisplayCollection was returned in iterating over all displays.
    

    80 chars.

Also, xjm reminded me, that git diff --colorwords is helpful in situations like these.

pwolanin’s picture

I think the naming currently is a total Drupal WTF, so I think this renaming would be a big DX win

fabianx’s picture

Assigned: Unassigned » alexpott
Status: Needs review » Reviewed & tested by the community

If we want core committer feedback, RTBC is the status to use.

@Core committers - Just some nits left.

Trying with alexpott for now.

Can we get approval / disproval of this issue before fixing them?

catch’s picture

This is a tricky one for beta criteria, my personal opinion, not a 'decision' yet - let's see what others think.

1. The name is misleading rather than not ideal - i.e. there's tangible benefit in it expressing what it is, whereas it currently expresses what it's not.

On a hierarchy of renames: Accuracy > Precision > Aesthetics.

2. Not saying we should, but presumably the old class could be left in, unused, subclassing, with the old name for bc?

3. This was RTBC during DrupalCon Amsterdam, which #2350615: [policy, no patch] What changes can be accepted during the Drupal 8 beta phase? has a section that would allow a little more leeway to those specific patches during the next 3.5 weeks, but that's not been discussed with Dries or webchick yet (was only posted 36 hours ago). Even if we do that, we could still decide the change isn't worth it, but it does mean it's OK to specifically ask for committer feedback here. Leaving assigned to Alex.

alexpott’s picture

Status: Reviewed & tested by the community » Needs work

I'm okay with going forward with this under the "Amsterdam exception" rules.

So now to fix up the nits that @Fabianx refers to in #14

Also lets have a change record for the issue to help people.

cilefen’s picture

Issue summary: View changes

I started the draft change record: https://www.drupal.org/node/2352673

cilefen’s picture

Issue summary: View changes
cilefen’s picture

Status: Needs work » Needs review
StatusFileSize
new8.66 KB
new89.47 KB
dawehner’s picture

+1 for naming it lazy, because it tells you what happens. Yes, you could argue that this is an internal detail,
but on the other hand, people might realize what it is good for.

cilefen’s picture

There are other classes renamed with suffix "Bag" that may be wrong in the current patch:

  • ActionBag to ActionCollection, maybe it should be ActionLazyPluginCollection
  • BlockPluginCollection should be BlockLazyPluginCollection?
  • Etc ... there are more

Should those be renamed that way?

mpdonadio’s picture

StatusFileSize
new89.47 KB
new866 bytes

Fixed a bad wrap on a @todo.

Generated with `git diff -M10% --minimal 8.0.x`

alexpott’s picture

Assigned: alexpott » Unassigned
wim leers’s picture

I discovered this through the change record draft (which again appeared in the feed of *published* change records, and therefore is broken again…).

This name is so much better, together with reading the change record I now *finally* fully understand what this "PluginBag" thing is about!

yesct’s picture

Issue tags: -Needs change record

@Wim Leers I went to make a comment on #2337375: Feed showing draft change records
but I could not see this draft record in
https://www.drupal.org/list-changes/drupal
or the rss feed, or the twitter feed for @drupal8changes

any thoughts on #21 ? Should we carry through the lazy wording on more class names?

taking off the needs change record tag since we have a draft and it looked good to @Wim Leers

wim leers’s picture

cilefen’s picture

StatusFileSize
new89.45 KB

Reroll.

cilefen’s picture

Regarding #21, I think we should not include Lazy in the names of the classes that extend LazyPluginCollection, except for DefaultLazyPluginCollection DefaultSingleLazyPluginCollection.

ActionBag should probably be renamed to ActionPluginCollection and similarly for the rest.

yesct’s picture

@cilefen ok. since lazy can be argued to be an implementation detail, that seems ok to me. (and I can't get a strong response from others.)

yesct’s picture

Status: Needs review » Needs work

needs work to do #28

cilefen’s picture

Issue summary: View changes
cilefen’s picture

Status: Needs work » Needs review
StatusFileSize
new88.67 KB

Rerolled because of a comment change in #2235363: Document config dependencies.

mpdonadio’s picture

Assigned: Unassigned » mpdonadio
Status: Needs review » Needs work

For reference (and before I lose this), here are two class hierarchies in question:

LazyPluginCollection
-- DefaultLazyPluginCollection
---- ConditionLazyPluginCollection
---- FilterCollection
---- ImageEffectCollection
---- TipsCollection
---- DisplayCollection
-- DefaultSingleLazyPluginCollection
---- ActionCollection
---- BlockPluginCollection
---- SearchPluginCollection
-- TestLazyPluginCollection

LazyPluginCollectionTestBase
-- ConfigurablePluginCollectionTest
-- DefaultLazyPluginCollectionTest
-- DefaultSingleLazyPluginCollectionTest

I am going to remove Lazy from ConditionLazyPluginCollection, and change to FooPluginCollection for the other leaf classes.

mpdonadio’s picture

Assigned: mpdonadio » Unassigned
Status: Needs work » Needs review
StatusFileSize
new40.2 KB
new149.67 KB
new93.69 KB

OK, renamed classes via refactor tools in PHPStorm. The new hierarchy is shown in the image.

cilefen’s picture

@mpdonadio: this patch will be smaller and easier to read if you make it with git diff -M10% --minimal

Status: Needs review » Needs work

The last submitted patch, 34: rename_pluginbag_to-2246647-34.patch, failed testing.

mpdonadio’s picture

Status: Needs work » Needs review
StatusFileSize
new88.92 KB
new18.43 KB

Minimal patch.

Status: Needs review » Needs work

The last submitted patch, 37: interdiff-32-36.patch, failed testing.

The last submitted patch, 37: rename_pluginbag_to-2246647-36.patch, failed testing.

mpdonadio’s picture

Status: Needs work » Needs review
StatusFileSize
new20.32 KB
new88.94 KB

I missed two classes uses as strings for test mocks. Fixed those and they pass locally, along with a comment that was too long.

yesct’s picture

Issue summary: View changes

added a before and after hierarchy to the summary.

yesct’s picture

Issue summary: View changes
Status: Needs review » Reviewed & tested by the community

updated the change record with the rename details.

useful for reviewing:
on both head and with the patch
ag --ignore-case " bag" core/lib/* core/modules/*
ag --ignore-case "bag " core/lib/* core/modules/*
ag --ignore-case "pluginbag" core/lib/* core/modules/*

with the patch applied, useful for reviewing:
git diff --color-words -M10% --minimal 8.0.x

--
added to the summary
EntityWithPluginBagsInterface -> EntityWithPluginCollectionInterface
ConfigEntityBaseWithPluginBags -> ConfigEntityBaseWithPluginCollections
SearchPluginBagTest -> SearchPluginCollectionTest

and updated the change record again.

I read through the whole patch again. Looks ok to me.

mpdonadio’s picture

Should we make the class names fully qualified in the Change Record?

alexpott’s picture

Status: Reviewed & tested by the community » Fixed

Committed 22c8258 and pushed to 8.0.x. Thanks!

I think fully qualified classnames will make the CR harder to read.

  • alexpott committed 22c8258 on 8.0.x
    Issue #2246647 by mpdonadio, cilefen, YesCT, tim.plunkett: Rename...

Status: Fixed » Closed (fixed)

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