Php 如何在Drupal8中以编程方式创建角色?
如何在Drupal8中以编程方式创建角色 我做错了什么Php 如何在Drupal8中以编程方式创建角色?,php,drupal,roles,drupal-8,security-roles,Php,Drupal,Roles,Drupal 8,Security Roles,如何在Drupal8中以编程方式创建角色 我做错了什么 $role = \Drupal\user\Entity\Role::create(['id' => 'client', 'name' => 'Client']); $role->save(); 问题在于数据数组按标签更改名称: 或者您可以使用: //your data array $data = array('id' => 'client', 'label' => 'Client'); //creating
$role = \Drupal\user\Entity\Role::create(['id' => 'client', 'name' => 'Client']);
$role->save();
问题在于数据数组按标签更改名称: 或者您可以使用:
//your data array
$data = array('id' => 'client', 'label' => 'Client');
//creating your role
$role = \Drupal\user\Entity\Role::create($data);
//saving your role
$role->save();
我更新我的答案;-)我的答案代码有效,我测试它:-)
//your data array
$data = array('id' => 'client', 'label' => 'Client');
//creating your role
$role = \Drupal\user\Entity\Role::create($data);
//saving your role
$role->save();