Questions tagged [symfony-services]

The tag has no usage guidance.

Filter by
Sorted by
Tagged with
0
votes
0answers
17 views

How do I configure Scout APM?

Their docs have setup instructions for Symfony, but I'm not sure how they translate to Drupal: https://scoutapm.com/docs/php/symfony. Could anybody provide some insight on how the xml/bundle ...
1
vote
2answers
91 views

Injecting a NEW instance of a service into another service class

I have a service (for sending error alerts) which is used by multiple other services. The alert service is injected into those classes via the relevant services.yml files and through their ...
0
votes
1answer
41 views

Site error on Drupal 9 on Acquia Dev Desktop [closed]

I am working on the Packt book Drupal 9 Module Development I finished the chapter 3 Here is the Github Link to the code When I call an url of admin part of my Drupal (I wanted to clear the cache) I ...
1
vote
1answer
117 views

Return a Closure from a Factory

I have services that depend on request information. I'm trying to create a Factory Factory which will have the Dependency Injection container returns a factory (an anonymous function) that will create ...
1
vote
2answers
224 views

How to alter the parameters in the core.services.yml file programatically?

I need to modify the filter_protocols parameter inside the core.services.yml file programmatically to add a new protocol. I know how to alter a service but I don't find any information about how to ...
1
vote
1answer
78 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
47 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
1answer
101 views

How to inherit base class dependencies without redefining theme in child class service arguments?

The current system I have a set of services classes that extends the same base class ex: class NodeHandler extends ContentEntityHandlerBase {} class ParagraphHandler extends ContentEntityHandlerBase {}...
0
votes
1answer
204 views

Are service autowiring and class autoresolving not anymore supported?

In Drupal 8, I needed to define services via the mymodule.services.yml file only, if I wanted to use them via the service container. I could also autowire them and the classes were automatically ...
1
vote
0answers
57 views

Database password revealed in PHP error_log?

Noticed some errors while updating to Drupal 8.9.11. As I'm reviewing I come across the following. Replaced the actual password with PASSWORD below. Is this intentional or a bug? I can't see why the ...
2
votes
1answer
125 views

How to inject an object into a service?

I need to do a couple of things: Inject guzzle's httpclient into class A Inject class A into my service What I've tried so far: services: my_module.field_fetcher: class: Drupal\my_module\...
1
vote
2answers
596 views

How do I pass dynamic parameters to a service?

Is it possible to pass dynamic parameters when calling a service? mymodule.services.yml services: my_module.default: class: Drupal\services\DefaultService arguments: ['@entity_type.manager'] ...
-1
votes
1answer
46 views

How to get $_POST which has blank parameters [closed]

I understand that as per new rules, post request in drupal should be replaced with $stack->getCurrentRequest()->request; But I need to know what is the replacement for $_POST which does not ...
0
votes
1answer
34 views

What is the syntax for using a contrib module's service from within a hook implementation?

I'm trying to get a list of objects from AWS using the S3fsService from the S3 File System module from within a hook_cron() implementation. The following code works: // Fetch list of files in S3. $...
0
votes
2answers
174 views

Drupal 8 service dependency injection [closed]

I am trying to build a service that will leverage the Pathauto service so my class looks like this. namespace Drupal\some_system; use Drupal\pathauto\PathautoGenerator; use Drupal\pathauto\...
-1
votes
1answer
428 views

Web service APIs returns HTML content instead of JSON response

I have used Drupal 7 before and the web services were working perfectly fine. I recently started working on Drupal 8 (8.8 to be precise), and the login service is not working properly. When I do not ...
0
votes
1answer
127 views

Replace \Drupal::service with Dependency injection in FieldWidget class

I have created an ajax callback inside a custom Field Widget plugin. In the Ajax callback I have called a custom service using $service = \Drupal::service('service.name') I am using phpmd to clean ...
1
vote
0answers
35 views

Can we have multiple Normalizers in REST API?

I have a requirement of exposing multiple content type data via different REST end point. I am using Normalizers to create an array as expected. For one content type it works perfect but when i try to ...
2
votes
1answer
303 views

$base_root problem

In /core/lib/Drupal/Core/DrupalKernal.php the $base_root shows incorrect value: Line 1113 protected function initializeRequestGlobals(Request $request) { global $base_url; // Set and ...
0
votes
0answers
295 views

How to override a service provided by a contrib module?

I need to override Validator class from Telephone Validations contrib module. I tried the both static and dynamic methods described here: https://www.drupal.org/docs/8/api/services-and-dependency-...
0
votes
1answer
195 views

How to override a service

I am trying to override a service by using a ServiceProvider Class class MyModuleServiceProvider extends ServiceProviderBase { public function alter(ContainerBuilder $container) { // ...
1
vote
1answer
57 views

Difference between creating a Rest endpoint and a route&controller with jsonResponse

What is the difference between creating a Rest plugin with the Rest API and creating a route/controller that returns a jsonResponse ? In which case i have to create a custom route/controller with a ...
0
votes
1answer
287 views

Symfony's getQueryString method doesn't return modified query parameters

Symfony's getQueryString method doesn't return modified query parameters. So how should someone go about getting a modified query parameter string? Example code: $request = \Drupal::request(); ...
2
votes
2answers
74 views

What good is the create() method? [closed]

Most classes are instantiated using create($container) and __construct(...$services) in conjunction, it seems that the more efficient workflow would be to simply pass the container to the constructor ...
5
votes
1answer
425 views

What is the right way of loading a service?

when trying to use a service in drupal actually there is 3 ways , what is the preferred way to use a service and why : passing dependencies directly through the constructor: public function ...
3
votes
0answers
586 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 ...
1
vote
1answer
114 views

Set parent service when registering a service in a ServiceProvider

I want to create dynamic services, therefore I added a ServiceProvider class to my module. I have created a base service that my other services will have as parent. When doing this in my_module....
0
votes
1answer
78 views

Why all core services cannot be registered in core.services.yaml?

DrupalKernel Building of Dependency Injection Container and registration of Service Providers Core provides the CoreServiceProvider, which, in addition to registering any core services that cannot ...
1
vote
0answers
187 views

Get all services that are tagged with a specific tag in *.services.yml

Is there an easy (supported) way to programatically get all services in Drupal 8 that are tagged with a specific tag? For example getting all services that are tagged with "breadcrumb_builder" tag ...
0
votes
2answers
147 views

How add pager with external request

After many search and read posts, I'm still stuck with my code. Let me explain : I created a custom module who display newsletters from Mailjet and old newsletters comming from drupal. To avoid the ...
1
vote
2answers
504 views

How can I make a response cachable by browsers?

I am working on a Drupal Controller implementation that would return a generated image as response. I used Symfony's Response and I was trying to add ETag header to it: use Drupal\Core\Controller\...
2
votes
0answers
84 views

Why is @? used when referring router.request_context?

In core.services.yml we have: calls: - [setContext, ['@?router.request_context']] But router.request_context is also defined in core.services.yml (and it depends on request_stack alone which doesn'...
0
votes
0answers
47 views

Update Symfony before Drupal core?

Right now there are some security updates for Symfony: curl -sS https://get.symfony.com/cli/installer | bash echo y | ~/.symfony/bin/symfony self:update ~/.symfony/bin/symfony security:check Symfony ...
1
vote
1answer
990 views

Problem in dependency injection in drupal custom module service

I face with a problem in defining service in drupal 8.0 my service is : services: tracking.middleware: class: Drupal\mkt_tracking_v2\Middleware\TrackingMiddleware arguments: ['@kernel','@...
0
votes
2answers
651 views

Add parameter to the URL based on a field value

Is it possible to append a campaign tracking code to the requested URL basing on a specific field value on the linked node? I'm trying to use a path_processor_outbound service, but it doesn't work ...
3
votes
0answers
651 views

How to get environment variables in a service container? [closed]

According to the Symfony documentation, env() parameters were introduced in version 3.2, allowing to use environment variables in service container configuration: # app/config/config.yml doctrine: ...
0
votes
1answer
263 views

Instantiate Controller with Interface not concrete class [closed]

As background, I am rebuilding some old code and want to wrap all the curl based requests in an interface (HttpRequestInterface) so I can swap that out later without having to write all the api calls ...
1
vote
1answer
109 views

How to define event listener in the service?

In Drupal 8 is possible to use event subscriber that is the separate class that defines the callback that should be called on the defined event. See Event Systems Overview & How To Subscribe To ...
2
votes
2answers
6k views

How can I log(watchdog)?

In D7 is used to log using Watchdog function. In D8, I see its gone and I should use something called the logging API. What I a trying to do: I have created a menu/route, mysite.com/logmessage When ...
0
votes
1answer
2k views

InvalidArgumentException: Cannot redirect to an empty URL. in Symfony

Pages are not shwoing up. They display the follwoing error: InvalidArgumentException: Cannot redirect to an empty URL. in Symfony\Component\HttpFoundation\RedirectResponse->setTargetUrl() (line 86 of ...
3
votes
1answer
370 views

How can I inject a different service in an existing one, i.e. exchange one already injected service by an own one?

The basic authentication provider service uses the user.auth service: basic_auth.authentication.basic_auth: class: Drupal\basic_auth\Authentication\Provider\BasicAuth arguments: ['@config....
0
votes
2answers
2k views

Dependency injection or \Drupal class methods?

Suppose I have an ExampleService class and I need a service (current_user) to process my logic. So I have implemented my service like this. The way 1: DI standard Drupal namespace Drupal\...
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 ...
13
votes
2answers
4k views

When should I create a service or a utility function?

I had this question in mind along all the last week: When I should create a service or an utility function? In the Drupal Core we have both Services and Utility functions, but I can't find the ...
8
votes
1answer
3k views

how to unit test an http client service with DI in drupal 8?

I have a service the consumes data from an external source. I would like to unit test the service and I am not sure how to get the test set up. To start with I would like to just test 1 method. Here ...
1
vote
1answer
66 views

Can a Event Service be coupled to a route

I have created a custom service and have hooked into the "event_subscriber" via tags in my custom service.yml demo_api.exception_handler_subscriber: class: Drupal\demo_api\Response\Handler ...
7
votes
1answer
2k views

How to inject a service in another service?

I am building a custom service, a membership service. This service can be called from a controller. But what I don't seem to get working, is to use another service, the QueryFactory, to use in that ...
16
votes
4answers
23k views

How do I set up CORS?

Drupal 8 has RESTful web service in-built in core and since 8.2 we don't need cors module. Now to use services we just enable and configure default.service.yml file as specified in here However, I ...
3
votes
0answers
111 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 ...