diff --git a/core/lib/Drupal/Core/Action/ActionCollection.php b/core/lib/Drupal/Core/Action/ActionCollection.php deleted file mode 100644 index 3086015..0000000 --- a/core/lib/Drupal/Core/Action/ActionCollection.php +++ /dev/null @@ -1,26 +0,0 @@ -conditionCollection)) { - $this->conditionCollection = new ConditionLazyPluginCollection($this->conditionPluginManager(), $this->configuration['visibility']); + $this->conditionCollection = new ConditionPluginCollection($this->conditionPluginManager(), $this->configuration['visibility']); } return $this->conditionCollection; } diff --git a/core/lib/Drupal/Core/Block/BlockPluginInterface.php b/core/lib/Drupal/Core/Block/BlockPluginInterface.php index e174604..01f97ad 100644 --- a/core/lib/Drupal/Core/Block/BlockPluginInterface.php +++ b/core/lib/Drupal/Core/Block/BlockPluginInterface.php @@ -146,7 +146,7 @@ public function getMachineNameSuggestion(); /** * Gets conditions for this block. * - * @return \Drupal\Core\Condition\ConditionInterface[]|\Drupal\Core\Condition\ConditionLazyPluginCollection + * @return \Drupal\Core\Condition\ConditionInterface[]|\Drupal\Core\Condition\ConditionPluginCollection * An array or collection of configured condition plugins. */ public function getVisibilityConditions(); diff --git a/core/lib/Drupal/Core/Condition/ConditionLazyPluginCollection.php b/core/lib/Drupal/Core/Condition/ConditionLazyPluginCollection.php deleted file mode 100644 index e2189a2..0000000 --- a/core/lib/Drupal/Core/Condition/ConditionLazyPluginCollection.php +++ /dev/null @@ -1,76 +0,0 @@ - $instance_config) { - $default_config = array(); - $default_config['id'] = $instance_id; - $default_config += $this->get($instance_id)->defaultConfiguration(); - if ($default_config === $instance_config) { - unset($configuration[$instance_id]); - } - } - return $configuration; - } - - /** - * Sets the condition context for a given name. - * - * @param string $name - * The name of the context. - * @param \Drupal\Component\Plugin\Context\ContextInterface $context - * The context to add. - * - * @return $this - */ - public function addContext($name, ContextInterface $context) { - $this->conditionContexts[$name] = $context; - return $this; - } - - /** - * Gets the values for all defined contexts. - * - * @return \Drupal\Component\Plugin\Context\ContextInterface[] - * An array of set contexts, keyed by context name. - */ - public function getConditionContexts() { - return $this->conditionContexts; - } - -} diff --git a/core/lib/Drupal/Core/Condition/ConditionPluginCollection.php b/core/lib/Drupal/Core/Condition/ConditionPluginCollection.php new file mode 100644 index 0000000..c2e532f --- /dev/null +++ b/core/lib/Drupal/Core/Condition/ConditionPluginCollection.php @@ -0,0 +1,76 @@ + $instance_config) { + $default_config = array(); + $default_config['id'] = $instance_id; + $default_config += $this->get($instance_id)->defaultConfiguration(); + if ($default_config === $instance_config) { + unset($configuration[$instance_id]); + } + } + return $configuration; + } + + /** + * Sets the condition context for a given name. + * + * @param string $name + * The name of the context. + * @param \Drupal\Component\Plugin\Context\ContextInterface $context + * The context to add. + * + * @return $this + */ + public function addContext($name, ContextInterface $context) { + $this->conditionContexts[$name] = $context; + return $this; + } + + /** + * Gets the values for all defined contexts. + * + * @return \Drupal\Component\Plugin\Context\ContextInterface[] + * An array of set contexts, keyed by context name. + */ + public function getConditionContexts() { + return $this->conditionContexts; + } + +} diff --git a/core/modules/block/src/Event/BlockConditionContextEvent.php b/core/modules/block/src/Event/BlockConditionContextEvent.php index 4ade466..af155b7 100644 --- a/core/modules/block/src/Event/BlockConditionContextEvent.php +++ b/core/modules/block/src/Event/BlockConditionContextEvent.php @@ -7,7 +7,7 @@ namespace Drupal\block\Event; -use Drupal\Core\Condition\ConditionLazyPluginCollection; +use Drupal\Core\Condition\ConditionPluginCollection; use Symfony\Component\EventDispatcher\Event; /** @@ -18,14 +18,14 @@ class BlockConditionContextEvent extends Event { /** - * @var \Drupal\Core\Condition\ConditionLazyPluginCollection + * @var \Drupal\Core\Condition\ConditionPluginCollection */ protected $conditions; /** - * @param \Drupal\Core\Condition\ConditionLazyPluginCollection $conditions + * @param \Drupal\Core\Condition\ConditionPluginCollection $conditions */ - public function __construct(ConditionLazyPluginCollection $conditions) { + public function __construct(ConditionPluginCollection $conditions) { $this->conditions = $conditions; } diff --git a/core/modules/block/src/EventSubscriber/BlockConditionContextSubscriberBase.php b/core/modules/block/src/EventSubscriber/BlockConditionContextSubscriberBase.php index bc2ab32..9fc2e87 100644 --- a/core/modules/block/src/EventSubscriber/BlockConditionContextSubscriberBase.php +++ b/core/modules/block/src/EventSubscriber/BlockConditionContextSubscriberBase.php @@ -18,7 +18,7 @@ abstract class BlockConditionContextSubscriberBase implements EventSubscriberInterface { /** - * @var \Drupal\Core\Condition\ConditionLazyPluginCollection + * @var \Drupal\Core\Condition\ConditionPluginCollection */ protected $conditions; diff --git a/core/modules/editor/src/Tests/EditorFileReferenceFilterTest.php b/core/modules/editor/src/Tests/EditorFileReferenceFilterTest.php index 6303e1d..bda9b2e 100644 --- a/core/modules/editor/src/Tests/EditorFileReferenceFilterTest.php +++ b/core/modules/editor/src/Tests/EditorFileReferenceFilterTest.php @@ -9,7 +9,7 @@ use Drupal\Core\Cache\Cache; use Drupal\simpletest\KernelTestBase; -use Drupal\filter\FilterCollection; +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 FilterCollection($manager, array()); + $bag = new FilterPluginCollection($manager, array()); $this->filters = $bag->getAll(); } diff --git a/core/modules/filter/src/Entity/FilterFormat.php b/core/modules/filter/src/Entity/FilterFormat.php index bdbc2a2..4b00af1 100644 --- a/core/modules/filter/src/Entity/FilterFormat.php +++ b/core/modules/filter/src/Entity/FilterFormat.php @@ -11,7 +11,7 @@ use Drupal\Core\Entity\EntityWithPluginCollectionInterface; use Drupal\Core\Entity\EntityStorageInterface; use Drupal\filter\FilterFormatInterface; -use Drupal\filter\FilterCollection; +use Drupal\filter\FilterPluginCollection; use Drupal\filter\Plugin\FilterInterface; /** @@ -114,7 +114,7 @@ class FilterFormat extends ConfigEntityBase implements FilterFormatInterface, En /** * Holds the collection of filters that are attached to this format. * - * @var \Drupal\filter\FilterCollection + * @var \Drupal\filter\FilterPluginCollection */ protected $filterCollection; @@ -130,7 +130,7 @@ public function id() { */ public function filters($instance_id = NULL) { if (!isset($this->filterCollection)) { - $this->filterCollection = new FilterCollection(\Drupal::service('plugin.manager.filter'), $this->filters); + $this->filterCollection = new FilterPluginCollection(\Drupal::service('plugin.manager.filter'), $this->filters); $this->filterCollection->sort(); } if (isset($instance_id)) { diff --git a/core/modules/filter/src/FilterCollection.php b/core/modules/filter/src/FilterCollection.php deleted file mode 100644 index 22317c4..0000000 --- a/core/modules/filter/src/FilterCollection.php +++ /dev/null @@ -1,132 +0,0 @@ -definitions) { - $this->definitions = $this->manager->getDefinitions(); - // Do not allow the null filter to be used directly, only as a fallback. - unset($this->definitions['filter_null']); - } - - // Ensure that there is an instance of all available filters. - // Note that getDefinitions() are keyed by $plugin_id. $instance_id is the - // $plugin_id for filters, since a single filter plugin can only exist once - // in a format. - foreach ($this->definitions as $plugin_id => $definition) { - if (!isset($this->pluginInstances[$plugin_id])) { - $this->initializePlugin($plugin_id); - } - } - return $this->pluginInstances; - } - - /** - * {@inheritdoc} - */ - protected function initializePlugin($instance_id) { - // Filters have a 1:1 relationship to text formats and can be added and - // instantiated at any time. - // @todo $configuration is the whole filter plugin instance configuration, - // as contained in the text format configuration. The default - // configuration is the filter plugin definition. Configuration should not - // be contained in definitions. Move into a FilterBase::init() method. - $configuration = $this->manager->getDefinition($instance_id); - // Merge the actual configuration into the default configuration. - if (isset($this->configurations[$instance_id])) { - $configuration = NestedArray::mergeDeep($configuration, $this->configurations[$instance_id]); - } - $this->configurations[$instance_id] = $configuration; - parent::initializePlugin($instance_id); - } - - /** - * {@inheritdoc} - */ - public function sort() { - $this->getAll(); - return parent::sort(); - } - - /** - * {@inheritdoc} - */ - public function sortHelper($aID, $bID) { - $a = $this->get($aID); - $b = $this->get($bID); - if ($a->status != $b->status) { - return !empty($a->status) ? -1 : 1; - } - if ($a->weight != $b->weight) { - return $a->weight < $b->weight ? -1 : 1; - } - if ($a->provider != $b->provider) { - return strnatcasecmp($a->provider, $b->provider); - } - return parent::sortHelper($aID, $bID); - } - - /** - * {@inheritdoc} - */ - public function getConfiguration() { - $configuration = parent::getConfiguration(); - // Remove configuration if it matches the defaults. In self::getAll(), we - // load all available filters, in addition to the enabled filters stored in - // configuration. In order to prevent those from bleeding through to the - // stored configuration, remove all filters that match the default values. - // Because filters are disabled by default, this will never remove the - // configuration of an enabled filter. - foreach ($configuration as $instance_id => $instance_config) { - $default_config = array(); - $default_config['id'] = $instance_id; - $default_config += $this->get($instance_id)->defaultConfiguration(); - if ($default_config === $instance_config) { - unset($configuration[$instance_id]); - } - } - return $configuration; - } - -} diff --git a/core/modules/filter/src/FilterFormatInterface.php b/core/modules/filter/src/FilterFormatInterface.php index 876574e..b5e75ce 100644 --- a/core/modules/filter/src/FilterFormatInterface.php +++ b/core/modules/filter/src/FilterFormatInterface.php @@ -20,7 +20,7 @@ * @param string $instance_id * (optional) The ID of a filter plugin instance to return. * - * @return \Drupal\filter\FilterCollection|\Drupal\filter\Plugin\FilterInterface + * @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 FilterCollection 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. diff --git a/core/modules/filter/src/FilterPluginCollection.php b/core/modules/filter/src/FilterPluginCollection.php new file mode 100644 index 0000000..3e32470 --- /dev/null +++ b/core/modules/filter/src/FilterPluginCollection.php @@ -0,0 +1,132 @@ +definitions) { + $this->definitions = $this->manager->getDefinitions(); + // Do not allow the null filter to be used directly, only as a fallback. + unset($this->definitions['filter_null']); + } + + // Ensure that there is an instance of all available filters. + // Note that getDefinitions() are keyed by $plugin_id. $instance_id is the + // $plugin_id for filters, since a single filter plugin can only exist once + // in a format. + foreach ($this->definitions as $plugin_id => $definition) { + if (!isset($this->pluginInstances[$plugin_id])) { + $this->initializePlugin($plugin_id); + } + } + return $this->pluginInstances; + } + + /** + * {@inheritdoc} + */ + protected function initializePlugin($instance_id) { + // Filters have a 1:1 relationship to text formats and can be added and + // instantiated at any time. + // @todo $configuration is the whole filter plugin instance configuration, + // as contained in the text format configuration. The default + // configuration is the filter plugin definition. Configuration should not + // be contained in definitions. Move into a FilterBase::init() method. + $configuration = $this->manager->getDefinition($instance_id); + // Merge the actual configuration into the default configuration. + if (isset($this->configurations[$instance_id])) { + $configuration = NestedArray::mergeDeep($configuration, $this->configurations[$instance_id]); + } + $this->configurations[$instance_id] = $configuration; + parent::initializePlugin($instance_id); + } + + /** + * {@inheritdoc} + */ + public function sort() { + $this->getAll(); + return parent::sort(); + } + + /** + * {@inheritdoc} + */ + public function sortHelper($aID, $bID) { + $a = $this->get($aID); + $b = $this->get($bID); + if ($a->status != $b->status) { + return !empty($a->status) ? -1 : 1; + } + if ($a->weight != $b->weight) { + return $a->weight < $b->weight ? -1 : 1; + } + if ($a->provider != $b->provider) { + return strnatcasecmp($a->provider, $b->provider); + } + return parent::sortHelper($aID, $bID); + } + + /** + * {@inheritdoc} + */ + public function getConfiguration() { + $configuration = parent::getConfiguration(); + // Remove configuration if it matches the defaults. In self::getAll(), we + // load all available filters, in addition to the enabled filters stored in + // configuration. In order to prevent those from bleeding through to the + // stored configuration, remove all filters that match the default values. + // Because filters are disabled by default, this will never remove the + // configuration of an enabled filter. + foreach ($configuration as $instance_id => $instance_config) { + $default_config = array(); + $default_config['id'] = $instance_id; + $default_config += $this->get($instance_id)->defaultConfiguration(); + if ($default_config === $instance_config) { + unset($configuration[$instance_id]); + } + } + return $configuration; + } + +} diff --git a/core/modules/filter/src/Plugin/FilterBase.php b/core/modules/filter/src/Plugin/FilterBase.php index 42532e9..b5394b4 100644 --- a/core/modules/filter/src/Plugin/FilterBase.php +++ b/core/modules/filter/src/Plugin/FilterBase.php @@ -58,7 +58,7 @@ /** * A collection of all filters this filter participates in. * - * @var \Drupal\filter\FilterCollection + * @var \Drupal\filter\FilterPluginCollection */ protected $collection; diff --git a/core/modules/filter/src/Tests/FilterUnitTest.php b/core/modules/filter/src/Tests/FilterUnitTest.php index fb8e6fc..50813ea 100644 --- a/core/modules/filter/src/Tests/FilterUnitTest.php +++ b/core/modules/filter/src/Tests/FilterUnitTest.php @@ -10,7 +10,7 @@ use Drupal\Component\Utility\Html; use Drupal\Component\Utility\String; use Drupal\simpletest\DrupalUnitTestBase; -use Drupal\filter\FilterCollection; +use Drupal\filter\FilterPluginCollection; /** * Tests Filter module filters individually. @@ -36,7 +36,7 @@ protected function setUp() { $this->installConfig(array('system')); $manager = $this->container->get('plugin.manager.filter'); - $bag = new FilterCollection($manager, array()); + $bag = new FilterPluginCollection($manager, array()); $this->filters = $bag->getAll(); } diff --git a/core/modules/image/src/Entity/ImageStyle.php b/core/modules/image/src/Entity/ImageStyle.php index 75c3401..5811c0e 100644 --- a/core/modules/image/src/Entity/ImageStyle.php +++ b/core/modules/image/src/Entity/ImageStyle.php @@ -14,7 +14,7 @@ use Drupal\Core\Entity\EntityWithPluginCollectionInterface; use Drupal\Core\Routing\RequestHelper; use Drupal\Core\Site\Settings; -use Drupal\image\ImageEffectCollection; +use Drupal\image\ImageEffectPluginCollection; use Drupal\image\ImageEffectInterface; use Drupal\image\ImageStyleInterface; use Drupal\Component\Utility\Crypt; @@ -85,7 +85,7 @@ class ImageStyle extends ConfigEntityBase implements ImageStyleInterface, Entity /** * Holds the collection of image effects that are used by this image style. * - * @var \Drupal\image\ImageEffectCollection + * @var \Drupal\image\ImageEffectPluginCollection */ protected $effectsCollection; @@ -347,7 +347,7 @@ public function getEffect($effect) { */ public function getEffects() { if (!$this->effectsCollection) { - $this->effectsCollection = new ImageEffectCollection($this->getImageEffectPluginManager(), $this->effects); + $this->effectsCollection = new ImageEffectPluginCollection($this->getImageEffectPluginManager(), $this->effects); $this->effectsCollection->sort(); } return $this->effectsCollection; diff --git a/core/modules/image/src/ImageEffectCollection.php b/core/modules/image/src/ImageEffectCollection.php deleted file mode 100644 index e587789..0000000 --- a/core/modules/image/src/ImageEffectCollection.php +++ /dev/null @@ -1,39 +0,0 @@ -get($aID)->getWeight(); - $b_weight = $this->get($bID)->getWeight(); - if ($a_weight == $b_weight) { - return 0; - } - - return ($a_weight < $b_weight) ? -1 : 1; - } - -} diff --git a/core/modules/image/src/ImageEffectPluginCollection.php b/core/modules/image/src/ImageEffectPluginCollection.php new file mode 100644 index 0000000..ef17191 --- /dev/null +++ b/core/modules/image/src/ImageEffectPluginCollection.php @@ -0,0 +1,39 @@ +get($aID)->getWeight(); + $b_weight = $this->get($bID)->getWeight(); + if ($a_weight == $b_weight) { + return 0; + } + + return ($a_weight < $b_weight) ? -1 : 1; + } + +} diff --git a/core/modules/image/src/ImageStyleInterface.php b/core/modules/image/src/ImageStyleInterface.php index 91e2bf2..6701d6f 100644 --- a/core/modules/image/src/ImageStyleInterface.php +++ b/core/modules/image/src/ImageStyleInterface.php @@ -157,7 +157,7 @@ public function getEffect($effect); /** * Returns the image effects for this style. * - * @return \Drupal\image\ImageEffectCollection|\Drupal\image\ImageEffectInterface[] + * @return \Drupal\image\ImageEffectPluginCollection|\Drupal\image\ImageEffectInterface[] * The image effect plugin collection. */ public function getEffects(); diff --git a/core/modules/system/src/Entity/Action.php b/core/modules/system/src/Entity/Action.php index d249502..a7176db 100644 --- a/core/modules/system/src/Entity/Action.php +++ b/core/modules/system/src/Entity/Action.php @@ -11,7 +11,7 @@ use Drupal\Core\Config\Entity\ConfigEntityInterface; use Drupal\Core\Entity\EntityWithPluginCollectionInterface; use Drupal\system\ActionConfigEntityInterface; -use Drupal\Core\Action\ActionCollection; +use Drupal\Core\Action\ActionPluginCollection; use Drupal\Component\Plugin\ConfigurablePluginInterface; /** @@ -67,7 +67,7 @@ class Action extends ConfigEntityBase implements ActionConfigEntityInterface, En /** * The plugin collection that stores action plugins. * - * @var \Drupal\Core\Action\ActionCollection + * @var \Drupal\Core\Action\ActionPluginCollection */ protected $pluginCollection; @@ -79,7 +79,7 @@ class Action extends ConfigEntityBase implements ActionConfigEntityInterface, En */ protected function getPluginCollection() { if (!$this->pluginCollection) { - $this->pluginCollection = new ActionCollection(\Drupal::service('plugin.manager.action'), $this->plugin, $this->configuration); + $this->pluginCollection = new ActionPluginCollection(\Drupal::service('plugin.manager.action'), $this->plugin, $this->configuration); } return $this->pluginCollection; } diff --git a/core/modules/tour/src/Entity/Tour.php b/core/modules/tour/src/Entity/Tour.php index aee2545..d5ffdff 100644 --- a/core/modules/tour/src/Entity/Tour.php +++ b/core/modules/tour/src/Entity/Tour.php @@ -9,7 +9,7 @@ use Drupal\Core\Config\Entity\ConfigEntityBase; use Drupal\Core\Entity\EntityStorageInterface; -use Drupal\tour\TipsCollection; +use Drupal\tour\TipsPluginCollection; use Drupal\tour\TourInterface; /** @@ -67,7 +67,7 @@ class Tour extends ConfigEntityBase implements TourInterface { /** * Holds the collection of tips that are attached to this tour. * - * @var \Drupal\tour\TipsCollection + * @var \Drupal\tour\TipsPluginCollection */ protected $tipsCollection; @@ -84,7 +84,7 @@ class Tour extends ConfigEntityBase implements TourInterface { public function __construct(array $values, $entity_type) { parent::__construct($values, $entity_type); - $this->tipsCollection = new TipsCollection(\Drupal::service('plugin.manager.tour.tip'), $this->tips); + $this->tipsCollection = new TipsPluginCollection(\Drupal::service('plugin.manager.tour.tip'), $this->tips); } /** diff --git a/core/modules/tour/src/TipsCollection.php b/core/modules/tour/src/TipsCollection.php deleted file mode 100644 index 8b5cd0b..0000000 --- a/core/modules/tour/src/TipsCollection.php +++ /dev/null @@ -1,31 +0,0 @@ -storage->get('display')); - - $this->view = $view; - $this->initializePlugin('default'); - } - - /** - * Destructs a DisplayCollection object. - */ - public function __destruct() { - $this->clear(); - } - - /** - * {@inheritdoc} - * - * @return \Drupal\views\Plugin\views\display\DisplayPluginBase - */ - public function &get($instance_id) { - return parent::get($instance_id); - } - - /** - * Overrides \Drupal\Component\Plugin\LazyPluginCollection::clear(). - */ - public function clear() { - foreach (array_filter($this->pluginInstances) as $display) { - $display->destroy(); - } - - parent::clear(); - } - - /** - * {@inheritdoc} - */ - protected function initializePlugin($display_id) { - // Retrieve and initialize the new display handler with data. - $display = &$this->view->storage->getDisplay($display_id); - - try { - $this->configurations[$display_id] = $display; - parent::initializePlugin($display_id); - } - // Catch any plugin exceptions that are thrown. So we can fail nicely if a - // display plugin isn't found. - catch (PluginException $e) { - $message = $e->getMessage(); - drupal_set_message(t('!message', array('!message' => $message)), 'warning'); - } - - // If no plugin instance has been created, return NULL. - if (empty($this->pluginInstances[$display_id])) { - return NULL; - } - - $this->pluginInstances[$display_id]->initDisplay($this->view, $display); - // If this is not the default display handler, let it know which is since - // it may well utilize some data from the default. - if ($display_id != 'default') { - $this->pluginInstances[$display_id]->default_display = $this->pluginInstances['default']; - } - } - - /** - * Overrides \Drupal\Component\Plugin\LazyPluginCollection::remove(). - */ - public function remove($instance_id) { - $this->get($instance_id)->remove(); - - parent::remove($instance_id); - } - - -} diff --git a/core/modules/views/src/DisplayPluginCollection.php b/core/modules/views/src/DisplayPluginCollection.php new file mode 100644 index 0000000..e1c96b5 --- /dev/null +++ b/core/modules/views/src/DisplayPluginCollection.php @@ -0,0 +1,114 @@ +storage->get('display')); + + $this->view = $view; + $this->initializePlugin('default'); + } + + /** + * Destructs a DisplayPluginCollection object. + */ + public function __destruct() { + $this->clear(); + } + + /** + * {@inheritdoc} + * + * @return \Drupal\views\Plugin\views\display\DisplayPluginBase + */ + public function &get($instance_id) { + return parent::get($instance_id); + } + + /** + * Overrides \Drupal\Component\Plugin\LazyPluginCollection::clear(). + */ + public function clear() { + foreach (array_filter($this->pluginInstances) as $display) { + $display->destroy(); + } + + parent::clear(); + } + + /** + * {@inheritdoc} + */ + protected function initializePlugin($display_id) { + // Retrieve and initialize the new display handler with data. + $display = &$this->view->storage->getDisplay($display_id); + + try { + $this->configurations[$display_id] = $display; + parent::initializePlugin($display_id); + } + // Catch any plugin exceptions that are thrown. So we can fail nicely if a + // display plugin isn't found. + catch (PluginException $e) { + $message = $e->getMessage(); + drupal_set_message(t('!message', array('!message' => $message)), 'warning'); + } + + // If no plugin instance has been created, return NULL. + if (empty($this->pluginInstances[$display_id])) { + return NULL; + } + + $this->pluginInstances[$display_id]->initDisplay($this->view, $display); + // If this is not the default display handler, let it know which is since + // it may well utilize some data from the default. + if ($display_id != 'default') { + $this->pluginInstances[$display_id]->default_display = $this->pluginInstances['default']; + } + } + + /** + * Overrides \Drupal\Component\Plugin\LazyPluginCollection::remove(). + */ + public function remove($instance_id) { + $this->get($instance_id)->remove(); + + parent::remove($instance_id); + } + + +} diff --git a/core/modules/views/src/Tests/ViewExecutableTest.php b/core/modules/views/src/Tests/ViewExecutableTest.php index 5c46231..6ecca04 100644 --- a/core/modules/views/src/Tests/ViewExecutableTest.php +++ b/core/modules/views/src/Tests/ViewExecutableTest.php @@ -10,7 +10,7 @@ use Drupal\views\Views; use Drupal\views\ViewExecutable; use Drupal\views\ViewExecutableFactory; -use Drupal\views\DisplayCollection; +use Drupal\views\DisplayPluginCollection; use Drupal\views\Plugin\views\display\DefaultDisplay; use Drupal\views\Plugin\views\display\Page; use Drupal\views\Plugin\views\style\DefaultStyle; @@ -196,7 +196,7 @@ public function testDisplays() { // Tests Drupal\views\ViewExecutable::initDisplay(). $view->initDisplay(); - $this->assertTrue($view->displayHandlers instanceof DisplayCollection, 'The displayHandlers property has the right class.'); + $this->assertTrue($view->displayHandlers instanceof DisplayPluginCollection, 'The displayHandlers property has the right class.'); // Tests the classes of the instances. $this->assertTrue($view->displayHandlers->get('default') instanceof DefaultDisplay); $this->assertTrue($view->displayHandlers->get('page_1') instanceof Page); diff --git a/core/modules/views/src/ViewExecutable.php b/core/modules/views/src/ViewExecutable.php index 6805c50..87e2064 100644 --- a/core/modules/views/src/ViewExecutable.php +++ b/core/modules/views/src/ViewExecutable.php @@ -202,7 +202,7 @@ class ViewExecutable { * An array containing Drupal\views\Plugin\views\display\DisplayPluginBase * objects. * - * @var \Drupal\views\DisplayCollection + * @var \Drupal\views\DisplayPluginCollection */ public $displayHandlers; @@ -619,7 +619,7 @@ public function initDisplay() { } // Initialize the display cache array. - $this->displayHandlers = new DisplayCollection($this, Views::pluginManager('display')); + $this->displayHandlers = new DisplayPluginCollection($this, Views::pluginManager('display')); $this->current_display = 'default'; $this->display_handler = $this->displayHandlers->get('default'); diff --git a/core/modules/views_ui/src/Tests/DisplayFeedTest.php b/core/modules/views_ui/src/Tests/DisplayFeedTest.php index 002e351..b07d10b 100644 --- a/core/modules/views_ui/src/Tests/DisplayFeedTest.php +++ b/core/modules/views_ui/src/Tests/DisplayFeedTest.php @@ -49,7 +49,7 @@ protected function checkFeedViewUi($view_name) { $this->drupalGet('admin/structure/views'); // Verify that the page lists the $view_name view. // Regression test: ViewListBuilder::getDisplayPaths() did not properly - // check whether a DisplayCollection was returned in iterating over all + // check whether a DisplayPluginCollection was returned in iterating over all // displays. $this->assertText($view_name);