Early Bird Registration for DrupalCon Portland 2024 is open! Register by 23:59 PST on 31 March 2024, to get $100 off your ticket.
By pwolanin on
Change record status:
Published (View all published change records)
Project:
Introduced in branch:
8.x
Description:
class \Drupal\Core\Controller\ControllerBase
now implements \Drupal\Core\DependencyInjection\ContainerInjectionInterface
. This means any extending the base class can use container injection automatically.
Before:
class AggregatorController extends ControllerBase implements ContainerInjectionInterface {
protected $database;
/**
* Constructs a \Drupal\aggregator\Controller\AggregatorController object.
*
* @param \Drupal\Core\Database\Connection $database
* The database connection.
*/
public function __construct(Connection $database) {
$this->database = $database;
}
/**
* {inheritdoc}
*/
public static function create(ContainerInterface $container) {
return new static(
$container->get('database')
);
}
...
}
After:
class AggregatorController extends ControllerBase {
protected $database;
/**
* Constructs a \Drupal\aggregator\Controller\AggregatorController object.
*
* @param \Drupal\Core\Database\Connection $database
* The database connection.
*/
public function __construct(Connection $database) {
$this->database = $database;
}
/**
* {inheritdoc}
*/
public static function create(ContainerInterface $container) {
return new static(
$container->get('database')
);
}
...
}
Impacts:
Module developers