Skip to content
Snippets Groups Projects
Commit 8485135f authored by Alex Pott's avatar Alex Pott
Browse files

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

parent 9e826723
No related branches found
No related tags found
2 merge requests!7452Issue #1797438. HTML5 validation is preventing form submit and not fully...,!789Issue #3210310: Adjust Database API to remove deprecated Drupal 9 code in Drupal 10
......@@ -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.
*
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment