Problem/Motivation
I have a Drupal 10.1.4 and when I installed the latest 4.x version of the module (in my case 4.0.0-alpha9) I get the following error while performing a drush cr
:
Fatal error: Uncaught TypeError: Drupal\Core\Plugin\DefaultPluginManager::__construct(): Argument #6 ($additional_annotation_namespaces) must be of type array, string given, called in /app/web/sites/sgeshop/modules/contrib/computed_field/
src/ComputedFieldManager.php on line 41 and defined in /app/web/core/lib/Drupal/Core/Plugin/DefaultPluginManager.php:130
Looking at the source code of computed_field/src/ComputedFieldManager.php
I found this:
class ComputedFieldManager extends DefaultPluginManager {
/**
* Constructs a new ComputedFieldManagerManager.
*
* @param \Traversable $namespaces
* An object that implements \Traversable which contains the root paths
* keyed by the corresponding namespace to look for plugin implementations.
* @param \Drupal\Core\Cache\CacheBackendInterface $cache_backend
* The cache backend.
* @param \Drupal\Core\Extension\ModuleHandlerInterface $module_handler
* The module handler.
*/
public function __construct(
\Traversable $namespaces,
CacheBackendInterface $cache_backend,
ModuleHandlerInterface $module_handler
) {
parent::__construct(
'Plugin/ComputedField',
$namespaces,
$module_handler,
ComputedFieldPluginInterface::class,
ComputedField::class,
ComputedFieldAnnotation::class
);
$this->alterInfo('computed_field_info');
$this->setCacheBackend($cache_backend, 'computed_field_plugins');
}
The class extends Drupal\Core\Plugin\DefaultPluginManager
. If you look at the documentation constructor documentation the 6th parameter is an array()
while here it's declared as ComputedFieldAnnotation::class
which is incompatible. Hence the error.
Steps to reproduce
Install the module via composer and run drush cr
.
Proposed resolution
Probably change the parameter to an array()
. I changed it and it seems to work but haven't tested the modules work correctly (yet).