Same name and namespace in other branches
- 8.9.x core/lib/Drupal.php \Drupal::classResolver()
- 9 core/lib/Drupal.php \Drupal::classResolver()
Retrieves the class resolver.
This is to be used in procedural code such as module files to instantiate an object of a class that implements \Drupal\Core\DependencyInjection\ContainerInjectionInterface.
One common use case is to provide a class which contains the actual code of a hook implementation, without having to create a service.
Parameters
string $class: (optional) A class name to instantiate.
Return value
\Drupal\Core\DependencyInjection\ClassResolverInterface|object The class resolver or if $class is provided, a class instance with a given class definition.
Throws
\InvalidArgumentException If $class does not exist.
50 calls to Drupal::classResolver()
- block_content_post_update_revision_type in core/
modules/ block_content/ block_content.post_update.php - Update configuration for revision type.
- block_content_post_update_sort_permissions in core/
modules/ block_content/ block_content.post_update.php - Update permissions for users with "administer blocks" permission.
- ckeditor5_post_update_code_block in core/
modules/ ckeditor5/ ckeditor5.post_update.php - Updates Text Editors using CKEditor 5 Code Block.
- ckeditor5_post_update_image_toolbar_item in core/
modules/ ckeditor5/ ckeditor5.post_update.php - The image toolbar item changed from `uploadImage` to `drupalInsertImage`.
- ckeditor5_post_update_list_multiblock in core/
modules/ ckeditor5/ ckeditor5.post_update.php - Updates Text Editors using CKEditor 5.
File
- core/
lib/ Drupal.php, line 364
Class
- Drupal
- Static Service Container wrapper.
Code
public static function classResolver($class = NULL) {
if ($class) {
return static::getContainer()
->get('class_resolver')
->getInstanceFromDefinition($class);
}
return static::getContainer()
->get('class_resolver');
}