function Drupal::service

Same name and namespace in other branches
  1. 9 core/lib/Drupal.php \Drupal::service()
  2. 8.9.x core/lib/Drupal.php \Drupal::service()
  3. 11.x core/lib/Drupal.php \Drupal::service()

Retrieves a service from the container.

Use this method if the desired service is not one of those with a dedicated accessor method below. If it is listed below, those methods are preferred as they can return useful type hints.

Parameters

string $id: The ID of the service to retrieve.

Return value

mixed The specified service.

208 calls to Drupal::service()
ApcuBackend::__construct in core/lib/Drupal/Core/Cache/ApcuBackend.php
Constructs a new ApcuBackend instance.
ApcuBackendFactory::__construct in core/lib/Drupal/Core/Cache/ApcuBackendFactory.php
Constructs an ApcuBackendFactory object.
AssetResolver::getJsAssets in core/lib/Drupal/Core/Asset/AssetResolver.php
Returns the JavaScript assets for the current response's libraries.
BaseFieldDefinition::create in core/lib/Drupal/Core/Field/BaseFieldDefinition.php
Creates a new field definition.
BaseFieldOverride::preSave in core/lib/Drupal/Core/Field/Entity/BaseFieldOverride.php

... See full list

File

core/lib/Drupal.php, line 196

Class

Drupal
Static Service Container wrapper.

Code

public static function service($id) {
  return static::getContainer()->get($id);
}

Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.