Commit 22c82583 authored by alexpott's avatar alexpott

Issue #2246647 by mpdonadio, cilefen, YesCT, tim.plunkett: Rename PluginBag to...

Issue #2246647 by mpdonadio, cilefen, YesCT, tim.plunkett: Rename PluginBag to LazyPluginCollection.
parent 7eaeebc5
......@@ -2,7 +2,7 @@
/**
* @file
* Contains \Drupal\Component\Plugin\PluginBag.
* Contains \Drupal\Component\Plugin\LazyPluginCollection.
*/
namespace Drupal\Component\Plugin;
......@@ -12,7 +12,7 @@
*
* @ingroup plugin_api
*/
abstract class PluginBag implements \Iterator, \Countable {
abstract class LazyPluginCollection implements \Iterator, \Countable {
/**
* Stores all instantiated plugins.
......@@ -37,7 +37,7 @@ abstract class PluginBag implements \Iterator, \Countable {
abstract protected function initializePlugin($instance_id);
/**
* Returns the current configuration of all plugins in this bag.
* Returns the current configuration of all plugins in this collection.
*
* @return array
* An array of up-to-date plugin configuration.
......@@ -45,7 +45,7 @@ abstract class PluginBag implements \Iterator, \Countable {
abstract public function getConfiguration();
/**
* Sets the configuration for all plugins in this bag.
* Sets the configuration for all plugins in this collection.
*
* @param array $configuration
* An array of up-to-date plugin configuration.
......
......@@ -2,17 +2,17 @@
/**
* @file
* Contains \Drupal\Core\Action\ActionBag.
* Contains \Drupal\Core\Action\ActionPluginCollection.
*/
namespace Drupal\Core\Action;
use Drupal\Core\Plugin\DefaultSinglePluginBag;
use Drupal\Core\Plugin\DefaultSingleLazyPluginCollection;
/**
* Provides a container for lazily loading Action plugins.
*/
class ActionBag extends DefaultSinglePluginBag {
class ActionPluginCollection extends DefaultSingleLazyPluginCollection {
/**
* {@inheritdoc}
......
......@@ -13,7 +13,7 @@
use Drupal\Component\Plugin\ContextAwarePluginInterface;
use Drupal\Core\Access\AccessResult;
use Drupal\Core\Condition\ConditionAccessResolverTrait;
use Drupal\Core\Condition\ConditionPluginBag;
use Drupal\Core\Condition\ConditionPluginCollection;
use Drupal\Core\Form\FormState;
use Drupal\Core\Form\FormStateInterface;
use Drupal\Core\Plugin\ContextAwarePluginBase;
......@@ -38,11 +38,11 @@ abstract class BlockBase extends ContextAwarePluginBase implements BlockPluginIn
use ConditionAccessResolverTrait;
/**
* The condition plugin bag.
* The condition plugin collection.
*
* @var \Drupal\Core\Condition\ConditionPluginBag
* @var \Drupal\Core\Condition\ConditionPluginCollection
*/
protected $conditionBag;
protected $conditionCollection;
/**
* The condition plugin manager.
......@@ -507,10 +507,10 @@ public function isCacheable() {
* {@inheritdoc}
*/
public function getVisibilityConditions() {
if (!isset($this->conditionBag)) {
$this->conditionBag = new ConditionPluginBag($this->conditionPluginManager(), $this->configuration['visibility']);
if (!isset($this->conditionCollection)) {
$this->conditionCollection = new ConditionPluginCollection($this->conditionPluginManager(), $this->configuration['visibility']);
}
return $this->conditionBag;
return $this->conditionCollection;
}
/**
......
......@@ -146,8 +146,8 @@ public function getMachineNameSuggestion();
/**
* Gets conditions for this block.
*
* @return \Drupal\Core\Condition\ConditionInterface[]|\Drupal\Core\Condition\ConditionPluginBag
* An array or bag of configured condition plugins.
* @return \Drupal\Core\Condition\ConditionInterface[]|\Drupal\Core\Condition\ConditionPluginCollection
* An array or collection of configured condition plugins.
*/
public function getVisibilityConditions();
......
......@@ -2,18 +2,18 @@
/**
* @file
* Contains \Drupal\Core\Condition\ConditionPluginBag.
* Contains \Drupal\Core\Condition\ConditionPluginCollection.
*/
namespace Drupal\Core\Condition;
use Drupal\Component\Plugin\Context\ContextInterface;
use Drupal\Core\Plugin\DefaultPluginBag;
use Drupal\Core\Plugin\DefaultLazyPluginCollection;
/**
* Provides a collection of condition plugins.
*/
class ConditionPluginBag extends DefaultPluginBag {
class ConditionPluginCollection extends DefaultLazyPluginCollection {
/**
* An array of collected contexts for conditions.
......
......@@ -14,7 +14,7 @@
use Drupal\Core\Entity\Entity;
use Drupal\Core\Config\ConfigDuplicateUUIDException;
use Drupal\Core\Entity\EntityStorageInterface;
use Drupal\Core\Entity\EntityWithPluginBagsInterface;
use Drupal\Core\Entity\EntityWithPluginCollectionInterface;
use Drupal\Core\Language\LanguageInterface;
use Drupal\Core\Plugin\PluginDependencyTrait;
......@@ -43,8 +43,8 @@ abstract class ConfigEntityBase extends Entity implements ConfigEntityInterface
/**
* The name of the property that is used to store plugin configuration.
*
* This is needed when the entity utilizes a PluginBag, to dictate where the
* plugin configuration should be stored.
* This is needed when the entity utilizes a LazyPluginCollection, to dictate
* where the plugin configuration should be stored.
*
* @var string
*/
......@@ -138,11 +138,11 @@ public function get($property_name) {
* {@inheritdoc}
*/
public function set($property_name, $value) {
if ($this instanceof EntityWithPluginBagsInterface) {
$plugin_bags = $this->getPluginBags();
if (isset($plugin_bags[$property_name])) {
if ($this instanceof EntityWithPluginCollectionInterface) {
$plugin_collections = $this->getPluginCollections();
if (isset($plugin_collections[$property_name])) {
// If external code updates the settings, pass it along to the plugin.
$plugin_bags[$property_name]->setConfiguration($value);
$plugin_collections[$property_name]->setConfiguration($value);
}
}
......@@ -276,11 +276,11 @@ protected function getTypedConfig() {
public function preSave(EntityStorageInterface $storage) {
parent::preSave($storage);
if ($this instanceof EntityWithPluginBagsInterface) {
if ($this instanceof EntityWithPluginCollectionInterface) {
// Any changes to the plugin configuration must be saved to the entity's
// copy as well.
foreach ($this->getPluginBags() as $plugin_config_key => $plugin_bag) {
$this->set($plugin_config_key, $plugin_bag->getConfiguration());
foreach ($this->getPluginCollections() as $plugin_config_key => $plugin_collection) {
$this->set($plugin_config_key, $plugin_collection->getConfiguration());
}
}
......@@ -317,11 +317,11 @@ public function calculateDependencies() {
// Dependencies should be recalculated on every save. This ensures stale
// dependencies are never saved.
$this->dependencies = array();
if ($this instanceof EntityWithPluginBagsInterface) {
if ($this instanceof EntityWithPluginCollectionInterface) {
// Configuration entities need to depend on the providers of any plugins
// that they store the configuration for.
foreach ($this->getPluginBags() as $plugin_bag) {
foreach ($plugin_bag as $instance) {
foreach ($this->getPluginCollections() as $plugin_collection) {
foreach ($plugin_collection as $instance) {
$this->calculatePluginDependencies($instance);
}
}
......
<?php
/**
* @file
* Contains \Drupal\Core\Entity\EntityWithPluginBagsInterface.
*/
namespace Drupal\Core\Entity;
/**
* Provides an interface for an object utilizing a plugin bag.
*
* @see \Drupal\Component\Plugin\PluginBag
*
* @ingroup plugin_api
*/
interface EntityWithPluginBagsInterface extends EntityInterface {
/**
* Returns the plugin bags used by this entity.
*
* @return \Drupal\Component\Plugin\PluginBag[]
* An array of plugin bags, keyed by the property name they use to store
* their configuration.
*/
public function getPluginBags();
}
<?php
/**
* @file
* Contains \Drupal\Core\Entity\EntityWithPluginCollectionInterface.
*/
namespace Drupal\Core\Entity;
/**
* Provides an interface for an object utilizing a plugin collection.
*
* @see \Drupal\Component\Plugin\LazyPluginCollection
*
* @ingroup plugin_api
*/
interface EntityWithPluginCollectionInterface extends EntityInterface {
/**
* Returns the plugin collections used by this entity.
*
* @return \Drupal\Component\Plugin\LazyPluginCollection[]
* An array of plugin collections, keyed by the property name they use to
* store their configuration.
*/
public function getPluginCollections();
}
......@@ -2,24 +2,25 @@
/**
* @file
* Contains \Drupal\Core\Plugin\DefaultPluginBag.
* Contains \Drupal\Core\Plugin\DefaultLazyPluginCollection.
*/
namespace Drupal\Core\Plugin;
use Drupal\Component\Plugin\Exception\PluginNotFoundException;
use Drupal\Component\Plugin\PluginBag;
use Drupal\Component\Plugin\LazyPluginCollection;
use Drupal\Component\Plugin\PluginManagerInterface;
use Drupal\Component\Plugin\ConfigurablePluginInterface;
/**
* Provides a default plugin bag for a plugin type.
* Provides a default plugin collection for a plugin type.
*
* A plugin bag is used to contain plugins that will be lazily instantiated. The
* configurations of each potential plugin are passed in, and the configuration
* key containing the plugin ID is specified by self::$pluginKey.
* A plugin collection is used to contain plugins that will be lazily
* instantiated. The configurations of each potential plugin are passed in, and
* the configuration key containing the plugin ID is specified by
* self::$pluginKey.
*/
class DefaultPluginBag extends PluginBag {
class DefaultLazyPluginCollection extends LazyPluginCollection {
/**
* The manager used to instantiate the plugins.
......@@ -29,11 +30,11 @@ class DefaultPluginBag extends PluginBag {
protected $manager;
/**
* The initial configuration for each plugin in the bag.
* The initial configuration for each plugin in the collection.
*
* @var array
* An associative array containing the initial configuration for each plugin
* in the bag, keyed by plugin instance ID.
* in the collection, keyed by plugin instance ID.
*/
protected $configurations = array();
......@@ -52,13 +53,13 @@ class DefaultPluginBag extends PluginBag {
protected $originalOrder = array();
/**
* Constructs a new DefaultPluginBag object.
* Constructs a new DefaultLazyPluginCollection object.
*
* @param \Drupal\Component\Plugin\PluginManagerInterface $manager
* The manager to be used for instantiating plugins.
* @param array $configurations
* (optional) An associative array containing the initial configuration for
* each plugin in the bag, keyed by plugin instance ID.
* each plugin in the collection, keyed by plugin instance ID.
*/
public function __construct(PluginManagerInterface $manager, array $configurations = array()) {
$this->manager = $manager;
......@@ -84,7 +85,7 @@ protected function initializePlugin($instance_id) {
}
/**
* Sorts all plugin instances in this bag.
* Sorts all plugin instances in this collection.
*
* @return $this
*/
......
......@@ -2,25 +2,25 @@
/**
* @file
* Contains \Drupal\Core\Plugin\DefaultSinglePluginBag.
* Contains \Drupal\Core\Plugin\DefaultSingleLazyPluginCollection.
*/
namespace Drupal\Core\Plugin;
use Drupal\Component\Plugin\PluginManagerInterface;
use Drupal\Component\Plugin\PluginBag;
use Drupal\Component\Plugin\LazyPluginCollection;
use Drupal\Component\Plugin\ConfigurablePluginInterface;
/**
* Provides a default plugin bag for a plugin type.
* Provides a default plugin collection for a plugin type.
*
* A plugin bag usually stores multiple plugins, and is used to lazily
* A plugin collection usually stores multiple plugins, and is used to lazily
* instantiate them. When only one plugin is needed, it is still best practice
* to encapsulate all of the instantiation logic in a plugin bag. This class can
* be used directly, or subclassed to add further exception handling in
* self::initializePlugin().
* to encapsulate all of the instantiation logic in a plugin collection. This
* class can be used directly, or subclassed to add further exception handling
* in self::initializePlugin().
*/
class DefaultSinglePluginBag extends PluginBag {
class DefaultSingleLazyPluginCollection extends LazyPluginCollection {
/**
* The manager used to instantiate the plugins.
......@@ -37,14 +37,14 @@ class DefaultSinglePluginBag extends PluginBag {
protected $configuration;
/**
* The instance ID used for this plugin bag.
* The instance ID used for this plugin collection.
*
* @var string
*/
protected $instanceId;
/**
* Constructs a new DefaultSinglePluginBag object.
* Constructs a new DefaultSingleLazyPluginCollection object.
*
* @param \Drupal\Component\Plugin\PluginManagerInterface $manager
* The manager to be used for instantiating plugins.
......@@ -56,7 +56,7 @@ class DefaultSinglePluginBag extends PluginBag {
public function __construct(PluginManagerInterface $manager, $instance_id, array $configuration) {
$this->manager = $manager;
$this->instanceId = $instance_id;
// This is still needed by the parent PluginBag class.
// This is still needed by the parent LazyPluginCollection class.
$this->instanceIDs = array($instance_id => $instance_id);
$this->configuration = $configuration;
}
......
......@@ -2,7 +2,7 @@
/**
* @file
* Contains \Drupal\block\BlockPluginBag.
* Contains \Drupal\block\BlockPluginCollection.
*/
namespace Drupal\block;
......@@ -10,22 +10,22 @@
use Drupal\Component\Plugin\Exception\PluginException;
use Drupal\Component\Plugin\PluginManagerInterface;
use Drupal\Component\Utility\String;
use Drupal\Core\Plugin\DefaultSinglePluginBag;
use Drupal\Core\Plugin\DefaultSingleLazyPluginCollection;
/**
* Provides a collection of block plugins.
*/
class BlockPluginBag extends DefaultSinglePluginBag {
class BlockPluginCollection extends DefaultSingleLazyPluginCollection {
/**
* The block ID this plugin bag belongs to.
* The block ID this plugin collection belongs to.
*
* @var string
*/
protected $blockId;
/**
* Constructs a new BlockPluginBag.
* Constructs a new BlockPluginCollection.
*
* @param \Drupal\Component\Plugin\PluginManagerInterface $manager
* The manager to be used for instantiating plugins.
......
......@@ -9,10 +9,10 @@
use Drupal\Core\Cache\Cache;
use Drupal\Core\Config\Entity\ConfigEntityBase;
use Drupal\block\BlockPluginBag;
use Drupal\block\BlockPluginCollection;
use Drupal\block\BlockInterface;
use Drupal\Core\Config\Entity\ConfigEntityInterface;
use Drupal\Core\Entity\EntityWithPluginBagsInterface;
use Drupal\Core\Entity\EntityWithPluginCollectionInterface;
use Drupal\Core\Entity\EntityStorageInterface;
/**
......@@ -40,7 +40,7 @@
* }
* )
*/
class Block extends ConfigEntityBase implements BlockInterface, EntityWithPluginBagsInterface {
class Block extends ConfigEntityBase implements BlockInterface, EntityWithPluginCollectionInterface {
/**
* The ID of the block.
......@@ -78,37 +78,37 @@ class Block extends ConfigEntityBase implements BlockInterface, EntityWithPlugin
protected $plugin;
/**
* The plugin bag that holds the block plugin for this entity.
* The plugin collection that holds the block plugin for this entity.
*
* @var \Drupal\block\BlockPluginBag
* @var \Drupal\block\BlockPluginCollection
*/
protected $pluginBag;
protected $pluginCollection;
/**
* {@inheritdoc}
*/
public function getPlugin() {
return $this->getPluginBag()->get($this->plugin);
return $this->getPluginCollection()->get($this->plugin);
}
/**
* Encapsulates the creation of the block's PluginBag.
* Encapsulates the creation of the block's LazyPluginCollection.
*
* @return \Drupal\Component\Plugin\PluginBag
* The block's plugin bag.
* @return \Drupal\Component\Plugin\LazyPluginCollection
* The block's plugin collection.
*/
protected function getPluginBag() {
if (!$this->pluginBag) {
$this->pluginBag = new BlockPluginBag(\Drupal::service('plugin.manager.block'), $this->plugin, $this->get('settings'), $this->id());
protected function getPluginCollection() {
if (!$this->pluginCollection) {
$this->pluginCollection = new BlockPluginCollection(\Drupal::service('plugin.manager.block'), $this->plugin, $this->get('settings'), $this->id());
}
return $this->pluginBag;
return $this->pluginCollection;
}
/**
* {@inheritdoc}
*/
public function getPluginBags() {
return array('settings' => $this->getPluginBag());
public function getPluginCollections() {
return array('settings' => $this->getPluginCollection());
}
/**
......
......@@ -7,7 +7,7 @@
namespace Drupal\block\Event;
use Drupal\Core\Condition\ConditionPluginBag;
use Drupal\Core\Condition\ConditionPluginCollection;
use Symfony\Component\EventDispatcher\Event;
/**
......@@ -18,14 +18,14 @@
class BlockConditionContextEvent extends Event {
/**
* @var \Drupal\Core\Condition\ConditionPluginBag
* @var \Drupal\Core\Condition\ConditionPluginCollection
*/
protected $conditions;
/**
* @param \Drupal\Core\Condition\ConditionPluginBag $conditions
* @param \Drupal\Core\Condition\ConditionPluginCollection $conditions
*/
public function __construct(ConditionPluginBag $conditions) {
public function __construct(ConditionPluginCollection $conditions) {
$this->conditions = $conditions;
}
......
......@@ -18,7 +18,7 @@
abstract class BlockConditionContextSubscriberBase implements EventSubscriberInterface {
/**
* @var \Drupal\Core\Condition\ConditionPluginBag
* @var \Drupal\Core\Condition\ConditionPluginCollection
*/
protected $conditions;
......
......@@ -75,30 +75,30 @@ protected function setUp() {
*/
public function testCalculateDependencies() {
$values = array('theme' => 'stark');
// Mock the entity under test so that we can mock getPluginBags().
// Mock the entity under test so that we can mock getPluginCollections().
$entity = $this->getMockBuilder('\Drupal\block\Entity\Block')
->setConstructorArgs(array($values, $this->entityTypeId))
->setMethods(array('getPluginBags'))
->setMethods(array('getPluginCollections'))
->getMock();
// Create a configurable plugin that would add a dependency.
$instance_id = $this->randomMachineName();
$instance = new TestConfigurablePlugin(array(), $instance_id, array('provider' => 'test'));
// Create a plugin bag to contain the instance.
$plugin_bag = $this->getMockBuilder('\Drupal\Core\Plugin\DefaultPluginBag')
// Create a plugin collection to contain the instance.
$plugin_collection = $this->getMockBuilder('\Drupal\Core\Plugin\DefaultLazyPluginCollection')
->disableOriginalConstructor()
->setMethods(array('get'))
->getMock();
$plugin_bag->expects($this->atLeastOnce())
$plugin_collection->expects($this->atLeastOnce())
->method('get')
->with($instance_id)
->will($this->returnValue($instance));
$plugin_bag->addInstanceId($instance_id);
$plugin_collection->addInstanceId($instance_id);
// Return the mocked plugin bag.
// Return the mocked plugin collection.
$entity->expects($this->once())
->method('getPluginBags')
->will($this->returnValue(array($plugin_bag)));
->method('getPluginCollections')
->will($this->returnValue(array($plugin_collection)));
$dependencies = $entity->calculateDependencies();
$this->assertContains('test', $dependencies['module']);
......
......@@ -102,8 +102,8 @@ public function calculateDependencies() {
parent::calculateDependencies();
// Create a dependency on the associated FilterFormat.
$this->addDependency('entity', $this->getFilterFormat()->getConfigDependencyName());
// @todo use EntityWithPluginBagsInterface so configuration between config
// entity and dependency on provider is managed automatically.
// @todo use EntityWithPluginCollectionInterface so configuration between
// config entity and dependency on provider is managed automatically.
$definition = $this->editorPluginManager()->createInstance($this->editor)->getPluginDefinition();
$this->addDependency('module', $definition['provider']);
return $this->dependencies;
......
......@@ -9,7 +9,7 @@
use Drupal\Core\Cache\Cache;
use Drupal\simpletest\KernelTestBase;
use Drupal\filter\FilterBag;
use Drupal\filter\FilterPluginCollection;
/**
* Tests Editor module's file reference filter.
......@@ -40,7 +40,7 @@ protected function setUp() {
$this->installSchema('file', array('file_usage'));
$manager = $this->container->get('plugin.manager.filter');
$bag = new FilterBag($manager, array());
$bag = new FilterPluginCollection($manager, array());
$this->filters = $bag->getAll();
}
......
......@@ -8,10 +8,10 @@
namespace Drupal\filter\Entity;
use Drupal\Core\Config\Entity\ConfigEntityBase;
use Drupal\Core\Entity\EntityWithPluginBagsInterface;
use Drupal\Core\Entity\EntityWithPluginCollectionInterface;
use Drupal\Core\Entity\EntityStorageInterface;
use Drupal\filter\FilterFormatInterface;
use Drupal\filter\FilterBag;
use Drupal\filter\FilterPluginCollection;
use Drupal\filter\Plugin\FilterInterface;
/**
......@@ -43,7 +43,7 @@
* }
* )
*/
class FilterFormat extends ConfigEntityBase implements FilterFormatInterface, EntityWithPluginBagsInterface {
class FilterFormat extends ConfigEntityBase implements FilterFormatInterface, EntityWithPluginCollectionInterface {
/**
* Unique machine name of the format.
......@@ -114,9 +114,9 @@ class FilterFormat extends ConfigEntityBase implements FilterFormatInterface, En
/**
* Holds the collection of filters that are attached to this format.
*
* @var \Drupal\filter\FilterBag
* @var \Drupal\filter\FilterPluginCollection
*/
protected $filterBag;
protected $filterCollection;
/**
* {@inheritdoc}
......@@ -129,20 +129,20 @@ public function id() {
* {@inheritdoc}
*/
public function filters($instance_id = NULL) {
if (!isset($this->filterBag)) {
$this->filterBag = new FilterBag(\Drupal::service('plugin.manager.filter'), $this->filters);
$this->filterBag->sort();
if (!isset($this->filterCollection)) {
$this->filterCollection = new FilterPluginCollection(\Drupal::service('plugin.manager.filter'), $this->filters);
$this->filterCollection->sort();
}
if (isset($instance_id)) {
return $this->filterBag->get($instance_id);
return $this->filterCollection->get($instance_id);
}
return $this->filterBag;
return $this->filterCollection;
}
/**
* {@inheritdoc}
*/
public function getPluginBags() {
public function getPluginCollections() {
return array('filters' => $this->filters());
}
......@@ -151,8 +151,8 @@ public function getPluginBags() {
*/
public function setFilterConfig($instance_id, array $configuration) {
$this->filters[$instance_id] = $configuration;
if (isset($this->filterBag)) {
$this->filterBag->setInstanceConfiguration($instance_id, $configuration);
if (isset($this->filterCollection)) {
$this->filterCollection->setInstanceConfiguration($instance_id, $configuration);
}
return $this;
}
......
......@@ -20,8 +20,8 @@ interface FilterFormatInterface extends ConfigEntityInterface {
* @param string $instance_id
* (optional) The ID of a filter plugin instance to return.
*
* @return \Drupal\filter\FilterBag|\Drupal\filter\Plugin\FilterInterface
* Either the filter bag or a specific filter plugin instance.
* @return \Drupal\filter\FilterPluginCollection|\Drupal\filter\Plugin\FilterInterface
* Either the filter collection or a specific filter plugin instance.
*/
public function filters($instance_id = NULL);
......@@ -30,7 +30,7 @@ public function filters($instance_id = NULL);
*
* Sets or replaces the configuration of a filter plugin in $this->filters,
* and if instantiated already, also ensures that the actual filter plugin on
* the FilterBag contains the identical configuration.
* the FilterPluginCollection contains the identical configuration.
*
* @param string $instance_id
* The ID of a filter plugin to set the configuration for.
......
......@@ -2,18 +2,18 @@
/**
* @file
* Contains \Drupal\filter\FilterBag.
* Contains \Drupal\filter\FilterPluginCollection.
*/
namespace Drupal\filter;
use Drupal\Component\Utility\NestedArray;
use Drupal\Core\Plugin\DefaultPluginBag;
use Drupal\Core\Plugin\DefaultLazyPluginCollection;
/**
* A collection of filters.
*/
class FilterBag extends DefaultPluginBag {