Skip to content
Snippets Groups Projects
Commit ed4ad77a authored by Alex Bronstein's avatar Alex Bronstein
Browse files

Issue #2824655 by tim.plunkett: Plugin definitions should store their class in...

Issue #2824655 by tim.plunkett: Plugin definitions should store their class in a consistent manner (without leading slashes)
parent 90882577
No related branches found
No related tags found
2 merge requests!7452Issue #1797438. HTML5 validation is preventing form submit and not fully...,!789Issue #3210310: Adjust Database API to remove deprecated Drupal 9 code in Drupal 10
......@@ -63,6 +63,17 @@ protected function getDiscovery() {
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}
......
......@@ -80,10 +80,6 @@ public function processDefinition(&$definition, $plugin_id) {
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)) {
......
......@@ -240,13 +240,17 @@ public function useCaches($use_caches = FALSE) {
* 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'], '\\');
}
}
......
......@@ -98,6 +98,7 @@ protected function setUpEntityTypeDefinitions($definitions = []) {
// 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();
}
......
......@@ -4,6 +4,7 @@
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 @@ public function testGetContextualLinksArrayByGroupAccessCheck() {
public function testPluginDefinitionAlter() {
$definitions['test_plugin'] = array(
'id' => 'test_plugin',
'class' => '\Drupal\Core\Menu\ContextualLinkDefault',
'class' => ContextualLinkDefault::class,
'title' => 'Plugin',
'weight' => 2,
'group' => 'group1',
......
......@@ -438,6 +438,17 @@ public function providerTestProcessDefinition() {
'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;
}
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment