public static function ModerationSidebarController::create in Moderation Sidebar 8
Instantiates a new instance of this class.
This is a factory method that returns a new instance of this class. The factory should pass any needed dependencies into the constructor of this class, but not the container itself. Every call to this method must return a new instance of this class; that is, it may not implement a singleton.
Parameters
\Symfony\Component\DependencyInjection\ContainerInterface $container: The service container this instance should use.
Overrides ControllerBase::create
File
- src/
Controller/ ModerationSidebarController.php, line 92
Class
- ModerationSidebarController
- Endpoints for the Moderation Sidebar module.
Namespace
Drupal\moderation_sidebar\ControllerCode
public static function create(ContainerInterface $container) {
$moderation_info = $container
->get('content_moderation.moderation_information');
// We need an instance of LocalTaskManager that thinks we're viewing the
// entity. To accomplish this, we need to mock a request stack with a fake
// request. This looks crazy, but there is no other way to render
// Local Tasks for an arbitrary path without this.
/** @var \Symfony\Component\HttpFoundation\RequestStack $request_stack */
$request_stack = $container
->get('request_stack');
$attributes = $request_stack
->getCurrentRequest()->attributes;
/** @var \Drupal\Core\Entity\EntityInterface $entity */
$entity = $attributes
->has('node') ? $attributes
->get('node') : $attributes
->get('entity');
$fake_request_stack = new RequestStack();
$current_request = $container
->get('request_stack')
->getCurrentRequest();
$request = Request::create($entity
->toUrl()
->getInternalPath(), 'GET', [], [], [], $current_request->server
->all(), NULL);
/** @var \Drupal\Core\Routing\AccessAwareRouter $router */
$router = $container
->get('router');
$router
->matchRequest($request);
$fake_request_stack
->push($request);
$route_match = new CurrentRouteMatch($fake_request_stack);
$local_task_manager = new LocalTaskManager($container
->get('http_kernel.controller.argument_resolver'), $fake_request_stack, $route_match, $container
->get('router.route_provider'), $container
->get('module_handler'), $container
->get('cache.discovery'), $container
->get('language_manager'), $container
->get('access_manager'), $container
->get('current_user'));
return new static($moderation_info, $request_stack, $container
->get('date.formatter'), $container
->get('module_handler'), $local_task_manager);
}