diff --git a/core/lib/Drupal/Core/Config/TypedConfigManager.php b/core/lib/Drupal/Core/Config/TypedConfigManager.php index c347e1585e9b..802f9688cb27 100644 --- a/core/lib/Drupal/Core/Config/TypedConfigManager.php +++ b/core/lib/Drupal/Core/Config/TypedConfigManager.php @@ -63,6 +63,17 @@ class TypedConfigManager extends TypedDataManager implements TypedConfigManagerI return $this->discovery; } + /** + * {@inheritdoc} + */ + public function processDefinition(&$definition, $plugin_id) { + parent::processDefinition($definition, $plugin_id); + + // Typed config definitions assume a leading slash, see ::hasConfigSchema(). + if (is_array($definition) && isset($definition['class'])) { + $definition['class'] = '\\' . $definition['class']; + } + } /** * {@inheritdoc} diff --git a/core/lib/Drupal/Core/Layout/LayoutPluginManager.php b/core/lib/Drupal/Core/Layout/LayoutPluginManager.php index bc8b67662fd6..e5a88dea00df 100644 --- a/core/lib/Drupal/Core/Layout/LayoutPluginManager.php +++ b/core/lib/Drupal/Core/Layout/LayoutPluginManager.php @@ -80,10 +80,6 @@ class LayoutPluginManager extends DefaultPluginManager implements LayoutPluginMa throw new InvalidPluginDefinitionException($plugin_id, sprintf('The "%s" layout definition must extend %s', $plugin_id, LayoutDefinition::class)); } - // Keep class definitions standard with no leading slash. - // @todo Remove this once https://www.drupal.org/node/2824655 is resolved. - $definition->setClass(ltrim($definition->getClass(), '\\')); - // Add the module or theme path to the 'path'. $provider = $definition->getProvider(); if ($this->moduleHandler->moduleExists($provider)) { diff --git a/core/lib/Drupal/Core/Plugin/DefaultPluginManager.php b/core/lib/Drupal/Core/Plugin/DefaultPluginManager.php index 294e08b43d83..8622db997ba6 100644 --- a/core/lib/Drupal/Core/Plugin/DefaultPluginManager.php +++ b/core/lib/Drupal/Core/Plugin/DefaultPluginManager.php @@ -240,13 +240,17 @@ class DefaultPluginManager extends PluginManagerBase implements PluginManagerInt * method. */ public function processDefinition(&$definition, $plugin_id) { - // Only arrays can be operated on. - if (!is_array($definition)) { - return; + // Only array-based definitions can have defaults merged in. + if (is_array($definition) && !empty($this->defaults) && is_array($this->defaults)) { + $definition = NestedArray::mergeDeep($this->defaults, $definition); } - if (!empty($this->defaults) && is_array($this->defaults)) { - $definition = NestedArray::mergeDeep($this->defaults, $definition); + // Keep class definitions standard with no leading slash. + if ($definition instanceof PluginDefinitionInterface) { + $definition->setClass(ltrim($definition->getClass(), '\\')); + } + elseif (is_array($definition) && isset($definition['class'])) { + $definition['class'] = ltrim($definition['class'], '\\'); } } diff --git a/core/tests/Drupal/Tests/Core/Entity/EntityTypeManagerTest.php b/core/tests/Drupal/Tests/Core/Entity/EntityTypeManagerTest.php index c2325d423909..43464d14fbec 100644 --- a/core/tests/Drupal/Tests/Core/Entity/EntityTypeManagerTest.php +++ b/core/tests/Drupal/Tests/Core/Entity/EntityTypeManagerTest.php @@ -98,6 +98,7 @@ class EntityTypeManagerTest extends UnitTestCase { // Give the entity type a legitimate class to return. $entity_type->getClass()->willReturn($class); + $entity_type->setClass($class)->willReturn($entity_type->reveal()); $definitions[$key] = $entity_type->reveal(); } diff --git a/core/tests/Drupal/Tests/Core/Menu/ContextualLinkManagerTest.php b/core/tests/Drupal/Tests/Core/Menu/ContextualLinkManagerTest.php index b3f01517fa33..db0657845a09 100644 --- a/core/tests/Drupal/Tests/Core/Menu/ContextualLinkManagerTest.php +++ b/core/tests/Drupal/Tests/Core/Menu/ContextualLinkManagerTest.php @@ -4,6 +4,7 @@ namespace Drupal\Tests\Core\Menu; use Drupal\Core\Access\AccessResult; use Drupal\Core\Language\Language; +use Drupal\Core\Menu\ContextualLinkDefault; use Drupal\Tests\UnitTestCase; use Symfony\Component\HttpFoundation\RequestStack; @@ -384,7 +385,7 @@ class ContextualLinkManagerTest extends UnitTestCase { public function testPluginDefinitionAlter() { $definitions['test_plugin'] = array( 'id' => 'test_plugin', - 'class' => '\Drupal\Core\Menu\ContextualLinkDefault', + 'class' => ContextualLinkDefault::class, 'title' => 'Plugin', 'weight' => 2, 'group' => 'group1', diff --git a/core/tests/Drupal/Tests/Core/Plugin/DefaultPluginManagerTest.php b/core/tests/Drupal/Tests/Core/Plugin/DefaultPluginManagerTest.php index 4ced54701991..0a6e8d4c8717 100644 --- a/core/tests/Drupal/Tests/Core/Plugin/DefaultPluginManagerTest.php +++ b/core/tests/Drupal/Tests/Core/Plugin/DefaultPluginManagerTest.php @@ -438,6 +438,17 @@ class DefaultPluginManagerTest extends UnitTestCase { 'forms' => ['configure' => 'stdClass'], 'foo' => ['bar' => ['baz']], ]; + + $data['class_with_slashes'][] = [ + 'class' => '\Drupal\Tests\Core\Plugin\TestPluginForm', + ]; + $data['class_with_slashes'][] = [ + 'class' => 'Drupal\Tests\Core\Plugin\TestPluginForm', + 'foo' => ['bar' => ['baz']], + ]; + + $data['object_with_class_with_slashes'][] = (new PluginDefinition())->setClass('\Drupal\Tests\Core\Plugin\TestPluginForm'); + $data['object_with_class_with_slashes'][] = (new PluginDefinition())->setClass('Drupal\Tests\Core\Plugin\TestPluginForm'); return $data; }