Commit 8485135f authored by alexpott's avatar alexpott

Issue #2611086 by dawehner, xjm: Expose entity type manager on controller base / Entity / Drupal

parent 9e826723
......@@ -252,11 +252,27 @@ public static function currentUser() {
*
* @return \Drupal\Core\Entity\EntityManagerInterface
* The entity manager service.
*
* @deprecated in Drupal 8.0.0 and will be removed before Drupal 9.0.0.
* Use \Drupal::entityTypeManager() instead in most cases. If the needed
* method is not on \Drupal\Core\Entity\EntityTypeManagerInterface, see the
* deprecated \Drupal\Core\Entity\EntityManager to find the
* correct interface or service.
*/
public static function entityManager() {
return static::getContainer()->get('entity.manager');
}
/**
* Retrieves the entity type manager.
*
* @return \Drupal\Core\Entity\EntityTypeManagerInterface
* The entity type manager.
*/
public static function entityTypeManager() {
return static::getContainer()->get('entity_type.manager');
}
/**
* Returns the current primary database.
*
......
......@@ -49,6 +49,13 @@ abstract class ControllerBase implements ContainerInjectionInterface {
*/
protected $entityManager;
/**
* The entity type manager.
*
* @var \Drupal\Core\Entity\EntityTypeManagerInterface
*/
protected $entityTypeManager;
/**
* The entity form builder.
*
......@@ -117,6 +124,10 @@ public static function create(ContainerInterface $container) {
*
* @return \Drupal\Core\Entity\EntityManagerInterface
* The entity manager service.
*
* @deprecated in Drupal 8.0.0, will be removed before Drupal 9.0.0.
* Most of the time static::entityTypeManager() is supposed to be used
* instead.
*/
protected function entityManager() {
if (!$this->entityManager) {
......@@ -125,6 +136,19 @@ protected function entityManager() {
return $this->entityManager;
}
/**
* Retrieves the entity type manager.
*
* @return \Drupal\Core\Entity\EntityTypeManagerInterface
* The entity type manager.
*/
protected function entityTypeManager() {
if (!isset($this->entityTypeManager)) {
$this->entityTypeManager = $this->container()->get('entity_type.manager');
}
return $this->entityTypeManager;
}
/**
* Retrieves the entity form builder.
*
......
......@@ -72,11 +72,26 @@ public function __construct(array $values, $entity_type) {
* Gets the entity manager.
*
* @return \Drupal\Core\Entity\EntityManagerInterface
*
* @deprecated in Drupal 8.0.0 and will be removed before Drupal 9.0.0.
* Use \Drupal::entityTypeManager() instead in most cases. If the needed
* method is not on \Drupal\Core\Entity\EntityTypeManagerInterface, see the
* deprecated \Drupal\Core\Entity\EntityManager to find the
* correct interface or service.
*/
protected function entityManager() {
return \Drupal::entityManager();
}
/**
* Gets the entity type manager.
*
* @return \Drupal\Core\Entity\EntityTypeManagerInterface
*/
protected function entityTypeManager() {
return \Drupal::entityTypeManager();
}
/**
* Gets the language manager.
*
......
......@@ -86,6 +86,16 @@ public function testEntityManager() {
$this->assertNotNull(\Drupal::entityManager());
}
/**
* Tests the entityTypeManager() method.
*
* @covers ::entityTypeManager
*/
public function testEntityTypeManager() {
$this->setMockContainerService('entity_type.manager');
$this->assertNotNull(\Drupal::entityTypeManager());
}
/**
* Tests the database() method.
*
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment