Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
I
inline_entity_form
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
inline_entity_form
Merge requests
!88
Issue
#2702401
: Add integration for the user entity type
Code
Review changes
Check out branch
Download
Patches
Plain diff
Open
Issue
#2702401
: Add integration for the user entity type
issue/inline_entity_form-2702401:2702401-add-integration-for
into
8.x-1.x
Overview
2
Commits
2
Pipelines
0
Changes
2
2 unresolved threads
Hide all comments
Open
Jerry Radwick
requested to merge
issue/inline_entity_form-2702401:2702401-add-integration-for
into
8.x-1.x
1 year ago
Overview
2
Commits
2
Pipelines
0
Changes
2
2 unresolved threads
Hide all comments
Expand
0
0
Merge request reports
Compare
8.x-1.x
version 1
087edf13
1 year ago
8.x-1.x (HEAD)
and
latest version
latest version
574ef5e5
2 commits,
1 year ago
version 1
087edf13
1 commit,
1 year ago
2 files
+
92
−
0
Inline
Compare changes
Side-by-side
Inline
Show whitespace changes
Show one file at a time
Files
2
Search (e.g. *.vue) (Ctrl+P)
src/Form/UserInlineForm.php
0 → 100644
+
88
−
0
Options
<?php
namespace
Drupal\inline_entity_form\Form
;
use
Drupal\Core\Entity\EntityInterface
;
use
Drupal\Core\Form\FormStateInterface
;
use
Drupal\Core\Render\Element
;
use
Drupal\user\AccountForm
;
/**
* User inline form handler.
*/
class
UserInlineForm
extends
EntityInlineForm
{
protected
?AccountForm
$accountForm
;
protected
?FormStateInterface
$accountFormState
;
public
function
getEntityTypeLabels
()
{
return
[
'singular'
=>
$this
->
entityType
->
getSingularLabel
(),
'plural'
=>
$this
->
entityType
->
getPluralLabel
(),
];
}
public
function
entityForm
(
array
$entity_form
,
FormStateInterface
$form_state
)
{
$user_form_object
=
$this
->
getUserFormObject
(
$entity_form
[
'#entity'
],
$form_state
,
$entity_form
[
'#form_mode'
]);
// Copy user base fields items into the main entity form object.
$user_form
=
$user_form_object
->
form
(
$entity_form
,
$form_state
);
foreach
(
Element
::
children
(
$user_form
)
as
$field_name
)
{
$entity_form
[
$field_name
]
=
$user_form
[
$field_name
];
}
return
parent
::
entityForm
(
$entity_form
,
$form_state
);
}
/**
* Builds an updated entity object based upon the submitted form values.
*/
protected
function
buildEntity
(
array
$entity_form
,
EntityInterface
$entity
,
FormStateInterface
$form_state
)
{
/** @var \Drupal\user\UserInterface $entity */
parent
::
buildEntity
(
$entity_form
,
$entity
,
$form_state
);
$this
->
accountFormState
=
clone
$form_state
;
$this
->
accountFormState
->
setValues
(
$form_state
->
getValue
(
$entity_form
[
'#parents'
])[
'account'
]);
$user_entity
=
$this
->
accountForm
->
buildEntity
(
$entity_form
,
$this
->
accountFormState
);
foreach
(
$user_entity
->
getFields
()
as
$field_name
=>
$field_value
)
{
$entity
->
set
(
$field_name
,
$field_value
->
getValue
());
}
// Uncomment to allow resubmitting the form without having to face
// integrity constraint error on every submit.
// $entity->setEmail(uniqid() . '@example.com');
}
/**
* Internal helper.
*
* Returns handler for the user form.
*
* @param \Drupal\Core\Entity\ContentEntityInterface $entity
* User account entity.
* @param \Drupal\Core\Form\FormStateInterface $form_state
* Current form state.
* @param string $form_mode
* User form mode (usually it's "register").
*
* @return \Drupal\Core\Form\FormInterface
* User account form.
*/
protected
function
getUserFormObject
(
EntityInterface
$entity
,
FormStateInterface
$form_state
,
string
$form_mode
):
AccountForm
{
/** @var \Drupal\user\RegisterForm $user_form_object */
$this
->
accountForm
=
$this
->
entityTypeManager
->
getFormObject
(
$entity
->
getEntityTypeId
(),
$form_mode
);
$this
->
accountForm
->
setEntity
(
$entity
);
$form_display
=
$this
->
getFormDisplay
(
$entity
,
$form_mode
);
$this
->
accountForm
->
setFormDisplay
(
$form_display
,
$form_state
);
return
$this
->
accountForm
;
}
}
Loading