By dawehner on
Change record status:
Published (View all published change records)
Project:
Introduced in branch:
8.x
Issue links:
Description:
Controller which extend the ControllerBase cannot longer call the container() method but have to use the create() method and constructor injection.
Before:
class ExampleController extends ControllerBase {
public function exampleContent() {
$theme_handler = $this->container()->get('theme_handler');
// ...
}
}
After:
class ExampleController extends ControllerBase {
public function __construct(ThemeHandlerInterface $theme_handler) {
$this->themeHandler = $theme_handler;
}
public function create(Container $container) {
return new static($container->get('theme_handler');
}
public function exampleContent() {
$this->themeHandler...;
// ...
}
}
Impacts:
Module developers
Comments
Typo in sample code
in the 'After' example above there is a bracket missing in the return statement of the create function.
return new static($container->get('theme_handler');