0

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. I wanted to this because I want the users to edit their profile without going to the user/[user_id]/edit page.

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.

4

1 回答 1

0
  1. 准备好要加载数据的用户对象。
  2. Drupal::formBuilder()->getForm(Drupal\user\ProfileForm::class, $user_obj)
于 2018-10-08T10:00:37.290 回答