Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
D
drupal
Manage
Activity
Members
Labels
Plan
Wiki
Custom issue tracker
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Locked files
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Model registry
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Code review analytics
Insights
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Terms and privacy
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
project
drupal
Commits
1d02be7f
Commit
1d02be7f
authored
11 years ago
by
Angie Byron
Browse files
Options
Downloads
Patches
Plain Diff
Issue
#2015923
by chx, plopesc, tim.plunkett: Clean up entity form functions.
parent
4161356d
No related branches found
Branches containing commit
No related tags found
Tags containing commit
2 merge requests
!7452
Issue #1797438. HTML5 validation is preventing form submit and not fully...
,
!789
Issue #3210310: Adjust Database API to remove deprecated Drupal 9 code in Drupal 10
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
core/includes/entity.inc
+3
-71
3 additions, 71 deletions
core/includes/entity.inc
core/lib/Drupal/Core/Entity/EntityManager.php
+10
-3
10 additions, 3 deletions
core/lib/Drupal/Core/Entity/EntityManager.php
with
13 additions
and
74 deletions
core/includes/entity.inc
+
3
−
71
View file @
1d02be7f
...
...
@@ -442,80 +442,12 @@ function entity_access_controller($entity_type) {
->
getAccessController
(
$entity_type
);
}
/**
* Returns an entity form controller for the given operation.
*
* Since there might be different scenarios in which an entity is edited,
* multiple form controllers suitable to the different operations may be defined.
* If no controller is found for the default operation, the base class will be
* used. If a non-existing non-default operation is specified an exception will
* be thrown.
*
* @see \Drupal\Core\Entity\EntityManagerInterface
*
* @param $entity_type
* The type of the entity.
* @param $operation
* (optional) The name of an operation, such as creation, editing or deletion,
* identifying the controlled form. Defaults to 'default' which is the usual
* create/edit form.
*
* @return \Drupal\Core\Entity\EntityFormControllerInterface
* An entity form controller instance.
*
* @deprecated Use \Drupal\Core\Entity\EntityManagerInterface::getFormController().
*/
function
entity_form_controller
(
$entity_type
,
$operation
=
'default'
)
{
return
\Drupal
::
entityManager
()
->
getFormController
(
$entity_type
,
$operation
);
}
/**
* Returns the default form state for the given entity and operation.
*
* @param EntityInterface $entity
* The entity to be created or edited.
* @param $operation
* (optional) The operation identifying the form to be processed.
*
* @return
* A $form_state array already filled the entity form controller.
*/
function
entity_form_state_defaults
(
EntityInterface
$entity
,
$operation
=
'default'
)
{
$form_state
=
array
();
$controller
=
\Drupal
::
entityManager
()
->
getFormController
(
$entity
->
entityType
(),
$operation
);
$controller
->
setEntity
(
$entity
);
$form_state
[
'build_info'
][
'callback_object'
]
=
$controller
;
$form_state
[
'build_info'
][
'base_form_id'
]
=
$controller
->
getBaseFormID
();
$form_state
[
'build_info'
][
'args'
]
=
array
();
return
$form_state
;
}
/**
* Retrieves, populates, and processes an entity form.
*
* @param EntityInterface $entity
* The entity to be created or edited.
* @param $operation
* (optional) The operation identifying the form to be submitted.
* @param $form_state
* (optional) A keyed array containing the current state of the form.
*
* @return
* A $form_state array already filled with the entity form controller.
*/
function
entity_form_submit
(
EntityInterface
$entity
,
$operation
=
'default'
,
&
$form_state
=
array
())
{
$form_state
+=
entity_form_state_defaults
(
$entity
,
$operation
);
$form_id
=
$form_state
[
'build_info'
][
'callback_object'
]
->
getFormId
();
drupal_form_submit
(
$form_id
,
$form_state
);
}
/**
* Returns the built and processed entity form for the given entity.
*
* @param EntityInterface $entity
* @param
\Drupal\Core\Entity\
EntityInterface $entity
* The entity to be created or edited.
* @param $operation
* @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.
...
...
@@ -525,7 +457,7 @@ function entity_form_submit(EntityInterface $entity, $operation = 'default', &$f
* $form = entity_get_form($entity, 'default', $form_state);
* @endcode
*
* @return
* @return
array
* The processed form for the given entity and operation.
*
* @deprecated Use \Drupal::entityManager()->getForm() or _entity_form from a
...
...
This diff is collapsed.
Click to expand it.
core/lib/Drupal/Core/Entity/EntityManager.php
+
10
−
3
View file @
1d02be7f
...
...
@@ -288,9 +288,16 @@ protected function getController($entity_type, $controller_type) {
* {@inheritdoc}
*/
public
function
getForm
(
EntityInterface
$entity
,
$operation
=
'default'
,
array
$form_state
=
array
())
{
$form_state
+=
entity_form_state_defaults
(
$entity
,
$operation
);
$form_id
=
$form_state
[
'build_info'
][
'callback_object'
]
->
getFormId
();
return
drupal_build_form
(
$form_id
,
$form_state
);
$form_state
[
'build_info'
]
=
isset
(
$form_state
[
'build_info'
])
?
$form_state
[
'build_info'
]
:
array
();
$controller
=
$this
->
getFormController
(
$entity
->
entityType
(),
$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
);
}
/**
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment