function Drupal::service
Same name and namespace in other branches
- 8.9.x core/lib/Drupal.php \Drupal::service()
- 10 core/lib/Drupal.php \Drupal::service()
- 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.
282 calls to Drupal::service()
- AccessRoleTest::testRenderCaching in core/
modules/ user/ tests/ src/ Functional/ Views/ AccessRoleTest.php - Tests access on render caching.
- ApcuBackendTest::createCacheBackend in core/
tests/ Drupal/ KernelTests/ Core/ Cache/ ApcuBackendTest.php - Creates a cache backend to test.
- ArchiverManager::__construct in core/
lib/ Drupal/ Core/ Archiver/ ArchiverManager.php - Constructs an ArchiverManager object.
- AssertContentTrait::assertThemeOutput in core/
tests/ Drupal/ KernelTests/ AssertContentTrait.php - Asserts themed output.
- AssertMailTraitTest::testAssertMailTrait in core/
tests/ Drupal/ KernelTests/ Core/ Test/ AssertMailTraitTest.php - Tests that the maintenance theme initializes the theme and its base themes.
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.