drupal/core-annotation has a hidden dependency on drupal/core-class-finder

Created on 8 November 2023, 7 months ago
Updated 12 December 2023, 6 months ago

Problem/Motivation

I'm using the Drupal component "drupal/core-annotation" in a custom project and after I updated all its dependencies and tried to run the project, I got the following error:

Fatal error: Uncaught Error: Interface "Drupal\Component\ClassFinder\ClassFinderInterface" not found in /myproject/vendor/drupal/core-annotation/Reflection/MockFileFinder.php:15

Drupal\Component\Annotation\Reflection\MockFileFinder extends Drupal\Component\ClassFinder\ClassFinderInterface, but "drupal/core-class-finder" is not listed as dependency in the composer.json of "drupal/core-annotation".

Steps to reproduce

  1. Create a composer based project that depends on "drupal/core-annotation".
  2. Create an annotation class.
  3. Create a plugin interface extending \Drupal\Component\Plugin\PluginInspectionInterface.
  4. Create plugin base class extending \Drupal\Component\Plugin\PluginBase and implementing the just created interface.
  5. Create a plugin manager class that sets the discovery property to an instance of \Drupal\Component\Annotation\Plugin\Discovery\AnnotatedClassDiscovery and the factory property to an instance of \Drupal\Component\Plugin\Factory\DefaultFactory. Pass the plugin interface name as second parameter when constructing DefaultFactory.
  6. Create a plugin class that uses annotation. Name it for example 'bar'.
  7. Try to instantiate the plugin as follows:
    \Drupal\Component\FileCache\FileCacheFactory::setPrefix('foo');
    $manager = new \MyProject\PluginManager();
    $manager->createInstance('bar');
    

Proposed resolution

Add "drupal/core-class-finder" to the composer.json of "drupal/core-annotation".

Remaining tasks

User interface changes

API changes

Data model changes

Release notes snippet

MR for 10.1.x will follow.

πŸ› Bug report
Status

Fixed

Version

10.1 ✨

Component
PluginΒ  β†’

Last updated about 17 hours ago

Created by

πŸ‡³πŸ‡±Netherlands MegaChriz

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

Merge Requests

Comments & Activities

Production build 0.69.0 2024