Change record status: 
Project: 
Introduced in branch: 
8.x
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

Beedge’s picture

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');