魑魅魍魉魃魈魁魅 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 依据报错在原代吗格式的基础上解决问题
    • ¥15 在虚拟机中安装flash code
    • ¥15 单片机stm32f10x编写光敏电阻调节3.3伏大功率灯亮度(光强越大灯越暗,白天正常光强灯不亮,使用ADC,PWM等模块)望各位找一下错误或者提供一个可实现功能的代码
    • ¥20 verilog状态机方法流水灯
    • ¥15 pandas代码实现不了意图
    • ¥15 GD32H7 从存储器到外设SPI传输数据无法重复启用DMA
    • ¥25 LT码在高斯信道下的误码率仿真
    • ¥45 渲染完成之后将物体的材质贴图改变,自动化进行这个操作
    • ¥15 yolov5目标检测并显示目标出现的时间或视频帧
    • ¥15 电视版的优酷可以设置电影连续播放吗?