Skip to content
GitLab
Projects
Groups
Snippets
Help
Loading...
Help
What's new
10
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Sign in
Toggle navigation
Open sidebar
project
drupal
Commits
8485135f
Commit
8485135f
authored
Nov 12, 2015
by
alexpott
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Issue
#2611086
by dawehner, xjm: Expose entity type manager on controller base / Entity / Drupal
parent
9e826723
Changes
4
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
65 additions
and
0 deletions
+65
-0
core/lib/Drupal.php
core/lib/Drupal.php
+16
-0
core/lib/Drupal/Core/Controller/ControllerBase.php
core/lib/Drupal/Core/Controller/ControllerBase.php
+24
-0
core/lib/Drupal/Core/Entity/Entity.php
core/lib/Drupal/Core/Entity/Entity.php
+15
-0
core/tests/Drupal/Tests/Core/DrupalTest.php
core/tests/Drupal/Tests/Core/DrupalTest.php
+10
-0
No files found.
core/lib/Drupal.php
View file @
8485135f
...
...
@@ -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.
*
...
...
core/lib/Drupal/Core/Controller/ControllerBase.php
View file @
8485135f
...
...
@@ -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.
*
...
...
core/lib/Drupal/Core/Entity/Entity.php
View file @
8485135f
...
...
@@ -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.
*
...
...
core/tests/Drupal/Tests/Core/DrupalTest.php
View file @
8485135f
...
...
@@ -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.
*
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment