In an effort to future-proof our AnnotationClassDiscovery loading paradigm, we had to re-evaluate how annotation class were loaded. When finding classes to parse for annotations, we are looking for a particular annotation class to be in use. Previously, we had to inform the system WHERE to find this annotation class, which was difficult since we had to map directly to the directory. This was eased to some degree by the availability of all namespaces within to system, but was still not particularly good DX. As of this change, a developer need only specific the annotation class to use, and the system will determine where that class lives through typical class autloading paradigms. This means we can change out our autoloader without needing to worry about the loading of the annotation class going forward.
This change will require any contrib modules that are using Annotations for plugins to change the parameters they're passing, using the block plugin manager BlockManager as an example, it's pretty straight forward:
Old:
public function __construct(\Traversable $namespaces, CacheBackendInterface $cache_backend, LanguageManager $language_manager, ModuleHandlerInterface $module_handler, TranslationInterface $translation_manager) {
$annotation_namespaces = array('Drupal\block\Annotation' => $namespaces['Drupal\block']);
parent::__construct('Plugin/Block', $namespaces, $module_handler, $annotation_namespaces, 'Drupal\block\Annotation\Block');
$this->alterInfo('block');
$this->setCacheBackend($cache_backend, $language_manager, 'block_plugins');
$this->translationManager = $translation_manager;
}
New:
public function __construct(\Traversable $namespaces, CacheBackendInterface $cache_backend, LanguageManager $language_manager, ModuleHandlerInterface $module_handler, TranslationInterface $translation_manager) {
parent::__construct('Plugin/Block', $namespaces, $module_handler, 'Drupal\block\Annotation\Block');
$this->alterInfo('block');
$this->setCacheBackend($cache_backend, $language_manager, 'block_plugins');
$this->translationManager = $translation_manager;
}
We no longer need to parse out the annotation dir and pass it to the DefaultPluginManager, likewise manual use of the AnnotatedClassDiscovery will not require it. That parameter has been completely removed, from now on, just pass the name of the annotation class.
Note: The "New" example above serves primarily to reflect this particular change. The constructor signature of DefaultPluginManager (and subclasses) has since been altered further. See Plugin caching now not language dependent by default, include language in cache key as needed and Plugin factories check inheritance of plugins.