魑魅魍魉魃魈魁魅 2021-09-30 16:12
浏览 17
已结题

drupal 自定义实体报错:The id field definition does not exist and it is used as id entity key

#The id field definition does not exist and it is used as id entity key
我自定义了一个日志实体,但是在安装module的时候报错:The id field definition does not exist and it is used as id entity key

img

#代码:

img

<?php

namespace Drupal\ixtend_log\Entity;

use Drupal\Core\Entity\ContentEntityBase;
use Drupal\Core\Entity\ContentEntityInterface;
use Drupal\Core\Entity\EntityTypeInterface;
use Drupal\Core\Field\BaseFieldDefinition;

/**
 * Defines the ixtend_custom_log entity.
 *
 * @ContentEntityType(
 *   id = "ixtend_custom_log",
 *   label = @Translation ("Ixtend Log"),
 *   base_table = "ixtend_log",
 *   entity_keys = {
 *     "id" = "id",
 *     "uuid" = "uuid",
 *   },
 *   handlers = {
 *     "views_data" = "Drupal\views\IxtendLogViewsData",
 *   },
 * )
 */
class IxtendLog extends ContentEntityBase implements ContentEntityInterface {

  /**
   * {@inheritdoc}
   */
  public static function baseFieldDefinitions(EntityTypeInterface $entity_type) {
    $fields = parent::baseFieldDefinitions($entity_type);

    $fields['user_id'] = BaseFieldDefinition::create('entity_reference')
      ->setLabel(t('Created by'))
      ->setSetting('target_type', 'user')
      ->setDefaultValueCallback(static::class . "::getDefaultEntityCreator");

    $fields['created'] = BaseFieldDefinition::create('created')
      ->setLabel(t('Created'))
      ->setDescription(t('The time that the log created.'));

    $fields['message'] = BaseFieldDefinition::create('string_long')
      ->setLabel(t('Message'));

  }

  /**
   * Default value callback for 'uid' base field.
   *
   * @return mixed
   *   A default value for the uid field.
   */
  public static function getDefaultEntityCreator() {
    return \Drupal::currentUser()->id();
  }

}


  • 写回答

0条回答 默认 最新

    报告相同问题?

    问题事件

    • 系统已结题 10月8日
    • 创建了问题 9月30日

    悬赏问题

    • ¥15 如何让企业微信机器人实现消息汇总整合
    • ¥50 关于#ui#的问题:做yolov8的ui界面出现的问题
    • ¥15 如何用Python爬取各高校教师公开的教育和工作经历
    • ¥15 TLE9879QXA40 电机驱动
    • ¥20 对于工程问题的非线性数学模型进行线性化
    • ¥15 Mirare PLUS 进行密钥认证?(详解)
    • ¥15 物体双站RCS和其组成阵列后的双站RCS关系验证
    • ¥20 想用ollama做一个自己的AI数据库
    • ¥15 关于qualoth编辑及缝合服装领子的问题解决方案探寻
    • ¥15 请问怎么才能复现这样的图呀