Same name and namespace in other branches
- 8.9.x core/lib/Drupal.php \Drupal::service()
- 9 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.
1926 calls to Drupal::service()
- AccessRoleTest::testRenderCaching in core/
modules/ user/ tests/ src/ Functional/ Views/ AccessRoleTest.php - Tests access on render caching.
- AccessTest::testFileCacheability in core/
modules/ file/ tests/ src/ Kernel/ AccessTest.php - Tests cacheability metadata.
- Actions::preRenderActionsDropbutton in core/
lib/ Drupal/ Core/ Render/ Element/ Actions.php - #pre_render callback for #type 'actions'.
- ActionsTest::testDropbuttonWithBubbleableMetadata in core/
tests/ Drupal/ KernelTests/ Core/ Render/ Element/ ActionsTest.php - ActionUninstallTest::testActionUninstall in core/
modules/ action/ tests/ src/ Functional/ ActionUninstallTest.php - Tests Actions UI uninstall.
File
- core/
lib/ Drupal.php, line 196
Class
- Drupal
- Static Service Container wrapper.
Code
public static function service($id) {
return static::getContainer()
->get($id);
}