【问题标题】:Drupal 8 Render User Profile Form in custom module自定义模块中的 Drupal 8 渲染用户配置文件表单
【发布时间】:2019-03-07 14:06:09
【问题描述】:

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

这是我迄今为止在控制器中所做的:

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

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

【问题讨论】:

    标签: php forms drupal-8 form-api


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

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2019-02-12
      • 2023-03-12
      相关资源
      最近更新 更多