Issue #2267329 by tim.plunkett | joachim: Move EntityWithPluginBagInterface out of Drupal\Core\Config\Entity and make it useful for more than one bag.
parent
fa17d471ff
commit
85f243e204
|
@ -35,7 +35,7 @@ use Drupal\Component\Utility\SortArray;
|
||||||
* \Drupal\Core\Config\Entity\ConfigEntityBase::calculateDependencies() which
|
* \Drupal\Core\Config\Entity\ConfigEntityBase::calculateDependencies() which
|
||||||
* resets the dependencies and provides an implementation to determine the
|
* resets the dependencies and provides an implementation to determine the
|
||||||
* plugin providers for configuration entities that implement
|
* plugin providers for configuration entities that implement
|
||||||
* \Drupal\Core\Config\Entity\EntityWithPluginBagInterface.
|
* \Drupal\Core\Entity\EntityWithPluginBagsInterface.
|
||||||
*
|
*
|
||||||
* The configuration manager service provides methods to find dependencies for
|
* The configuration manager service provides methods to find dependencies for
|
||||||
* a specified module, theme or configuration entity.
|
* a specified module, theme or configuration entity.
|
||||||
|
|
|
@ -13,6 +13,7 @@ use Drupal\Core\Cache\Cache;
|
||||||
use Drupal\Core\Entity\Entity;
|
use Drupal\Core\Entity\Entity;
|
||||||
use Drupal\Core\Config\ConfigDuplicateUUIDException;
|
use Drupal\Core\Config\ConfigDuplicateUUIDException;
|
||||||
use Drupal\Core\Entity\EntityStorageInterface;
|
use Drupal\Core\Entity\EntityStorageInterface;
|
||||||
|
use Drupal\Core\Entity\EntityWithPluginBagsInterface;
|
||||||
use Drupal\Core\Language\Language;
|
use Drupal\Core\Language\Language;
|
||||||
use Drupal\Core\Plugin\PluginDependencyTrait;
|
use Drupal\Core\Plugin\PluginDependencyTrait;
|
||||||
|
|
||||||
|
@ -136,10 +137,11 @@ abstract class ConfigEntityBase extends Entity implements ConfigEntityInterface
|
||||||
* {@inheritdoc}
|
* {@inheritdoc}
|
||||||
*/
|
*/
|
||||||
public function set($property_name, $value) {
|
public function set($property_name, $value) {
|
||||||
if ($this instanceof EntityWithPluginBagInterface) {
|
if ($this instanceof EntityWithPluginBagsInterface) {
|
||||||
if ($property_name == $this->pluginConfigKey) {
|
$plugin_bags = $this->getPluginBags();
|
||||||
|
if (isset($plugin_bags[$property_name])) {
|
||||||
// If external code updates the settings, pass it along to the plugin.
|
// If external code updates the settings, pass it along to the plugin.
|
||||||
$this->getPluginBag()->setConfiguration($value);
|
$plugin_bags[$property_name]->setConfiguration($value);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -257,11 +259,12 @@ abstract class ConfigEntityBase extends Entity implements ConfigEntityInterface
|
||||||
public function preSave(EntityStorageInterface $storage) {
|
public function preSave(EntityStorageInterface $storage) {
|
||||||
parent::preSave($storage);
|
parent::preSave($storage);
|
||||||
|
|
||||||
if ($this instanceof EntityWithPluginBagInterface) {
|
if ($this instanceof EntityWithPluginBagsInterface) {
|
||||||
// Any changes to the plugin configuration must be saved to the entity's
|
// Any changes to the plugin configuration must be saved to the entity's
|
||||||
// copy as well.
|
// copy as well.
|
||||||
$plugin_bag = $this->getPluginBag();
|
foreach ($this->getPluginBags() as $plugin_config_key => $plugin_bag) {
|
||||||
$this->set($this->pluginConfigKey, $plugin_bag->getConfiguration());
|
$this->set($plugin_config_key, $plugin_bag->getConfiguration());
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Ensure this entity's UUID does not exist with a different ID, regardless
|
// Ensure this entity's UUID does not exist with a different ID, regardless
|
||||||
|
@ -297,14 +300,13 @@ abstract class ConfigEntityBase extends Entity implements ConfigEntityInterface
|
||||||
// Dependencies should be recalculated on every save. This ensures stale
|
// Dependencies should be recalculated on every save. This ensures stale
|
||||||
// dependencies are never saved.
|
// dependencies are never saved.
|
||||||
$this->dependencies = array();
|
$this->dependencies = array();
|
||||||
// @todo When \Drupal\Core\Config\Entity\EntityWithPluginBagInterface moves
|
if ($this instanceof EntityWithPluginBagsInterface) {
|
||||||
// to a trait, switch to class_uses() instead.
|
|
||||||
if ($this instanceof EntityWithPluginBagInterface) {
|
|
||||||
// Configuration entities need to depend on the providers of any plugins
|
// Configuration entities need to depend on the providers of any plugins
|
||||||
// that they store the configuration for.
|
// that they store the configuration for.
|
||||||
$plugin_bag = $this->getPluginBag();
|
foreach ($this->getPluginBags() as $plugin_bag) {
|
||||||
foreach ($plugin_bag as $instance) {
|
foreach ($plugin_bag as $instance) {
|
||||||
$this->calculatePluginDependencies($instance);
|
$this->calculatePluginDependencies($instance);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return $this->dependencies;
|
return $this->dependencies;
|
||||||
|
|
|
@ -1,24 +0,0 @@
|
||||||
<?php
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @file
|
|
||||||
* Contains \Drupal\Core\Config\Entity\EntityWithPluginBagInterface.
|
|
||||||
*/
|
|
||||||
|
|
||||||
namespace Drupal\Core\Config\Entity;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Provides an interface for an object utilizing a plugin bag.
|
|
||||||
*
|
|
||||||
* @see \Drupal\Component\Plugin\PluginBag
|
|
||||||
*/
|
|
||||||
interface EntityWithPluginBagInterface extends ConfigEntityInterface {
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Returns the plugin bag used by this entity.
|
|
||||||
*
|
|
||||||
* @return \Drupal\Component\Plugin\PluginBag
|
|
||||||
*/
|
|
||||||
public function getPluginBag();
|
|
||||||
|
|
||||||
}
|
|
|
@ -0,0 +1,26 @@
|
||||||
|
<?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
|
||||||
|
*/
|
||||||
|
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();
|
||||||
|
|
||||||
|
}
|
|
@ -12,7 +12,7 @@ use Drupal\Core\Config\Entity\ConfigEntityBase;
|
||||||
use Drupal\block\BlockPluginBag;
|
use Drupal\block\BlockPluginBag;
|
||||||
use Drupal\block\BlockInterface;
|
use Drupal\block\BlockInterface;
|
||||||
use Drupal\Core\Config\Entity\ConfigEntityInterface;
|
use Drupal\Core\Config\Entity\ConfigEntityInterface;
|
||||||
use Drupal\Core\Config\Entity\EntityWithPluginBagInterface;
|
use Drupal\Core\Entity\EntityWithPluginBagsInterface;
|
||||||
use Drupal\Core\Entity\EntityStorageInterface;
|
use Drupal\Core\Entity\EntityStorageInterface;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -42,7 +42,7 @@ use Drupal\Core\Entity\EntityStorageInterface;
|
||||||
* }
|
* }
|
||||||
* )
|
* )
|
||||||
*/
|
*/
|
||||||
class Block extends ConfigEntityBase implements BlockInterface, EntityWithPluginBagInterface {
|
class Block extends ConfigEntityBase implements BlockInterface, EntityWithPluginBagsInterface {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The ID of the block.
|
* The ID of the block.
|
||||||
|
@ -86,11 +86,6 @@ class Block extends ConfigEntityBase implements BlockInterface, EntityWithPlugin
|
||||||
*/
|
*/
|
||||||
protected $pluginBag;
|
protected $pluginBag;
|
||||||
|
|
||||||
/**
|
|
||||||
* {@inheritdoc}
|
|
||||||
*/
|
|
||||||
protected $pluginConfigKey = 'settings';
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The visibility settings.
|
* The visibility settings.
|
||||||
*
|
*
|
||||||
|
@ -106,15 +101,25 @@ class Block extends ConfigEntityBase implements BlockInterface, EntityWithPlugin
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* {@inheritdoc}
|
* Encapsulates the creation of the block's PluginBag.
|
||||||
|
*
|
||||||
|
* @return \Drupal\Component\Plugin\PluginBag
|
||||||
|
* The block's plugin bag.
|
||||||
*/
|
*/
|
||||||
public function getPluginBag() {
|
protected function getPluginBag() {
|
||||||
if (!$this->pluginBag) {
|
if (!$this->pluginBag) {
|
||||||
$this->pluginBag = new BlockPluginBag(\Drupal::service('plugin.manager.block'), $this->plugin, $this->get('settings'), $this->id());
|
$this->pluginBag = new BlockPluginBag(\Drupal::service('plugin.manager.block'), $this->plugin, $this->get('settings'), $this->id());
|
||||||
}
|
}
|
||||||
return $this->pluginBag;
|
return $this->pluginBag;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* {@inheritdoc}
|
||||||
|
*/
|
||||||
|
public function getPluginBags() {
|
||||||
|
return array('settings' => $this->getPluginBag());
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Overrides \Drupal\Core\Entity\Entity::label();
|
* Overrides \Drupal\Core\Entity\Entity::label();
|
||||||
*/
|
*/
|
||||||
|
|
|
@ -88,10 +88,10 @@ class BlockConfigEntityUnitTest extends UnitTestCase {
|
||||||
*/
|
*/
|
||||||
public function testCalculateDependencies() {
|
public function testCalculateDependencies() {
|
||||||
$values = array('theme' => 'stark');
|
$values = array('theme' => 'stark');
|
||||||
// Mock the entity under test so that we can mock getPluginBag().
|
// Mock the entity under test so that we can mock getPluginBags().
|
||||||
$entity = $this->getMockBuilder('\Drupal\block\Entity\Block')
|
$entity = $this->getMockBuilder('\Drupal\block\Entity\Block')
|
||||||
->setConstructorArgs(array($values, $this->entityTypeId))
|
->setConstructorArgs(array($values, $this->entityTypeId))
|
||||||
->setMethods(array('getPluginBag'))
|
->setMethods(array('getPluginBags'))
|
||||||
->getMock();
|
->getMock();
|
||||||
// Create a configurable plugin that would add a dependency.
|
// Create a configurable plugin that would add a dependency.
|
||||||
$instance_id = $this->randomName();
|
$instance_id = $this->randomName();
|
||||||
|
@ -110,8 +110,8 @@ class BlockConfigEntityUnitTest extends UnitTestCase {
|
||||||
|
|
||||||
// Return the mocked plugin bag.
|
// Return the mocked plugin bag.
|
||||||
$entity->expects($this->once())
|
$entity->expects($this->once())
|
||||||
->method('getPluginBag')
|
->method('getPluginBags')
|
||||||
->will($this->returnValue($plugin_bag));
|
->will($this->returnValue(array($plugin_bag)));
|
||||||
|
|
||||||
$dependencies = $entity->calculateDependencies();
|
$dependencies = $entity->calculateDependencies();
|
||||||
$this->assertContains('test', $dependencies['module']);
|
$this->assertContains('test', $dependencies['module']);
|
||||||
|
|
|
@ -95,7 +95,7 @@ class Editor extends ConfigEntityBase implements EditorInterface {
|
||||||
parent::calculateDependencies();
|
parent::calculateDependencies();
|
||||||
// Create a dependency on the associated FilterFormat.
|
// Create a dependency on the associated FilterFormat.
|
||||||
$this->addDependency('entity', $this->getFilterFormat()->getConfigDependencyName());
|
$this->addDependency('entity', $this->getFilterFormat()->getConfigDependencyName());
|
||||||
// @todo use EntityWithPluginBagInterface so configuration between config
|
// @todo use EntityWithPluginBagsInterface so configuration between config
|
||||||
// entity and dependency on provider is managed automatically.
|
// entity and dependency on provider is managed automatically.
|
||||||
$definition = $this->editorPluginManager()->createInstance($this->editor)->getPluginDefinition();
|
$definition = $this->editorPluginManager()->createInstance($this->editor)->getPluginDefinition();
|
||||||
$this->addDependency('module', $definition['provider']);
|
$this->addDependency('module', $definition['provider']);
|
||||||
|
|
|
@ -8,7 +8,7 @@
|
||||||
namespace Drupal\filter\Entity;
|
namespace Drupal\filter\Entity;
|
||||||
|
|
||||||
use Drupal\Core\Config\Entity\ConfigEntityBase;
|
use Drupal\Core\Config\Entity\ConfigEntityBase;
|
||||||
use Drupal\Core\Config\Entity\EntityWithPluginBagInterface;
|
use Drupal\Core\Entity\EntityWithPluginBagsInterface;
|
||||||
use Drupal\Core\Entity\EntityStorageInterface;
|
use Drupal\Core\Entity\EntityStorageInterface;
|
||||||
use Drupal\filter\FilterFormatInterface;
|
use Drupal\filter\FilterFormatInterface;
|
||||||
use Drupal\filter\FilterBag;
|
use Drupal\filter\FilterBag;
|
||||||
|
@ -43,7 +43,7 @@ use Drupal\filter\Plugin\FilterInterface;
|
||||||
* }
|
* }
|
||||||
* )
|
* )
|
||||||
*/
|
*/
|
||||||
class FilterFormat extends ConfigEntityBase implements FilterFormatInterface, EntityWithPluginBagInterface {
|
class FilterFormat extends ConfigEntityBase implements FilterFormatInterface, EntityWithPluginBagsInterface {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Unique machine name of the format.
|
* Unique machine name of the format.
|
||||||
|
@ -125,11 +125,6 @@ class FilterFormat extends ConfigEntityBase implements FilterFormatInterface, En
|
||||||
*/
|
*/
|
||||||
protected $filterBag;
|
protected $filterBag;
|
||||||
|
|
||||||
/**
|
|
||||||
* {@inheritdoc}
|
|
||||||
*/
|
|
||||||
protected $pluginConfigKey = 'filters';
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* {@inheritdoc}
|
* {@inheritdoc}
|
||||||
*/
|
*/
|
||||||
|
@ -141,22 +136,21 @@ class FilterFormat extends ConfigEntityBase implements FilterFormatInterface, En
|
||||||
* {@inheritdoc}
|
* {@inheritdoc}
|
||||||
*/
|
*/
|
||||||
public function filters($instance_id = NULL) {
|
public function filters($instance_id = NULL) {
|
||||||
$filter_bag = $this->getPluginBag();
|
if (!isset($this->filterBag)) {
|
||||||
if (isset($instance_id)) {
|
$this->filterBag = new FilterBag(\Drupal::service('plugin.manager.filter'), $this->filters);
|
||||||
return $filter_bag->get($instance_id);
|
$this->filterBag->sort();
|
||||||
}
|
}
|
||||||
return $filter_bag;
|
if (isset($instance_id)) {
|
||||||
|
return $this->filterBag->get($instance_id);
|
||||||
|
}
|
||||||
|
return $this->filterBag;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* {@inheritdoc}
|
* {@inheritdoc}
|
||||||
*/
|
*/
|
||||||
public function getPluginBag() {
|
public function getPluginBags() {
|
||||||
if (!isset($this->filterBag)) {
|
return array('filters' => $this->filters());
|
||||||
$this->filterBag = new FilterBag(\Drupal::service('plugin.manager.filter'), $this->filters);
|
|
||||||
$this->filterBag->sort();
|
|
||||||
}
|
|
||||||
return $this->filterBag;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
@ -9,8 +9,8 @@ namespace Drupal\image\Entity;
|
||||||
|
|
||||||
use Drupal\Core\Cache\Cache;
|
use Drupal\Core\Cache\Cache;
|
||||||
use Drupal\Core\Config\Entity\ConfigEntityBase;
|
use Drupal\Core\Config\Entity\ConfigEntityBase;
|
||||||
use Drupal\Core\Config\Entity\EntityWithPluginBagInterface;
|
|
||||||
use Drupal\Core\Entity\EntityStorageInterface;
|
use Drupal\Core\Entity\EntityStorageInterface;
|
||||||
|
use Drupal\Core\Entity\EntityWithPluginBagsInterface;
|
||||||
use Drupal\Core\Routing\RequestHelper;
|
use Drupal\Core\Routing\RequestHelper;
|
||||||
use Drupal\image\ImageEffectBag;
|
use Drupal\image\ImageEffectBag;
|
||||||
use Drupal\image\ImageEffectInterface;
|
use Drupal\image\ImageEffectInterface;
|
||||||
|
@ -47,7 +47,7 @@ use Symfony\Component\DependencyInjection\Exception\ServiceNotFoundException;
|
||||||
* }
|
* }
|
||||||
* )
|
* )
|
||||||
*/
|
*/
|
||||||
class ImageStyle extends ConfigEntityBase implements ImageStyleInterface, EntityWithPluginBagInterface {
|
class ImageStyle extends ConfigEntityBase implements ImageStyleInterface, EntityWithPluginBagsInterface {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The name of the image style to use as replacement upon delete.
|
* The name of the image style to use as replacement upon delete.
|
||||||
|
@ -84,11 +84,6 @@ class ImageStyle extends ConfigEntityBase implements ImageStyleInterface, Entity
|
||||||
*/
|
*/
|
||||||
protected $effectsBag;
|
protected $effectsBag;
|
||||||
|
|
||||||
/**
|
|
||||||
* {@inheritdoc}
|
|
||||||
*/
|
|
||||||
protected $pluginConfigKey = 'effects';
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Overrides Drupal\Core\Entity\Entity::id().
|
* Overrides Drupal\Core\Entity\Entity::id().
|
||||||
*/
|
*/
|
||||||
|
@ -347,8 +342,8 @@ class ImageStyle extends ConfigEntityBase implements ImageStyleInterface, Entity
|
||||||
/**
|
/**
|
||||||
* {@inheritdoc}
|
* {@inheritdoc}
|
||||||
*/
|
*/
|
||||||
public function getPluginBag() {
|
public function getPluginBags() {
|
||||||
return $this->getEffects();
|
return array('effects' => $this->getEffects());
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
@ -9,9 +9,9 @@ namespace Drupal\search\Entity;
|
||||||
|
|
||||||
use Drupal\Core\Config\Entity\ConfigEntityBase;
|
use Drupal\Core\Config\Entity\ConfigEntityBase;
|
||||||
use Drupal\Core\Config\Entity\ConfigEntityInterface;
|
use Drupal\Core\Config\Entity\ConfigEntityInterface;
|
||||||
use Drupal\Core\Config\Entity\EntityWithPluginBagInterface;
|
|
||||||
use Drupal\Core\Entity\EntityStorageInterface;
|
use Drupal\Core\Entity\EntityStorageInterface;
|
||||||
use Drupal\Component\Plugin\ConfigurablePluginInterface;
|
use Drupal\Component\Plugin\ConfigurablePluginInterface;
|
||||||
|
use Drupal\Core\Entity\EntityWithPluginBagsInterface;
|
||||||
use Drupal\search\Plugin\SearchIndexingInterface;
|
use Drupal\search\Plugin\SearchIndexingInterface;
|
||||||
use Drupal\search\Plugin\SearchPluginBag;
|
use Drupal\search\Plugin\SearchPluginBag;
|
||||||
use Drupal\search\SearchPageInterface;
|
use Drupal\search\SearchPageInterface;
|
||||||
|
@ -50,7 +50,7 @@ use Drupal\search\SearchPageInterface;
|
||||||
* }
|
* }
|
||||||
* )
|
* )
|
||||||
*/
|
*/
|
||||||
class SearchPage extends ConfigEntityBase implements SearchPageInterface, EntityWithPluginBagInterface {
|
class SearchPage extends ConfigEntityBase implements SearchPageInterface, EntityWithPluginBagsInterface {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The name (plugin ID) of the search page entity.
|
* The name (plugin ID) of the search page entity.
|
||||||
|
@ -103,11 +103,6 @@ class SearchPage extends ConfigEntityBase implements SearchPageInterface, Entity
|
||||||
*/
|
*/
|
||||||
protected $pluginBag;
|
protected $pluginBag;
|
||||||
|
|
||||||
/**
|
|
||||||
* {@inheritdoc}
|
|
||||||
*/
|
|
||||||
protected $pluginConfigKey = 'configuration';
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* {@inheritdoc}
|
* {@inheritdoc}
|
||||||
*/
|
*/
|
||||||
|
@ -116,15 +111,25 @@ class SearchPage extends ConfigEntityBase implements SearchPageInterface, Entity
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* {@inheritdoc}
|
* Encapsulates the creation of the search page's PluginBag.
|
||||||
|
*
|
||||||
|
* @return \Drupal\Component\Plugin\PluginBag
|
||||||
|
* The search page's plugin bag.
|
||||||
*/
|
*/
|
||||||
public function getPluginBag() {
|
protected function getPluginBag() {
|
||||||
if (!$this->pluginBag) {
|
if (!$this->pluginBag) {
|
||||||
$this->pluginBag = new SearchPluginBag($this->searchPluginManager(), $this->plugin, $this->configuration, $this->id());
|
$this->pluginBag = new SearchPluginBag($this->searchPluginManager(), $this->plugin, $this->configuration, $this->id());
|
||||||
}
|
}
|
||||||
return $this->pluginBag;
|
return $this->pluginBag;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* {@inheritdoc}
|
||||||
|
*/
|
||||||
|
public function getPluginBags() {
|
||||||
|
return array('configuration' => $this->getPluginBag());
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* {@inheritdoc}
|
* {@inheritdoc}
|
||||||
*/
|
*/
|
||||||
|
|
|
@ -9,7 +9,7 @@ namespace Drupal\system\Entity;
|
||||||
|
|
||||||
use Drupal\Core\Config\Entity\ConfigEntityBase;
|
use Drupal\Core\Config\Entity\ConfigEntityBase;
|
||||||
use Drupal\Core\Config\Entity\ConfigEntityInterface;
|
use Drupal\Core\Config\Entity\ConfigEntityInterface;
|
||||||
use Drupal\Core\Config\Entity\EntityWithPluginBagInterface;
|
use Drupal\Core\Entity\EntityWithPluginBagsInterface;
|
||||||
use Drupal\system\ActionConfigEntityInterface;
|
use Drupal\system\ActionConfigEntityInterface;
|
||||||
use Drupal\Core\Action\ActionBag;
|
use Drupal\Core\Action\ActionBag;
|
||||||
use Drupal\Component\Plugin\ConfigurablePluginInterface;
|
use Drupal\Component\Plugin\ConfigurablePluginInterface;
|
||||||
|
@ -27,7 +27,7 @@ use Drupal\Component\Plugin\ConfigurablePluginInterface;
|
||||||
* }
|
* }
|
||||||
* )
|
* )
|
||||||
*/
|
*/
|
||||||
class Action extends ConfigEntityBase implements ActionConfigEntityInterface, EntityWithPluginBagInterface {
|
class Action extends ConfigEntityBase implements ActionConfigEntityInterface, EntityWithPluginBagsInterface {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The name (plugin ID) of the action.
|
* The name (plugin ID) of the action.
|
||||||
|
@ -72,20 +72,25 @@ class Action extends ConfigEntityBase implements ActionConfigEntityInterface, En
|
||||||
protected $pluginBag;
|
protected $pluginBag;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* {@inheritdoc}
|
* Encapsulates the creation of the action's PluginBag.
|
||||||
|
*
|
||||||
|
* @return \Drupal\Component\Plugin\PluginBag
|
||||||
|
* The action's plugin bag.
|
||||||
*/
|
*/
|
||||||
protected $pluginConfigKey = 'configuration';
|
protected function getPluginBag() {
|
||||||
|
|
||||||
/**
|
|
||||||
* {@inheritdoc}
|
|
||||||
*/
|
|
||||||
public function getPluginBag() {
|
|
||||||
if (!$this->pluginBag) {
|
if (!$this->pluginBag) {
|
||||||
$this->pluginBag = new ActionBag(\Drupal::service('plugin.manager.action'), $this->plugin, $this->configuration);
|
$this->pluginBag = new ActionBag(\Drupal::service('plugin.manager.action'), $this->plugin, $this->configuration);
|
||||||
}
|
}
|
||||||
return $this->pluginBag;
|
return $this->pluginBag;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* {@inheritdoc}
|
||||||
|
*/
|
||||||
|
public function getPluginBags() {
|
||||||
|
return array('configuration' => $this->getPluginBag());
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* {@inheritdoc}
|
* {@inheritdoc}
|
||||||
*/
|
*/
|
||||||
|
|
|
@ -7,7 +7,7 @@
|
||||||
|
|
||||||
namespace Drupal\system\Tests\Entity;
|
namespace Drupal\system\Tests\Entity;
|
||||||
|
|
||||||
use Drupal\Core\Config\Entity\EntityWithPluginBagInterface;
|
use Drupal\Core\Entity\EntityWithPluginBagsInterface;
|
||||||
use Drupal\simpletest\WebTestBase;
|
use Drupal\simpletest\WebTestBase;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -101,7 +101,7 @@ class ConfigEntityImportTest extends WebTestBase {
|
||||||
|
|
||||||
/** @var $entity \Drupal\filter\Entity\FilterFormat */
|
/** @var $entity \Drupal\filter\Entity\FilterFormat */
|
||||||
$entity = entity_load('filter_format', 'plain_text');
|
$entity = entity_load('filter_format', 'plain_text');
|
||||||
$plugin_bag = $entity->getPluginBag();
|
$plugin_bag = $entity->getPluginBags()['filters'];
|
||||||
|
|
||||||
$filters = $entity->get('filters');
|
$filters = $entity->get('filters');
|
||||||
$this->assertIdentical(72, $filters['filter_url']['settings']['filter_url_length']);
|
$this->assertIdentical(72, $filters['filter_url']['settings']['filter_url_length']);
|
||||||
|
@ -113,7 +113,7 @@ class ConfigEntityImportTest extends WebTestBase {
|
||||||
$this->assertIdentical($filters, $plugin_bag->getConfiguration());
|
$this->assertIdentical($filters, $plugin_bag->getConfiguration());
|
||||||
|
|
||||||
$filters['filter_url']['settings']['filter_url_length'] = -100;
|
$filters['filter_url']['settings']['filter_url_length'] = -100;
|
||||||
$entity->getPluginBag()->setConfiguration($filters);
|
$entity->getPluginBags()['filters']->setConfiguration($filters);
|
||||||
$entity->save();
|
$entity->save();
|
||||||
$this->assertIdentical($filters, $entity->get('filters'));
|
$this->assertIdentical($filters, $entity->get('filters'));
|
||||||
$this->assertIdentical($filters, $plugin_bag->getConfiguration());
|
$this->assertIdentical($filters, $plugin_bag->getConfiguration());
|
||||||
|
@ -133,7 +133,7 @@ class ConfigEntityImportTest extends WebTestBase {
|
||||||
|
|
||||||
/** @var $entity \Drupal\image\Entity\ImageStyle */
|
/** @var $entity \Drupal\image\Entity\ImageStyle */
|
||||||
$entity = entity_load('image_style', 'thumbnail');
|
$entity = entity_load('image_style', 'thumbnail');
|
||||||
$plugin_bag = $entity->getPluginBag();
|
$plugin_bag = $entity->getPluginBags()['effects'];
|
||||||
|
|
||||||
$effects = $entity->get('effects');
|
$effects = $entity->get('effects');
|
||||||
$effect_id = key($effects);
|
$effect_id = key($effects);
|
||||||
|
@ -147,7 +147,7 @@ class ConfigEntityImportTest extends WebTestBase {
|
||||||
$this->assertIdentical($effects, $plugin_bag->getConfiguration());
|
$this->assertIdentical($effects, $plugin_bag->getConfiguration());
|
||||||
|
|
||||||
$effects[$effect_id]['data']['height'] = -50;
|
$effects[$effect_id]['data']['height'] = -50;
|
||||||
$entity->getPluginBag()->setConfiguration($effects);
|
$entity->getPluginBags()['effects']->setConfiguration($effects);
|
||||||
$entity->save();
|
$entity->save();
|
||||||
// Ensure the entity and plugin have the correct configuration.
|
// Ensure the entity and plugin have the correct configuration.
|
||||||
$this->assertIdentical($effects, $entity->get('effects'));
|
$this->assertIdentical($effects, $entity->get('effects'));
|
||||||
|
@ -184,7 +184,7 @@ class ConfigEntityImportTest extends WebTestBase {
|
||||||
/**
|
/**
|
||||||
* Tests that a single set of plugin config stays in sync.
|
* Tests that a single set of plugin config stays in sync.
|
||||||
*
|
*
|
||||||
* @param \Drupal\Core\Config\Entity\EntityWithPluginBagInterface $entity
|
* @param \Drupal\Core\Entity\EntityWithPluginBagsInterface $entity
|
||||||
* The entity.
|
* The entity.
|
||||||
* @param string $config_key
|
* @param string $config_key
|
||||||
* Where the plugin config is stored.
|
* Where the plugin config is stored.
|
||||||
|
@ -193,8 +193,8 @@ class ConfigEntityImportTest extends WebTestBase {
|
||||||
* @param mixed $expected
|
* @param mixed $expected
|
||||||
* The expected default value of the plugin config setting.
|
* The expected default value of the plugin config setting.
|
||||||
*/
|
*/
|
||||||
protected function checkSinglePluginConfigSync(EntityWithPluginBagInterface $entity, $config_key, $setting_key, $expected) {
|
protected function checkSinglePluginConfigSync(EntityWithPluginBagsInterface $entity, $config_key, $setting_key, $expected) {
|
||||||
$plugin_bag = $entity->getPluginBag();
|
$plugin_bag = $entity->getPluginBags()[$config_key];
|
||||||
$settings = $entity->get($config_key);
|
$settings = $entity->get($config_key);
|
||||||
|
|
||||||
// Ensure the default config exists.
|
// Ensure the default config exists.
|
||||||
|
|
|
@ -210,13 +210,13 @@ class ConfigEntityBaseUnitTest extends UnitTestCase {
|
||||||
/**
|
/**
|
||||||
* @covers ::calculateDependencies
|
* @covers ::calculateDependencies
|
||||||
*
|
*
|
||||||
* @dataProvider providerCalculateDependenciesWithPluginBag
|
* @dataProvider providerCalculateDependenciesWithPluginBags
|
||||||
*/
|
*/
|
||||||
public function testCalculateDependenciesWithPluginBag($definition, $expected_dependencies) {
|
public function testCalculateDependenciesWithPluginBags($definition, $expected_dependencies) {
|
||||||
$values = array();
|
$values = array();
|
||||||
$this->entity = $this->getMockBuilder('\Drupal\Tests\Core\Config\Entity\Fixtures\ConfigEntityBaseWithPluginBag')
|
$this->entity = $this->getMockBuilder('\Drupal\Tests\Core\Config\Entity\Fixtures\ConfigEntityBaseWithPluginBags')
|
||||||
->setConstructorArgs(array($values, $this->entityTypeId))
|
->setConstructorArgs(array($values, $this->entityTypeId))
|
||||||
->setMethods(array('getPluginBag'))
|
->setMethods(array('getPluginBags'))
|
||||||
->getMock();
|
->getMock();
|
||||||
|
|
||||||
// Create a configurable plugin that would add a dependency.
|
// Create a configurable plugin that would add a dependency.
|
||||||
|
@ -236,18 +236,18 @@ class ConfigEntityBaseUnitTest extends UnitTestCase {
|
||||||
|
|
||||||
// Return the mocked plugin bag.
|
// Return the mocked plugin bag.
|
||||||
$this->entity->expects($this->once())
|
$this->entity->expects($this->once())
|
||||||
->method('getPluginBag')
|
->method('getPluginBags')
|
||||||
->will($this->returnValue($pluginBag));
|
->will($this->returnValue(array($pluginBag)));
|
||||||
|
|
||||||
$this->assertEquals($expected_dependencies, $this->entity->calculateDependencies());
|
$this->assertEquals($expected_dependencies, $this->entity->calculateDependencies());
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Data provider for testCalculateDependenciesWithPluginBag.
|
* Data provider for testCalculateDependenciesWithPluginBags.
|
||||||
*
|
*
|
||||||
* @return array
|
* @return array
|
||||||
*/
|
*/
|
||||||
public function providerCalculateDependenciesWithPluginBag() {
|
public function providerCalculateDependenciesWithPluginBags() {
|
||||||
// Start with 'a' so that order of the dependency array is fixed.
|
// Start with 'a' so that order of the dependency array is fixed.
|
||||||
$instance_dependency_1 = 'a' . $this->randomName(10);
|
$instance_dependency_1 = 'a' . $this->randomName(10);
|
||||||
$instance_dependency_2 = 'a' . $this->randomName(11);
|
$instance_dependency_2 = 'a' . $this->randomName(11);
|
||||||
|
|
|
@ -2,19 +2,19 @@
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @file
|
* @file
|
||||||
* Contains \Drupal\Tests\Core\Config\Entity\Fixtures\ConfigEntityBaseWithPluginBag.
|
* Contains \Drupal\Tests\Core\Config\Entity\Fixtures\ConfigEntityBaseWithPluginBags.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
namespace Drupal\Tests\Core\Config\Entity\Fixtures;
|
namespace Drupal\Tests\Core\Config\Entity\Fixtures;
|
||||||
|
|
||||||
use Drupal\Core\Config\Entity\ConfigEntityBase;
|
use Drupal\Core\Config\Entity\ConfigEntityBase;
|
||||||
use Drupal\Core\Config\Entity\EntityWithPluginBagInterface;
|
use Drupal\Core\Entity\EntityWithPluginBagsInterface;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Enables testing of dependency calculation.
|
* Enables testing of dependency calculation.
|
||||||
*
|
*
|
||||||
* @see \Drupal\Tests\Core\Config\Entity\ConfigEntityBaseUnitTest::testCalculateDependenciesWithPluginBag()
|
* @see \Drupal\Tests\Core\Config\Entity\ConfigEntityBaseUnitTest::testCalculateDependenciesWithPluginBags()
|
||||||
* @see \Drupal\Core\Config\Entity\ConfigEntityBase::calculateDependencies()
|
* @see \Drupal\Core\Config\Entity\ConfigEntityBase::calculateDependencies()
|
||||||
*/
|
*/
|
||||||
abstract class ConfigEntityBaseWithPluginBag extends ConfigEntityBase implements EntityWithPluginBagInterface {
|
abstract class ConfigEntityBaseWithPluginBags extends ConfigEntityBase implements EntityWithPluginBagsInterface {
|
||||||
}
|
}
|
Loading…
Reference in New Issue