Unverified Commit 390e3e00 authored by larowlan's avatar larowlan
Browse files

Issue #3240909 by andypost, alexpott, tim.plunkett: Plugin definitions with no...

Issue #3240909 by andypost, alexpott, tim.plunkett: Plugin definitions with no class trigger deprecations on PHP 8.1
parent 241acb9c
......@@ -246,6 +246,7 @@ public function processDefinition(&$definition, $plugin_id) {
// Keep class definitions standard with no leading slash.
if ($definition instanceof PluginDefinitionInterface) {
assert(is_string($definition->getClass()), 'Plugin definitions must have a class');
$definition->setClass(ltrim($definition->getClass(), '\\'));
}
elseif (is_array($definition) && isset($definition['class'])) {
......
......@@ -126,10 +126,10 @@ public function testLoadNull() {
*/
public function testFindDefinitions() {
$this->discovery->getDefinitions()->willReturn([
'plugin1' => new SectionStorageDefinition(),
'plugin2' => new SectionStorageDefinition(['weight' => -5]),
'plugin3' => new SectionStorageDefinition(['weight' => -5]),
'plugin4' => new SectionStorageDefinition(['weight' => 10]),
'plugin1' => (new SectionStorageDefinition())->setClass(SectionStorageInterface::class),
'plugin2' => (new SectionStorageDefinition(['weight' => -5]))->setClass(SectionStorageInterface::class),
'plugin3' => (new SectionStorageDefinition(['weight' => -5]))->setClass(SectionStorageInterface::class),
'plugin4' => (new SectionStorageDefinition(['weight' => 10]))->setClass(SectionStorageInterface::class),
]);
$expected = [
......@@ -156,9 +156,9 @@ public function testFindByContext($plugin_is_applicable) {
'foo' => new Context(new ContextDefinition('foo')),
];
$definitions = [
'no_access' => new SectionStorageDefinition(),
'missing_contexts' => new SectionStorageDefinition(),
'provider_access' => new SectionStorageDefinition(),
'no_access' => (new SectionStorageDefinition())->setClass(SectionStorageInterface::class),
'missing_contexts' => (new SectionStorageDefinition())->setClass(SectionStorageInterface::class),
'provider_access' => (new SectionStorageDefinition())->setClass(SectionStorageInterface::class),
];
$this->discovery->getDefinitions()->willReturn($definitions);
......@@ -211,8 +211,8 @@ public function testFindByContextCacheableSectionStorage() {
];
$definitions = [
'first' => new SectionStorageDefinition(),
'second' => new SectionStorageDefinition(),
'first' => (new SectionStorageDefinition())->setClass(SectionStorageInterface::class),
'second' => (new SectionStorageDefinition())->setClass(SectionStorageInterface::class),
];
$this->discovery->getDefinitions()->willReturn($definitions);
......
......@@ -11,6 +11,7 @@
use Drupal\Core\Extension\ThemeHandlerInterface;
use Drupal\Core\Layout\LayoutDefault;
use Drupal\Core\Layout\LayoutDefinition;
use Drupal\Core\Layout\LayoutInterface;
use Drupal\Core\Layout\LayoutPluginManager;
use Drupal\Core\StringTranslation\TranslatableMarkup;
use Drupal\Tests\UnitTestCase;
......@@ -404,6 +405,7 @@ public function getDerivativeDefinitions($base_plugin_definition) {
'id' => 'invalid_provider',
'provider' => 'invalid_provider',
]);
$this->derivatives['invalid_provider']->setClass(LayoutInterface::class);
}
return $this->derivatives;
}
......
......@@ -511,6 +511,8 @@ class ObjectDefinition extends PluginDefinition {
* @param array $definition
*/
public function __construct(array $definition) {
// This class does not exist but plugin definitions must provide a class.
$this->class = 'PluginObject';
foreach ($definition as $property => $value) {
$this->{$property} = $value;
}
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment