Skip to main content

Questions tagged [symfony-services]

Filter by
Sorted by
Tagged with
1 vote
0 answers
59 views

Symfony Process in background does not execute as expected in Drupal 9

I am implementing a custom queue worker in a Drupal 9 project. When a user visits a page, I enqueue an item and immediately trigger Drush to process the queue in the background using Symfony Process. ...
Francesco Marchetti-Stasi's user avatar
4 votes
1 answer
270 views

Do I still need to create() services with PHP v8 constructor promotion?

PHP v8 supports constructor property promotion, which greatly uses boilerplate code. But basically all Drupal services use a factory pattern with a __construct() and a create() function. Is the create(...
Hudri's user avatar
  • 5,204
0 votes
1 answer
158 views

Inject a class as depency injection in a service

I just want to inject a custom module class A as a dependency injection for a custom service. I tried but I failed. Can any one please guide me. I'm using Drupal version 10. Here is my code. moduleb....
zed Blackbeard's user avatar
0 votes
1 answer
517 views

How do I implement email dispatch with Drupal Symfony Mailer from scratch?

I'm implementing a cron job that should send a notification email to all users that meet a certain criterion. I created a Service implementing the CronInterface and hook_cron calls this service's run()...
flauschi's user avatar
0 votes
1 answer
122 views

How can I identify the service ID?

I am trying to use Cdn service provided in CDN module version 4.0.1 in my custom module Until 3.x version we had service id as cdn.settings But from 4.x version I can see there is no service id https:/...
harshal's user avatar
  • 4,354
0 votes
2 answers
418 views

menu.tree_storage service is missing from my site

I have upgraded my Drupal 9 site to Drupal 10.1. One of my custom module uses \Drupal::service('menu.tree_storage')->loadByProperties(); which works fine in drupal 9.5.9, but I get the following ...
hobbsie's user avatar
  • 53
1 vote
2 answers
276 views

Why is the service “@url_helper” not found?

I am trying to add the query string with the each URL access through the browser. To accomplish it, trying to implement that through the service. But getting no solution in Drupal 9. mymodule.services....
user110018's user avatar
0 votes
1 answer
136 views

What is the backend_overridable service tag usable for?

On some core services, I see they have a tag of backend_overridable. I see this changelog, but is there an example? https://www.drupal.org/node/2306083 Is that essentially what something like Memcache ...
Kevin's user avatar
  • 28k
0 votes
1 answer
408 views

How to use a Controller method inside a service with dependency injection?

I'm using the diff module for a project, this module has a method inside a Controller that I want to use in a service to reuse code. As this time I'm just calling the method like ...
Adrian Cid Almaguer's user avatar
1 vote
1 answer
133 views

Service continues to act as shared when shared is set to false

According to Symfony docs, doing shared: false on a service should mean that each time you call a service, you get a new instance. However, this doesn't seem to work for me. I am using Drupal 9 which ...
pixel5's user avatar
  • 106
-1 votes
1 answer
709 views

Class not found for service in custom module [closed]

I am trying to create an event subscriber service in a custom module and I keep getting a "Class not found" error. The module directory is modules/custom/avgc The class is in src/...
F Grassi's user avatar
0 votes
0 answers
193 views

How to change order items in autocomplete entity?

I override alter autocomplete in my custom module but I don't know how I can change the display order (DESC or ASC) <?php namespace Drupal\alter_entity_autocomplete; use Drupal\Component\Utility\...
L.wadii's user avatar
2 votes
1 answer
260 views

addViolation() is deprecated: how to replace it?

How to adapt the following code to avoid the deprecation of addViolation() according to https://www.drupal.org/node/3238432 ? class MyValidator extends ConstraintValidator { public function ...
Baud's user avatar
  • 542
5 votes
1 answer
343 views

Extending contrib module filelog service class displays PSR implementation error

I wanted to override the logger.filelog service from filelog module to make use of my own parser. An error occurred through drush cim and drush cr when the new custom module that overrides the service ...
Michael Chen's user avatar
1 vote
0 answers
102 views

Injecting service into another service does not work

I have to override pagecache service in order to have some custom validation logic to be executed for anonymous users. The issue is that I have the domain module's service domain.negotiator to be ...
Jaswin Singh's user avatar
4 votes
1 answer
699 views

non-existent service, yet cache is cleared and module is enabled

I'm trying to access a Drupal service for normalizing content, yet the service is non-existent, even though the module "hal" is enabled and the service is defined. How can I get the service &...
alberto56's user avatar
  • 234
1 vote
2 answers
957 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 ...
Geat's user avatar
  • 463
0 votes
1 answer
61 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 ...
Jean-Pierre Mena's user avatar
1 vote
1 answer
294 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 ...
dickwan's user avatar
  • 111
1 vote
2 answers
856 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 ...
Adrian Cid Almaguer's user avatar
1 vote
1 answer
336 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 ...
Christian's user avatar
  • 801
1 vote
1 answer
214 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 ...
remoteclient's user avatar
1 vote
1 answer
858 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 {}...
Marwen Amri's user avatar
0 votes
1 answer
596 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 ...
jepster's user avatar
  • 971
1 vote
0 answers
107 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 ...
Jeff's user avatar
  • 93
2 votes
1 answer
1k 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\...
Jordan's user avatar
  • 49
1 vote
2 answers
4k 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'] ...
Giuseppe's user avatar
  • 1,125
-1 votes
1 answer
108 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 ...
sanket jain's user avatar
0 votes
1 answer
67 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. $...
Matt V.'s user avatar
  • 2,984
-1 votes
1 answer
1k 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 ...
Guest's user avatar
  • 17
0 votes
1 answer
298 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 ...
Binny's user avatar
  • 934
1 vote
0 answers
102 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 ...
Suraj's user avatar
  • 884
2 votes
1 answer
908 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 ...
Charles Letcher's user avatar
0 votes
1 answer
1k 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-...
Sergey Kravchenko's user avatar
0 votes
1 answer
1k 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) { // ...
Baud's user avatar
  • 542
2 votes
1 answer
161 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 ...
Akram Zairig's user avatar
1 vote
1 answer
1k 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(); ...
ccjjmartin's user avatar
2 votes
2 answers
245 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 ...
Charlie Bamford's user avatar
6 votes
1 answer
2k 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 ...
Marwen Amri's user avatar
4 votes
0 answers
1k 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 ...
Kojo's user avatar
  • 3,513
1 vote
1 answer
285 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....
user avatar
0 votes
1 answer
90 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 ...
harshal's user avatar
  • 4,354
1 vote
1 answer
658 views

How to 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 ...
Stefan Korn's user avatar
  • 1,250
0 votes
2 answers
381 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 ...
AVA's user avatar
  • 1
1 vote
2 answers
1k 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\...
Koala Yeung's user avatar
2 votes
0 answers
91 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'...
̷c̷h̷x̷'s user avatar
1 vote
1 answer
2k 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','@...
Hossein Bagherzadegan's user avatar
0 votes
2 answers
2k 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 ...
bluedrop's user avatar
3 votes
0 answers
2k 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: ...
Filipe Miguel Fonseca's user avatar
0 votes
1 answer
408 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 ...
Rob Allen's user avatar
  • 103