function Drupal::service

Same name in other branches
  1. 8.9.x core/lib/Drupal.php \Drupal::service()
  2. 10 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.

862 calls to Drupal::service()
AccessRoleTest::testRenderCaching in core/modules/user/tests/src/Functional/Views/AccessRoleTest.php
Tests access on render caching.
Action::getPluginCollection in core/modules/system/src/Entity/Action.php
Encapsulates the creation of the action's LazyPluginCollection.
ActiveWorkspaceUpdateTest::testActiveWorkspaceDuringUpdate in core/modules/workspaces/tests/src/Functional/UpdateSystem/ActiveWorkspaceUpdateTest.php
Tests that there is no active workspace during database updates.
AddedStylesheetsTest::testCkeditorStylesheets in core/modules/ckeditor5/tests/src/Functional/AddedStylesheetsTest.php
Test the ckeditor5-stylesheets theme config.
aggregator_entity_extra_field_info in core/modules/aggregator/aggregator.module
Implements hook_entity_extra_field_info().

... See full list

File

core/lib/Drupal.php, line 206

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.