Lets override Drupal services (with and without overriding arguments) | Drupal 8

Service-based architecture is one of the major strength of Drupal 8. Drupal core and contrib provide lots of services to be used by other services, plugins or any other function. The flexible nature of Drupal allows overriding of services.

We can have different scenarios:

  1. Override Drupal Service without overriding arguments
  2. Override Drupal Service, overriding arguments as well

Now, both of them can be resolved using the approach discussed in https://www.drupal.org/docs/8/api/services-and-dependency-injection/altering-existing-services-providing-dynamic-services where we implement a class extending ServiceProviderBase and the alter() method.

A second way is decorating existing services: https://symfony.com/doc/current/service_container/service_decoration.html

But there is one more pretty handy way to perform the 1st task specific to Drupal. Let's find out that :).

Add new comment

Restricted HTML

  • Allowed HTML tags: <a href hreflang> <em> <strong> <cite> <blockquote cite> <code> <ul type> <ol start type> <li> <dl> <dt> <dd> <h2 id> <h3 id> <h4 id> <h5 id> <h6 id>
  • Lines and paragraphs break automatically.
  • Web page addresses and email addresses turn into links automatically.
CAPTCHA
This question is for testing whether or not you are a human visitor and to prevent automated spam submissions.