By catch on
Change record status:
Published (View all published change records)
Project:
Introduced in branch:
11.1.x
Introduced in version:
11.1.0
Issue links:
Description:
The addCachedDiscovery() method was removed from the CachedDiscoveryClearerInterface. Drupal 11.1 stopped calling the addCachedDiscovery() method during construction of the plugin.cache_clearer service. Instead, a tagged iterator is injected into CachedDiscoveryClearer constructor.
Implementations of CachedDiscoveryClearerInterface should follow that example and remove their addCachedDiscovery() methods as well and use the #[AutowireIterator(tag: 'plugin_manager_cache_clear')] attribute in their constructor. Note, that this requires autowire: true on the service definition as well.
Before
class CachedDiscoveryClearer implements CachedDiscoveryClearerInterface {
/**
* The stored discoveries.
*
* @var \Drupal\Component\Plugin\Discovery\CachedDiscoveryInterface[]
*/
protected $cachedDiscoveries = [];
/**
* {@inheritdoc}
*/
public function addCachedDiscovery(CachedDiscoveryInterface $cached_discovery) {
$this->cachedDiscoveries[] = $cached_discovery;
}
After
class CachedDiscoveryClearer implements CachedDiscoveryClearerInterface {
/**
* Constructs the CachedDiscoveryClearer service.
*
* @param \Traversable $cachedDiscoveries
* The cached discoveries.
*/
public function __construct(
#[AutowireIterator(tag: 'plugin_manager_cache_clear')]
protected \Traversable $cachedDiscoveries,
) {}
Impacts:
Module developers