Questions tagged [dependency-injection]

Use it for questions about implementing the software design pattern that implements inversion of control.

16 questions with no upvoted or accepted answers
Filter by
Sorted by
Tagged with
3
votes
0answers
558 views

How can I use TwigExtension from an existing symfony bundle?

UPDATED Context I'm using Symfony Webpack Encore to take care of all the JS and CSS postprocessing, transpiling and so on... There are different ways to implement webpack, even a module, Webpack ...
3
votes
0answers
105 views

Design help for serialized classes that need database access

I want to convert from \Drupal::database() to dependency injection. I'm not 100% certain how to move forward with a refactor I know I have to complete. Currently I have a series of custom classes ...
1
vote
1answer
76 views

New module service is dependency on old module service - The service has a dependency on a non-existent service

I have a new module moduleB. It defines a service that is used in the dependency injection of moduleA. moduleA is already enabled, its changes are just to the services definition. The info.yml has ...
1
vote
1answer
40 views

Missing proxy classes when container compiles custom ExtensionPass

Context I try to find a way to integrate Webpack Encore into Drupal. Since we can't use Symfony Bundles in Drupal I want to port the bundle to a custom Drupal module. What I have done so far To ...
1
vote
2answers
113 views

Issue with the cognito module

I am running into the below issue : The website encountered an unexpected error. Please try again later.InvalidArgumentException: Class "\Drupal\cognito\Form\Email\UserLoginForm" does ...
1
vote
1answer
163 views

How to instantiate a service inside ServiceProvider?

I need to instantiate a service inside ServiceProvider. At that point the container is not built. Any ideas or useful links? <?php namespace Drupal\my_module; use Drupal\Core\...
1
vote
0answers
1k views

How to understand and fix a Reflection does not exist error?

I am trying to get my head around using EventSubscriber for adding HTTP Headers. In D7 I would have simply used drupal_add_http_header('Content-Type', 'application/javascript'); But I see that this ...
1
vote
0answers
16 views

How to show different options for a dependent field

I've 2 options for a dependent field, I would like to show only one option from the dependent field, when the dependees field has a particular value. Dependees is a radio button. If the value is '...
0
votes
0answers
59 views

How to use methods from entity class if it doesn't have such service?

I'm writing an EventSubscriber for the config entity of the domain module. My goal is to insert some data in its config on preSave event (it becomes from the patch for D9). Here is my code from ...
0
votes
0answers
45 views

Use Injected CacheBackedInterface to invalidate certain bin

I've got a content type called SERVICE (I write it all capitalized to prevent mixture with drupal service) which admin can introduce different SERVICE using this type, it is expected that these ...
0
votes
0answers
55 views

Discover custom services with drush generate

When I create a module and a custom service with drush generate and then create another service, also with drush generate, the first one is not available to inject. What is missing to make it become ...
0
votes
0answers
70 views

After installing and configuring simplesamlphp_auth module gives Error on clearing cache

I installed simplesamlphp_auth(8x-3.2) module with drupal (9.1.x). SimpleSAMLphp (1.18.8) is configured correctly. saml authentication works fine, but while clearing cache i am getting the below error....
0
votes
1answer
64 views

How to use service container correcly?

I want to use service container inside my class so I have this this: class SomeController extends ControllerBase { protected $entityTypeManager; protected $requestStack; public function ...
0
votes
0answers
256 views

dependency injection by using $this when not in object context

if i´m using the codesniffer function i´m getting two warnings about: 155 | WARNING | \Drupal calls should be avoided in classes, use dependency injection instead If i´m changing the line from: $...
0
votes
0answers
423 views

Using a class to call a call a custom drush service

I have created a drush service and I can use it on the command line, but I am trying to use dependency injection to use it from another class. However, it is saying that the service cannot be found. (...
0
votes
0answers
175 views

Issue when trying to create service from ContentEntity subclass and inject into another class

I have a class ApplicationForm that extends ContentEntity. In my other class ApplicationFormForm (Poorly named, I know) I extend ContentEntityForm which in turn inherits from EntityForm. In one of ...