简体   繁体   English

自定义模块中的Drupal 8 Render用户配置文件表格

[英]Drupal 8 Render User Profile Form in custom module

I'm pretty new to Drupal 8 and I wanted to render the user profile (user/[user_id]/edit) from in a certain page which will be created through a custom module. 我是Drupal 8的新手,我想在某个页面中渲染用户配置文件(user / [user_id] / edit),该页面将通过自定义模块创建。 I wanted to this because I want the users to edit their profile without going to the user/[user_id]/edit page. 我想要这样做是因为我希望用户无需进入user / [user_id] / edit页面即可编辑其个人资料。

here's what I have done so far in my controller: 到目前为止,这是我在控制器中所做的:

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];
  }
}

It manages to display the form but no user contents. 它设法显示表单,但没有用户内容。

  1. Get your user object ready with which you want to load data. 准备好您要用来加载数据的用户对象。
  2. Drupal::formBuilder()->getForm(Drupal\\user\\ProfileForm::class, $user_obj) Drupal :: formBuilder()-> getForm(Drupal \\ user \\ ProfileForm :: class,$ user_obj)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM