Skip to content
GitLab
Menu
Projects
Groups
Snippets
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Sign in
Toggle navigation
Menu
Open sidebar
project
drupal
Commits
fe61b43d
Commit
fe61b43d
authored
Feb 08, 2014
by
alexpott
Browse files
Issue
#2183923
by tim.plunkett: Break the circular dependency in EntityManager.
parent
1939de98
Changes
32
Hide whitespace changes
Inline
Side-by-side
core/core.services.yml
View file @
fe61b43d
...
...
@@ -188,6 +188,9 @@ services:
entity.manager
:
class
:
Drupal\Core\Entity\EntityManager
arguments
:
[
'
@container.namespaces'
,
'
@service_container'
,
'
@module_handler'
,
'
@cache.cache'
,
'
@language_manager'
,
'
@string_translation'
]
entity.form_builder
:
class
:
Drupal\Core\Entity\EntityFormBuilder
arguments
:
[
'
@entity.manager'
,
'
@form_builder'
]
plugin.manager.field.field_type
:
class
:
Drupal\Core\Field\FieldTypePluginManager
arguments
:
[
'
@container.namespaces'
,
'
@cache.field'
,
'
@language_manager'
,
'
@module_handler'
]
...
...
core/includes/entity.inc
View file @
fe61b43d
...
...
@@ -442,31 +442,6 @@ function entity_access_controller($entity_type) {
->
getAccessController
(
$entity_type
);
}
/**
* Returns the built and processed entity form for the given entity.
*
* @param \Drupal\Core\Entity\EntityInterface $entity
* The entity to be created or edited.
* @param string $operation
* (optional) The operation identifying the form variation to be returned.
* @param array $form_state
* (optional) An associative array containing the current state of the form.
* Use this to pass additional information to the form, such as the langcode.
* @code
* $form_state['langcode'] = $langcode;
* $form = entity_get_form($entity, 'default', $form_state);
* @endcode
*
* @return array
* The processed form for the given entity and operation.
*
* @deprecated Use \Drupal::entityManager()->getForm() or _entity_form from a
* routing.yml file instead of a page callback.
*/
function
entity_get_form
(
EntityInterface
$entity
,
$operation
=
'default'
,
array
$form_state
=
array
())
{
return
\
Drupal
::
entityManager
()
->
getForm
(
$entity
,
$operation
,
$form_state
);
}
/**
* Returns an entity list controller for a given entity type.
*
...
...
core/lib/Drupal/Core/Controller/ControllerBase.php
View file @
fe61b43d
...
...
@@ -39,6 +39,13 @@ abstract class ControllerBase implements ContainerInjectionInterface {
*/
protected
$entityManager
;
/**
* The entity form builder.
*
* @var \Drupal\Core\Entity\EntityFormBuilderInterface
*/
protected
$entityFormBuilder
;
/**
* The language manager.
*
...
...
@@ -122,6 +129,19 @@ protected function entityManager() {
return
$this
->
entityManager
;
}
/**
* Retrieves the entity form builder.
*
* @return \Drupal\Core\Entity\EntityFormBuilderInterface
* The entity form builder.
*/
protected
function
entityFormBuilder
()
{
if
(
!
$this
->
entityFormBuilder
)
{
$this
->
entityFormBuilder
=
$this
->
container
()
->
get
(
'entity.form_builder'
);
}
return
$this
->
entityFormBuilder
;
}
/**
* Returns the requested cache bin.
*
...
...
core/lib/Drupal/Core/Entity/EntityFormBuilder.php
0 → 100644
View file @
fe61b43d
<?php
/**
* @file
* Contains \Drupal\Core\Entity\EntityFormBuilder.
*/
namespace
Drupal\Core\Entity
;
use
Drupal\Core\Form\FormBuilderInterface
;
/**
* Builds entity forms.
*/
class
EntityFormBuilder
implements
EntityFormBuilderInterface
{
/**
* The entity manager.
*
* @var \Drupal\Core\Entity\EntityManagerInterface
*/
protected
$entityManager
;
/**
* The form builder.
*
* @var \Drupal\Core\Form\FormBuilderInterface
*/
protected
$formBuilder
;
/**
* Constructs a new EntityFormBuilder.
*
* @param \Drupal\Core\Entity\EntityManagerInterface $entity_manager
* The entity manager.
* @param \Drupal\Core\Form\FormBuilderInterface $form_builder
* The form builder.
*/
public
function
__construct
(
EntityManagerInterface
$entity_manager
,
FormBuilderInterface
$form_builder
)
{
$this
->
entityManager
=
$entity_manager
;
$this
->
formBuilder
=
$form_builder
;
}
/**
* {@inheritdoc}
*/
public
function
getForm
(
EntityInterface
$entity
,
$operation
=
'default'
,
array
$form_state
=
array
())
{
$controller
=
$this
->
entityManager
->
getFormController
(
$entity
->
getEntityTypeId
(),
$operation
);
$controller
->
setEntity
(
$entity
);
$form_state
[
'build_info'
][
'callback_object'
]
=
$controller
;
$form_state
[
'build_info'
][
'base_form_id'
]
=
$controller
->
getBaseFormID
();
$form_state
[
'build_info'
]
+=
array
(
'args'
=>
array
());
return
$this
->
formBuilder
->
buildForm
(
$controller
->
getFormId
(),
$form_state
);
}
}
core/lib/Drupal/Core/Entity/EntityFormBuilderInterface.php
0 → 100644
View file @
fe61b43d
<?php
/**
* @file
* Contains \Drupal\Core\Entity\EntityFormBuilderInterface.
*/
namespace
Drupal\Core\Entity
;
/**
* Builds entity forms.
*/
interface
EntityFormBuilderInterface
{
/**
* Returns the built and processed entity form for the given entity.
*
* @param \Drupal\Core\Entity\EntityInterface $entity
* The entity to be created or edited.
* @param string $operation
* (optional) The operation identifying the form variation to be returned.
* Defaults to 'default'.
* @param array $form_state
* (optional) An associative array containing the current state of the form.
* Use this to pass additional information to the form, such as the
* langcode. Defaults to an empty array.
*
* @code
* $form_state['langcode'] = $langcode;
* $form = \Drupal::service('entity.form_builder')->getForm($entity, 'default', $form_state);
* @endcode
*
* @return array
* The processed form for the given entity and operation.
*/
public
function
getForm
(
EntityInterface
$entity
,
$operation
=
'default'
,
array
$form_state
=
array
());
}
core/lib/Drupal/Core/Entity/EntityManager.php
View file @
fe61b43d
...
...
@@ -279,22 +279,6 @@ public function getController($entity_type, $controller_type, $controller_class_
return
$this
->
controllers
[
$controller_type
][
$entity_type
];
}
/**
* {@inheritdoc}
*/
public
function
getForm
(
EntityInterface
$entity
,
$operation
=
'default'
,
array
$form_state
=
array
())
{
$form_state
[
'build_info'
]
=
isset
(
$form_state
[
'build_info'
])
?
$form_state
[
'build_info'
]
:
array
();
$controller
=
$this
->
getFormController
(
$entity
->
getEntityTypeId
(),
$operation
);
$controller
->
setEntity
(
$entity
);
$form_state
[
'build_info'
]
+=
array
(
'callback_object'
=>
$controller
,
'base_form_id'
=>
$controller
->
getBaseFormID
(),
'args'
=>
array
(),
);
$form_id
=
$controller
->
getFormID
();
return
\
Drupal
::
formBuilder
()
->
buildForm
(
$form_id
,
$form_state
);
}
/**
* {@inheritdoc}
*/
...
...
core/lib/Drupal/Core/Entity/EntityManagerInterface.php
View file @
fe61b43d
...
...
@@ -185,30 +185,6 @@ public function hasController($entity_type, $controller_type);
*/
public
function
getController
(
$entity_type
,
$controller_type
);
/**
* Returns the built and processed entity form for the given entity.
*
* @param \Drupal\Core\Entity\EntityInterface $entity
* The entity to be created or edited.
* @param string $operation
* (optional) The operation identifying the form variation to be returned.
* Defaults to 'default'.
* @param array $form_state
* (optional) An associative array containing the current state of the form.
* Use this to pass additional information to the form, such as the
* langcode. Defaults to an empty array.
*
* @code
* $form_state['langcode'] = $langcode;
* $manager = \Drupal::entityManager();
* $form = $manager->getForm($entity, 'default', $form_state);
* @endcode
*
* @return array
* The processed form for the given entity and operation.
*/
public
function
getForm
(
EntityInterface
$entity
,
$operation
=
'default'
,
array
$form_state
=
array
());
/**
* Get the bundle info of an entity type.
*
...
...
core/modules/aggregator/lib/Drupal/aggregator/Controller/AggregatorController.php
View file @
fe61b43d
...
...
@@ -55,12 +55,11 @@ public static function create(ContainerInterface $container) {
* A form array as expected by drupal_render().
*/
public
function
feedAdd
()
{
$entity_manager
=
$this
->
entityManager
();
$feed
=
$entity_manager
->
getStorageController
(
'aggregator_feed'
)
$feed
=
$this
->
entityManager
()
->
getStorageController
(
'aggregator_feed'
)
->
create
(
array
(
'refresh'
=>
3600
,
));
return
$
entity_manager
->
getForm
(
$feed
);
return
$
this
->
entityFormBuilder
()
->
getForm
(
$feed
);
}
/**
...
...
core/modules/block/custom_block/lib/Drupal/custom_block/Controller/CustomBlockController.php
View file @
fe61b43d
...
...
@@ -16,13 +16,6 @@
class
CustomBlockController
extends
ControllerBase
{
/**
* The entity manager.
*
* @var \Drupal\Component\Plugin\PluginManagerInterface
*/
protected
$entityManager
;
/**
* The custom block storage controller.
*
...
...
@@ -43,7 +36,6 @@ class CustomBlockController extends ControllerBase {
public
static
function
create
(
ContainerInterface
$container
)
{
$entity_manager
=
$container
->
get
(
'entity.manager'
);
return
new
static
(
$entity_manager
,
$entity_manager
->
getStorageController
(
'custom_block'
),
$entity_manager
->
getStorageController
(
'custom_block_type'
)
);
...
...
@@ -52,17 +44,14 @@ public static function create(ContainerInterface $container) {
/**
* Constructs a CustomBlock object.
*
* @param \Drupal\Component\Plugin\PluginManagerInterface $entity_manager
* The entity manager.
* @param \Drupal\Core\Entity\EntityStorageControllerInterface $custom_block_storage
* The custom block storage controller.
* @param \Drupal\Core\Entity\EntityStorageControllerInterface $custom_block_type_storage
* The custom block type storage controller.
*/
public
function
__construct
(
PluginManagerInterface
$entity_manager
,
EntityStorageControllerInterface
$custom_block_storage
,
EntityStorageControllerInterface
$custom_block_type_storage
)
{
public
function
__construct
(
EntityStorageControllerInterface
$custom_block_storage
,
EntityStorageControllerInterface
$custom_block_type_storage
)
{
$this
->
customBlockStorage
=
$custom_block_storage
;
$this
->
customBlockTypeStorage
=
$custom_block_type_storage
;
$this
->
entityManager
=
$entity_manager
;
}
/**
...
...
@@ -107,7 +96,7 @@ public function addForm(CustomBlockTypeInterface $custom_block_type, Request $re
// newly created block in the given theme.
$block
->
setTheme
(
$theme
);
}
return
$this
->
entity
Manager
->
getForm
(
$block
);
return
$this
->
entity
FormBuilder
()
->
getForm
(
$block
);
}
/**
...
...
core/modules/block/lib/Drupal/block/Controller/BlockAddController.php
View file @
fe61b43d
...
...
@@ -30,7 +30,7 @@ public function blockAddConfigureForm($plugin_id, $theme) {
// Create a block entity.
$entity
=
$this
->
entityManager
()
->
getStorageController
(
'block'
)
->
create
(
array
(
'plugin'
=>
$plugin_id
,
'theme'
=>
$theme
));
return
$this
->
entity
Manag
er
()
->
getForm
(
$entity
);
return
$this
->
entity
FormBuild
er
()
->
getForm
(
$entity
);
}
}
core/modules/comment/comment.module
View file @
fe61b43d
...
...
@@ -603,7 +603,7 @@ function comment_add(EntityInterface $entity, $field_name = 'comment', $pid = NU
'pid'
=>
$pid
,
);
$comment
=
entity_create
(
'comment'
,
$values
);
return
\
Drupal
::
entityManag
er
(
)
->
getForm
(
$comment
);
return
\
Drupal
::
service
(
'entity.form_build
er
'
)
->
getForm
(
$comment
);
}
/**
...
...
core/modules/comment/lib/Drupal/comment/Controller/CommentController.php
View file @
fe61b43d
...
...
@@ -270,7 +270,7 @@ public function getReplyForm(Request $request, $entity_type, $entity_id, $field_
'entity_type'
=>
$entity
->
getEntityTypeId
(),
'field_id'
=>
$entity
->
getEntityTypeId
()
.
'__'
.
$field_name
,
));
$build
[
'comment_form'
]
=
$this
->
entity
Manag
er
()
->
getForm
(
$comment
);
$build
[
'comment_form'
]
=
$this
->
entity
FormBuild
er
()
->
getForm
(
$comment
);
return
$build
;
}
...
...
core/modules/config/tests/config_test/lib/Drupal/config_test/ConfigTestController.php
View file @
fe61b43d
...
...
@@ -28,7 +28,7 @@ class ConfigTestController extends ControllerBase {
* A form array as expected by drupal_render().
*/
public
function
edit
(
ConfigTest
$config_test
)
{
$form
=
$this
->
entity
Manag
er
()
->
getForm
(
$config_test
);
$form
=
$this
->
entity
FormBuild
er
()
->
getForm
(
$config_test
);
$form
[
'#title'
]
=
String
::
format
(
'Edit %label'
,
array
(
'%label'
=>
$config_test
->
label
()));
return
$form
;
}
...
...
core/modules/contact/lib/Drupal/contact/Controller/ContactController.php
View file @
fe61b43d
...
...
@@ -90,7 +90,7 @@ public function contactSitePage(CategoryInterface $contact_category = NULL) {
'category'
=>
$contact_category
->
id
(),
));
$form
=
$this
->
entity
Manag
er
()
->
getForm
(
$message
);
$form
=
$this
->
entity
FormBuild
er
()
->
getForm
(
$message
);
$form
[
'#title'
]
=
String
::
checkPlain
(
$contact_category
->
label
());
return
$form
;
}
...
...
@@ -115,7 +115,7 @@ public function contactPersonalPage(UserInterface $user) {
'recipient'
=>
$user
->
id
(),
));
$form
=
$this
->
entity
Manag
er
()
->
getForm
(
$message
);
$form
=
$this
->
entity
FormBuild
er
()
->
getForm
(
$message
);
$form
[
'#title'
]
=
$this
->
t
(
'Contact @username'
,
array
(
'@username'
=>
$user
->
getUsername
()));
return
$form
;
}
...
...
core/modules/content_translation/content_translation.pages.inc
View file @
fe61b43d
...
...
@@ -189,7 +189,7 @@ function content_translation_add_page(EntityInterface $entity, Language $source
$form_state
[
'content_translation'
][
'source'
]
=
$source
;
$form_state
[
'content_translation'
][
'target'
]
=
$target
;
$form_state
[
'content_translation'
][
'translation_form'
]
=
!
$entity
->
access
(
'update'
);
return
\
Drupal
::
entityManag
er
(
)
->
getForm
(
$entity
,
'default'
,
$form_state
);
return
\
Drupal
::
service
(
'entity.form_build
er
'
)
->
getForm
(
$entity
,
'default'
,
$form_state
);
}
/**
...
...
@@ -210,7 +210,7 @@ function content_translation_edit_page(EntityInterface $entity, Language $langua
$language
=
!
empty
(
$language
)
?
$language
:
language
(
Language
::
TYPE_CONTENT
);
$form_state
[
'langcode'
]
=
$language
->
id
;
$form_state
[
'content_translation'
][
'translation_form'
]
=
TRUE
;
return
\
Drupal
::
entityManag
er
(
)
->
getForm
(
$entity
,
'default'
,
$form_state
);
return
\
Drupal
::
service
(
'entity.form_build
er
'
)
->
getForm
(
$entity
,
'default'
,
$form_state
);
}
/**
...
...
core/modules/forum/lib/Drupal/forum/Controller/ForumController.php
View file @
fe61b43d
...
...
@@ -157,7 +157,7 @@ public function addForum() {
'vid'
=>
$vid
,
'forum_controller'
=>
0
,
));
return
$this
->
entity
Manag
er
()
->
getForm
(
$taxonomy_term
,
'forum'
);
return
$this
->
entity
FormBuild
er
()
->
getForm
(
$taxonomy_term
,
'forum'
);
}
/**
...
...
@@ -172,7 +172,7 @@ public function addContainer() {
'vid'
=>
$vid
,
'forum_container'
=>
1
,
));
return
$this
->
entity
Manag
er
()
->
getForm
(
$taxonomy_term
,
'container'
);
return
$this
->
entity
FormBuild
er
()
->
getForm
(
$taxonomy_term
,
'container'
);
}
}
core/modules/menu/lib/Drupal/menu/Controller/MenuController.php
View file @
fe61b43d
...
...
@@ -54,7 +54,7 @@ public function addLink(MenuInterface $menu) {
'plid'
=>
0
,
'menu_name'
=>
$menu
->
id
(),
));
return
$this
->
entity
Manag
er
()
->
getForm
(
$menu_link
);
return
$this
->
entity
FormBuild
er
()
->
getForm
(
$menu_link
);
}
/**
...
...
core/modules/node/lib/Drupal/node/Controller/NodeController.php
View file @
fe61b43d
...
...
@@ -72,7 +72,7 @@ public function add(NodeTypeInterface $node_type) {
'langcode'
=>
$langcode
?
$langcode
:
$this
->
languageManager
()
->
getCurrentLanguage
()
->
id
,
));
$form
=
$this
->
entity
Manag
er
()
->
getForm
(
$node
);
$form
=
$this
->
entity
FormBuild
er
()
->
getForm
(
$node
);
return
$form
;
}
...
...
core/modules/options/lib/Drupal/options/Tests/OptionsFieldTest.php
View file @
fe61b43d
...
...
@@ -35,7 +35,7 @@ public static function getInfo() {
function
testUpdateAllowedValues
()
{
// All three options appear.
$entity
=
entity_create
(
'entity_test'
);
$form
=
\
Drupal
::
entityManag
er
(
)
->
getForm
(
$entity
);
$form
=
\
Drupal
::
service
(
'entity.form_build
er
'
)
->
getForm
(
$entity
);
$this
->
assertTrue
(
!
empty
(
$form
[
$this
->
fieldName
][
'widget'
][
1
]),
'Option 1 exists'
);
$this
->
assertTrue
(
!
empty
(
$form
[
$this
->
fieldName
][
'widget'
][
2
]),
'Option 2 exists'
);
$this
->
assertTrue
(
!
empty
(
$form
[
$this
->
fieldName
][
'widget'
][
3
]),
'Option 3 exists'
);
...
...
@@ -61,7 +61,7 @@ function testUpdateAllowedValues() {
$this
->
field
->
settings
[
'allowed_values'
]
=
array
(
2
=>
'Two'
);
$this
->
field
->
save
();
$entity
=
entity_create
(
'entity_test'
);
$form
=
\
Drupal
::
entityManag
er
(
)
->
getForm
(
$entity
);
$form
=
\
Drupal
::
service
(
'entity.form_build
er
'
)
->
getForm
(
$entity
);
$this
->
assertTrue
(
empty
(
$form
[
$this
->
fieldName
][
'widget'
][
1
]),
'Option 1 does not exist'
);
$this
->
assertTrue
(
!
empty
(
$form
[
$this
->
fieldName
][
'widget'
][
2
]),
'Option 2 exists'
);
$this
->
assertTrue
(
empty
(
$form
[
$this
->
fieldName
][
'widget'
][
3
]),
'Option 3 does not exist'
);
...
...
@@ -72,7 +72,7 @@ function testUpdateAllowedValues() {
// The entity holds an outdated field object with the old allowed values
// setting, so we need to reintialize the entity object.
$entity
=
entity_create
(
'entity_test'
);
$form
=
\
Drupal
::
entityManag
er
(
)
->
getForm
(
$entity
);
$form
=
\
Drupal
::
service
(
'entity.form_build
er
'
)
->
getForm
(
$entity
);
$this
->
assertTrue
(
empty
(
$form
[
$this
->
fieldName
][
'widget'
][
1
]),
'Option 1 does not exist'
);
$this
->
assertTrue
(
empty
(
$form
[
$this
->
fieldName
][
'widget'
][
2
]),
'Option 2 does not exist'
);
$this
->
assertTrue
(
empty
(
$form
[
$this
->
fieldName
][
'widget'
][
3
]),
'Option 3 does not exist'
);
...
...
@@ -93,7 +93,7 @@ function testUpdateAllowedValues() {
))
->
save
();
$entity
=
entity_create
(
'entity_test'
);
$form
=
\
Drupal
::
entityManag
er
(
)
->
getForm
(
$entity
);
$form
=
\
Drupal
::
service
(
'entity.form_build
er
'
)
->
getForm
(
$entity
);
$this
->
assertTrue
(
!
empty
(
$form
[
$this
->
fieldName
][
'widget'
][
1
]),
'Option 1 exists'
);
$this
->
assertTrue
(
!
empty
(
$form
[
$this
->
fieldName
][
'widget'
][
2
]),
'Option 2 exists'
);
$this
->
assertTrue
(
!
empty
(
$form
[
$this
->
fieldName
][
'widget'
][
3
]),
'Option 3 exists'
);
...
...
core/modules/search/lib/Drupal/search/Controller/SearchController.php
View file @
fe61b43d
...
...
@@ -87,7 +87,7 @@ public function view(Request $request, SearchPageInterface $entity, $keys = '')
}
}
// The form may be altered based on whether the search was run.
$build
[
'search_form'
]
=
$this
->
entity
Manag
er
()
->
getForm
(
$entity
,
'search'
);
$build
[
'search_form'
]
=
$this
->
entity
FormBuild
er
()
->
getForm
(
$entity
,
'search'
);
$build
[
'search_results'
]
=
$results
;
return
$build
;
}
...
...
Prev
1
2
Next
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