我是drupal的新手,我需要一些帮助。
我创建了一个名为user_extra
的新模块。在安装模块时创建necessery表。
但我还需要在'users_field_data'
表('user_extra_id'
和'user_office'
)中插入一些数据库字段
在baseFieldDefinitions
中,我为user_extra
表编写了所有necessery数据库表字段。
public static function baseFieldDefinitions(EntityTypeInterface $entity_type) {
// Standard field, used as a unique if primary index.
$fields['id'] = BaseFieldDefinition::create('integer')
->setLabel(t('Unit ID'))
->setDescription(t('The unit ID.'))
->setReadOnly(TRUE)
->setSetting('unsigned', TRUE);
$fields['uuid'] = BaseFieldDefinition::create('uuid')
->setLabel(t('UUID'))
->setDescription(t('The unit UUID.'))
->setReadOnly(TRUE);
.
.
.
$fields['user_info'] = BaseFieldDefinition::create('string')
->setLabel(t('User Info'))
->setDescription(t("The User Info"))
->setSetting('max_length', 255)
->setDisplayOptions('form', array(
'type' => 'string_textfield',
'weight' => 10,
))
->setDisplayConfigurable('form', TRUE);
return $fields;
}
安装模块时,它会插入我在baseFieldDefinitions
中定义的所有值。
但我还需要在'user_extra_id'
表中使用'user_office'
和'users_field_data'
选项创建setDisplayOptions
和setDisplayConfigurable
。
这是我在实体档案中发表的评论
/**
* @ContentEntityType(
* id = "user_extra",
* label = @Translation("user extra"),
* handlers = {
* "storage" = "Drupal\user_extra\UserextraStorage",
* "storage_schema" = "Drupal\user_extra\UserextraStorageSchema",
* "access" = "Drupal\user_extra\UserextraAccessControlHandler",
* "list_builder" = "Drupal\user_extra\UserextraListBuilder",
* "view_builder" = "Drupal\user_extra\UserextraViewBuilder",
* "views_data" = "Drupal\user_extra\UserextraViewsData",
* "form" = {
* "default" = "Drupal\user_extra\Form\UserextraForm",
* "add" = "Drupal\user_extra\Form\UserextraAddForm",
* "edit" = "Drupal\user_extra\Form\UserextraEditForm",
* "delete" = "Drupal\user_extra\Form\UserextraDeleteForm",
* }
* },
* admin_permission = "administer user_extra",
* base_table = "user_extra",
* entity_keys = {
* "id" = "id",
* "label" = "name",
* "uuid" = "uuid",
* },
* links = {
* "canonical" = "/admin/user_extra/{user_extra}",
* "add-form" = "/admin/user_extra/add",
* "delete-form" = "/admin/user_extra/{user_extra}/delete",
* "overview-form" = "/admin/user_extra/${user_extra}/overview",
* "edit-form" = "/admin/user_extra/{user_extra}",
* "collection" = "/admin/user_extra",
* "children" = "/admin/user_extra/{user_extra}/children",
* },
* )
*/