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

  1. Write a patch
  2. Review
  3. Commit

User interface changes

None.

API changes

None.

Data model changes

None.

CommentFileSizeAuthor
#3 3154461-3.patch773 bytesHardik_Patel_12
Support from Acquia helps fund testing for Drupal Acquia logo

Comments

Hardik_Patel_12 created an issue. See original summary.

Hardik_Patel_12’s picture

Issue summary: View changes
Hardik_Patel_12’s picture

Status: Active » Needs review
FileSize
773 bytes

Kindly review the patch.

Hardik_Patel_12’s picture

vijaycs85’s picture

Status: Needs review » Reviewed & tested by the community

Looks good.

  • catch committed e76396d on 9.1.x
    Issue #3154461 by Hardik_Patel_12: Removing getFormObject call from...

  • catch committed e6beb02 on 9.0.x
    Issue #3154461 by Hardik_Patel_12: Removing getFormObject call from...

  • catch committed 7feeb44 on 8.9.x
    Issue #3154461 by Hardik_Patel_12: Removing getFormObject call from...
catch’s picture

Version: 9.1.x-dev » 8.9.x-dev
Status: Reviewed & tested by the community » Fixed

Committed/pushed to 9.1.x and backported through to 8.9.x to keep tests in sync. Thanks!

Status: Fixed » Closed (fixed)

Automatically closed - issue fixed for 2 weeks with no activity.