diff --git a/core/lib/Drupal/Component/Plugin/Discovery/DerivativeDiscoveryDecorator.php b/core/lib/Drupal/Component/Plugin/Discovery/DerivativeDiscoveryDecorator.php index 53a1bef0c4fe50df9d6a4c4b6fad593095eff2ea..8eb2568ec97c696c5cb0b1e4614d13c343b42360 100644 --- a/core/lib/Drupal/Component/Plugin/Discovery/DerivativeDiscoveryDecorator.php +++ b/core/lib/Drupal/Component/Plugin/Discovery/DerivativeDiscoveryDecorator.php @@ -209,8 +209,11 @@ protected function getDeriver($base_plugin_id, $base_definition) { protected function getDeriverClass($base_definition) { $class = NULL; if ((is_array($base_definition) || ($base_definition = (array) $base_definition)) && (isset($base_definition['deriver']) && $class = $base_definition['deriver'])) { + if (!class_exists($class)) { + throw new InvalidDeriverException(sprintf('Plugin (%s) deriver "%s" does not exist.', $base_definition['id'], $class)); + } if (!is_subclass_of($class, '\Drupal\Component\Plugin\Derivative\DeriverInterface')) { - throw new InvalidDeriverException(sprintf('Plugin (%s) deriver "%s" must implement \Drupal\Component\Plugin\Derivative\DeriverInterface', $base_definition['id'], $class)); + throw new InvalidDeriverException(sprintf('Plugin (%s) deriver "%s" must implement \Drupal\Component\Plugin\Derivative\DeriverInterface.', $base_definition['id'], $class)); } } return $class; diff --git a/core/tests/Drupal/Tests/Core/Plugin/Discovery/DerivativeDiscoveryDecoratorTest.php b/core/tests/Drupal/Tests/Core/Plugin/Discovery/DerivativeDiscoveryDecoratorTest.php index f0740830af178746325c2e8b166df715efd51d6b..4cc05ad713ed4a770e3f7f232e02f8b7d433d5df 100644 --- a/core/tests/Drupal/Tests/Core/Plugin/Discovery/DerivativeDiscoveryDecoratorTest.php +++ b/core/tests/Drupal/Tests/Core/Plugin/Discovery/DerivativeDiscoveryDecoratorTest.php @@ -88,12 +88,36 @@ public function testGetDerivativeFetcherWithAnnotationObjects() { $this->assertEquals('\Drupal\Tests\Core\Plugin\Discovery\TestDerivativeDiscoveryWithObject', $definitions['non_container_aware_discovery:test_discovery_1']->deriver); } + /** + * Tests the getDerivativeFetcher method with a non-existent class. + * + * @see \Drupal\Component\Plugin\Discovery\DerivativeDiscoveryDecorator::getDeriver().\ + * + * @expectedException \Drupal\Component\Plugin\Exception\InvalidDeriverException + * @expectedExceptionMessage Plugin (non_existent_discovery) deriver "\Drupal\system\Tests\Plugin\NonExistentDeriver" does not exist. + */ + public function testNonExistentDerivativeFetcher() { + $definitions = array(); + // Do this with a class that doesn't exist. + $definitions['non_existent_discovery'] = array( + 'id' => 'non_existent_discovery', + 'deriver' => '\Drupal\system\Tests\Plugin\NonExistentDeriver', + ); + $this->discoveryMain->expects($this->any()) + ->method('getDefinitions') + ->will($this->returnValue($definitions)); + + $discovery = new DerivativeDiscoveryDecorator($this->discoveryMain); + $discovery->getDefinitions(); + } + /** * Tests the getDerivativeFetcher method with an invalid class. * * @see \Drupal\Component\Plugin\Discovery\DerivativeDiscoveryDecorator::getDeriver().\ * * @expectedException \Drupal\Component\Plugin\Exception\InvalidDeriverException + * @expectedExceptionMessage Plugin (invalid_discovery) deriver "\Drupal\system\Tests\Plugin\DerivativeTest" must implement \Drupal\Component\Plugin\Derivative\DeriverInterface. */ public function testInvalidDerivativeFetcher() { $definitions = array();