diff --git a/core/lib/Drupal/Component/Plugin/Discovery/DerivativeDiscoveryDecorator.php b/core/lib/Drupal/Component/Plugin/Discovery/DerivativeDiscoveryDecorator.php index 405a802..0cee170 100644 --- a/core/lib/Drupal/Component/Plugin/Discovery/DerivativeDiscoveryDecorator.php +++ b/core/lib/Drupal/Component/Plugin/Discovery/DerivativeDiscoveryDecorator.php @@ -204,18 +204,21 @@ protected function getDeriver($base_plugin_id, $base_definition) { */ protected function getDeriverClass($base_definition) { $class = NULL; + $id = NULL; if ($base_definition instanceof DerivablePluginDefinitionInterface) { $class = $base_definition->getDeriver(); + $id = $base_definition->id(); } if ((is_array($base_definition) || ($base_definition = (array) $base_definition)) && (isset($base_definition['deriver']))) { $class = $base_definition['deriver']; + $id = $base_definition['id']; } if ($class) { if (!class_exists($class)) { - throw new InvalidDeriverException(sprintf('Plugin (%s) deriver "%s" does not exist.', $base_definition['id'], $class)); + throw new InvalidDeriverException(sprintf('Plugin (%s) deriver "%s" does not exist.', $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.', $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 a243f35..07ba435 100644 --- a/core/tests/Drupal/Tests/Core/Plugin/Discovery/DerivativeDiscoveryDecoratorTest.php +++ b/core/tests/Drupal/Tests/Core/Plugin/Discovery/DerivativeDiscoveryDecoratorTest.php @@ -4,6 +4,7 @@ use Drupal\Component\Plugin\Definition\DerivablePluginDefinitionInterface; use Drupal\Component\Plugin\Discovery\DerivativeDiscoveryDecorator; +use Drupal\Component\Plugin\Exception\InvalidDeriverException; use Drupal\Tests\UnitTestCase; /** @@ -109,6 +110,26 @@ public function testGetDeriverClassWithClassedDefinitions() { } /** + * @covers ::getDeriverClass + */ + public function testGetDeriverClassWithInvalidClassedDefinitions() { + $definition = $this->prophesize(DerivablePluginDefinitionInterface::class); + $definition->id()->willReturn('non_existent_discovery'); + $definition->getDeriver()->willReturn('\Drupal\system\Tests\Plugin\NonExistentDeriver'); + + $definitions['non_existent_discovery'] = $definition->reveal(); + + $this->discoveryMain->expects($this->any()) + ->method('getDefinitions') + ->willReturn($definitions); + + $discovery = new DerivativeDiscoveryDecorator($this->discoveryMain); + + $this->setExpectedException(InvalidDeriverException::class, 'Plugin (non_existent_discovery) deriver "\Drupal\system\Tests\Plugin\NonExistentDeriver" does not exist.'); + $discovery->getDefinitions(); + } + + /** * Tests the getDerivativeFetcher method with a non-existent class. * * @see \Drupal\Component\Plugin\Discovery\DerivativeDiscoveryDecorator::getDeriver().\