Issue #2824655 by tim.plunkett: Plugin definitions should store their class in a consistent manner (without leading slashes)
parent
9088257709
commit
ed4ad77a12
|
@ -63,6 +63,17 @@ class TypedConfigManager extends TypedDataManager implements TypedConfigManagerI
|
||||||
return $this->discovery;
|
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}
|
* {@inheritdoc}
|
||||||
|
|
|
@ -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));
|
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'.
|
// Add the module or theme path to the 'path'.
|
||||||
$provider = $definition->getProvider();
|
$provider = $definition->getProvider();
|
||||||
if ($this->moduleHandler->moduleExists($provider)) {
|
if ($this->moduleHandler->moduleExists($provider)) {
|
||||||
|
|
|
@ -240,13 +240,17 @@ class DefaultPluginManager extends PluginManagerBase implements PluginManagerInt
|
||||||
* method.
|
* method.
|
||||||
*/
|
*/
|
||||||
public function processDefinition(&$definition, $plugin_id) {
|
public function processDefinition(&$definition, $plugin_id) {
|
||||||
// Only arrays can be operated on.
|
// Only array-based definitions can have defaults merged in.
|
||||||
if (!is_array($definition)) {
|
if (is_array($definition) && !empty($this->defaults) && is_array($this->defaults)) {
|
||||||
return;
|
$definition = NestedArray::mergeDeep($this->defaults, $definition);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!empty($this->defaults) && is_array($this->defaults)) {
|
// Keep class definitions standard with no leading slash.
|
||||||
$definition = NestedArray::mergeDeep($this->defaults, $definition);
|
if ($definition instanceof PluginDefinitionInterface) {
|
||||||
|
$definition->setClass(ltrim($definition->getClass(), '\\'));
|
||||||
|
}
|
||||||
|
elseif (is_array($definition) && isset($definition['class'])) {
|
||||||
|
$definition['class'] = ltrim($definition['class'], '\\');
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -98,6 +98,7 @@ class EntityTypeManagerTest extends UnitTestCase {
|
||||||
|
|
||||||
// Give the entity type a legitimate class to return.
|
// Give the entity type a legitimate class to return.
|
||||||
$entity_type->getClass()->willReturn($class);
|
$entity_type->getClass()->willReturn($class);
|
||||||
|
$entity_type->setClass($class)->willReturn($entity_type->reveal());
|
||||||
|
|
||||||
$definitions[$key] = $entity_type->reveal();
|
$definitions[$key] = $entity_type->reveal();
|
||||||
}
|
}
|
||||||
|
|
|
@ -4,6 +4,7 @@ namespace Drupal\Tests\Core\Menu;
|
||||||
|
|
||||||
use Drupal\Core\Access\AccessResult;
|
use Drupal\Core\Access\AccessResult;
|
||||||
use Drupal\Core\Language\Language;
|
use Drupal\Core\Language\Language;
|
||||||
|
use Drupal\Core\Menu\ContextualLinkDefault;
|
||||||
use Drupal\Tests\UnitTestCase;
|
use Drupal\Tests\UnitTestCase;
|
||||||
use Symfony\Component\HttpFoundation\RequestStack;
|
use Symfony\Component\HttpFoundation\RequestStack;
|
||||||
|
|
||||||
|
@ -384,7 +385,7 @@ class ContextualLinkManagerTest extends UnitTestCase {
|
||||||
public function testPluginDefinitionAlter() {
|
public function testPluginDefinitionAlter() {
|
||||||
$definitions['test_plugin'] = array(
|
$definitions['test_plugin'] = array(
|
||||||
'id' => 'test_plugin',
|
'id' => 'test_plugin',
|
||||||
'class' => '\Drupal\Core\Menu\ContextualLinkDefault',
|
'class' => ContextualLinkDefault::class,
|
||||||
'title' => 'Plugin',
|
'title' => 'Plugin',
|
||||||
'weight' => 2,
|
'weight' => 2,
|
||||||
'group' => 'group1',
|
'group' => 'group1',
|
||||||
|
|
|
@ -438,6 +438,17 @@ class DefaultPluginManagerTest extends UnitTestCase {
|
||||||
'forms' => ['configure' => 'stdClass'],
|
'forms' => ['configure' => 'stdClass'],
|
||||||
'foo' => ['bar' => ['baz']],
|
'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;
|
return $data;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue