#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
#代码:
<?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();
}
}