Support for Drupal 7 is ending on 5 January 2025—it’s time to migrate to Drupal 10! Learn about the many benefits of Drupal 10 and find migration tools in our resource center.
Problem/Motivation
protected function buildAccountForm($operation) {
// @see HtmlEntityFormController::getFormObject()
$entity_type = 'user';
$fields = [];
if ($operation != 'register') {
$fields['uid'] = 2;
}
$entity = $this->container->get('entity_type.manager')
->getStorage($entity_type)
->create($fields);
$this->container->get('entity_type.manager')
->getFormObject($entity_type, $operation)
->setEntity($entity);
// @see EntityFormBuilder::getForm()
return $this->container->get('entity.form_builder')->getForm($entity, $operation);
}
Proposed resolution
code is repeated in \Drupal\Core\Entity\EntityFormBuilder::getForm() so the getFormObject call is not needed.
protected function buildAccountForm($operation) {
// @see HtmlEntityFormController::getFormObject()
$entity_type = 'user';
$fields = [];
if ($operation != 'register') {
$fields['uid'] = 2;
}
$entity = $this->container->get('entity_type.manager')
->getStorage($entity_type)
->create($fields);
// @see EntityFormBuilder::getForm()
return $this->container->get('entity.form_builder')->getForm($entity, $operation);
}
Remaining tasks
- Write a patch
- Review
- Commit
User interface changes
None.
API changes
None.
Data model changes
None.
Comment | File | Size | Author |
---|---|---|---|
#3 | 3154461-3.patch | 773 bytes | Hardik_Patel_12 |
Comments
Comment #2
Hardik_Patel_12 CreditAttribution: Hardik_Patel_12 at QED42 for Drupal India Association commentedComment #3
Hardik_Patel_12 CreditAttribution: Hardik_Patel_12 at QED42 for Drupal India Association commentedKindly review the patch.
Comment #4
Hardik_Patel_12 CreditAttribution: Hardik_Patel_12 at QED42 for Drupal India Association commentedComment #5
vijaycs85Looks good.
Comment #9
catchCommitted/pushed to 9.1.x and backported through to 8.9.x to keep tests in sync. Thanks!