Problem/Motivation
The Seeds Widgets module currently uses static service calls (\Drupal::service()) and doesn't follow Drupal best practices for dependency injection. This makes the code:
Harder to test with unit tests
Difficult to override services
Non-compliant with Drupal coding standards
Harder to maintain
Proposed resolution
Implement proper dependency injection across the entire module:
1. Field Formatters (8 files)
Implement ContainerFactoryPluginInterface in all formatters
Inject
SeedsWidgetsManager
and EntityTypeManagerInterface
Inject ConfigFactoryInterface for CarouselFormatter and SliderFormatter
Use injected services instead of static calls
2. SeedsWidgetsManager Service
Inject: Renderer, ImageFactory, CurrentRouteMatch, ConfigFactoryInterface, EntityDisplayRepositoryInterface
Update service definition in
seeds_widgets.services.yml
3. BlocksTabsBlock Plugin
Inject: BlockManagerInterface, ContextRepositoryInterface, UuidInterface
Convert
addMoreCallback()
from static to instance method
Fix service locator anti-pattern
4. ParagraphViewModesForm
Inject EntityDisplayRepositoryInterface
Use injected service in form methods
Comments
Comment #3
ahmad-alyasaki commented