8.3.x Drupal.php Drupal::service($id)
8.0.x Drupal.php public static Drupal::service($id)
8.1.x Drupal.php public static Drupal::service($id)
8.2.x Drupal.php public static Drupal::service($id)
8.4.x Drupal.php public static Drupal::service($id)

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.

1235 calls to Drupal::service()
AccessPermissionTest::testRenderCaching in core/modules/user/src/Tests/Views/AccessPermissionTest.php
Tests access on render caching.
AccessRoleTest::testRenderCaching in core/modules/user/src/Tests/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.
Actions::preRenderActionsDropbutton in core/lib/Drupal/Core/Render/Element/Actions.php
#pre_render callback for #type 'actions'.
ActionUninstallTest::testActionUninstall in core/modules/action/tests/src/Functional/ActionUninstallTest.php
Tests Action uninstall.

... See full list

File

core/lib/Drupal.php, line 157
Contains \Drupal.

Class

Drupal
Static Service Container wrapper.

Code

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