DefaultSingleLazyPluginCollection::setConfiguration() accepts NULL but ConfigurableInterface::setConfiguration() does not

Created on 24 November 2023, over 1 year ago
Updated 14 December 2023, over 1 year ago

Problem/Motivation

Ran into this while working on πŸ“Œ Configuration schema & required values: add test coverage for `nullable: true` validation support Fixed .

signature \Drupal\Component\Plugin\ConfigurableInterface::setConfiguration(array $configuration) (note type hint)
πŸ†š
signature \Drupal\Component\Plugin\LazyPluginCollection::setConfiguration($configuration) (note NO type hint)
πŸ†š
\Drupal\Core\Plugin\DefaultSingleLazyPluginCollection::setConfiguration() implementation of LazyPluginCollection::setConfiguration():

  public function setConfiguration($configuration) {
    $this->configuration = $configuration;
    $plugin = $this->get($this->instanceId);
    if ($plugin instanceof ConfigurableInterface) {
      $plugin->setConfiguration($configuration);
    }
    return $this;
  }

Steps to reproduce

$block = Block::load('block.block.olivero_content');
$block->set('settings', NULL);
$typed_data = $this->container->get('typed_data_manager');
$definition = $typed_data->createDataDefinition('entity:block');
$violations = $typed_data->create($definition, $block)->validate();

Results in:

TypeError: Drupal\Core\Block\BlockBase::setConfiguration(): Argument #1 ($configuration) must be of type array, null given, called in /Users/wim.leers/core/core/lib/Drupal/Core/Plugin/DefaultSingleLazyPluginCollection.php on line 85

/Users/wim.leers/core/core/lib/Drupal/Core/Block/BlockPluginTrait.php:79
/Users/wim.leers/core/core/lib/Drupal/Core/Plugin/DefaultSingleLazyPluginCollection.php:85
/Users/wim.leers/core/core/lib/Drupal/Core/Config/Entity/ConfigEntityBase.php:165
…

Same problem in \Drupal\Core\Plugin\DefaultLazyPluginCollection::setConfiguration() (try visibility on

Proposed resolution

Make
\Drupal\Core\Plugin\DefaultSingleLazyPluginCollection::setConfiguration()
\Drupal\Core\Plugin\DefaultLazyPluginCollection::setConfiguration()
treat NULL as [] β€” see #8 for rationale.

Remaining tasks

None.

User interface changes

None.

API changes

None.

Data model changes

None.

Release notes snippet

N/A

πŸ› Bug report
Status

Fixed

Version

11.0 πŸ”₯

Component
PluginΒ  β†’

Last updated 22 minutes ago

Created by

πŸ‡§πŸ‡ͺBelgium wim leers Ghent πŸ‡§πŸ‡ͺπŸ‡ͺπŸ‡Ί

Live updates comments and jobs are added and updated live.
Sign in to follow issues

Merge Requests

Comments & Activities

Production build 0.71.5 2024