自定义模块中的 Drupal 8 渲染用户配置文件表单

Drupal 8 Render User Profile Form in custom module

我是 Drupal 8 的新手,我想从将通过自定义模块创建的某个页面中呈现用户配置文件 (user/[user_id]/edit)。我想这样做是因为我希望用户无需转到用户/[user_id]/编辑页面即可编辑他们的个人资料。

这是我目前在我的控制器中所做的:

namespace Drupal\my_account\Controller
use Drupal\user\ProfileForm

class MyAccountController{
  public function content(){
   $entity = \Drupal::entityManager()
  ->getStorage('user')
  ->create(array());

  $formObject = \Drupal::entityManager()
  ->getFormObject('user', 'default')
  ->setEntity($entity);

$form = \Drupal::formBuilder()->getForm($formObject);

    return ['form'=>$form];
  }
}

它设法显示表单但没有用户内容。

  1. 准备好要用来加载数据的用户对象。
  2. Drupal::formBuilder()->getForm(Drupal\user\ProfileForm::class, $user_obj)