Change record status: 
Project: 
Introduced in branch: 
11.4.x
Introduced in version: 
11.4.0
Description: 

The static methods Views::pluginManager() and Views::handlerManager() have been deprecated in favor of accessing Views plugin managers via dependency injection or using a new service locator.

Code that accessed Views plugin managers through static wrapper methods:

use Drupal\views\Views;

// Get a plugin manager for a specific type.
$filter_manager = Views::pluginManager('filter');
$field_manager = Views::handlerManager('field');

// Use with dynamic types.
$type = 'display';
$manager = Views::pluginManager($type);

should now use the service directly, or the service locator for dynamic types:

// For known/static types, use the specific service directly.
$filter_manager = \Drupal::service('plugin.manager.views.filter');
$field_manager = \Drupal::service('plugin.manager.views.field');

// For dynamic types, use the service locator.
$type = 'display';
$manager = \Drupal::service('views.plugin_managers')->get($type);

Similarly the service locator can be injected:

use Psr\Container\ContainerInterface;

class MyService {
  public function __construct(
    #[Autowire(service: 'views.plugin_managers')]
    private readonly ContainerInterface $viewsPluginManagers,
  ) {}

  public function doSomething(string $type): void {
    $manager = $this->viewsPluginManagers->get($type);
    // ...
  }
}
Impacts: 
Module developers