如何在单独的表drupal8中存储自定义字段类型?

时间:2019-01-17 13:45:07

标签: drupal drupal-8

自定义字段类型列将保存在实体的基表中。

我有一个自定义实体“事件”。我想要一个单独的数据库表来存储其他实体数据。因此,我创建了一个具有4列且基数为2的自定义字段类型。已将该字段添加到我的自定义实体中。但是字段列将保存在基表中。我希望它们存储在单独的表(如节点)中。我想念什么?

我的事件文件是:Drupal \ event \ Entity \ EventEntity.php

We couldn't connect to Azure DevOps with your credentials.

我的字段类型代码是 Drupal \ event \ Plugin \ Field \ FieldType \ EventConfigField.php

/**
 * Defines the Event entity.
 *
 * @ingroup event
 * @ContentEntityType(
 *   id = "event_entity",
 *   label = @Translation("Event entity"),
 *   base_table = "event",
 *   fieldable = TRUE,
 *   handlers = {
 *     "view_builder" = "Drupal\Core\Entity\EntityViewBuilder",
 *     "list_builder" = "Drupal\event\Controller\EventListBuilder",
 *     "form" = {
 *       "add" = "Drupal\event\Form\EventEntityForm",
 *       "edit" = "Drupal\event\Form\EventEntityForm",
 *       "delete" = "Drupal\event\Form\EventEntityDeleteForm",
 *     }
 *   },
 *   admin_permission = "administer event_entity entity",
 *   entity_keys = {
 *     "id" = "id",
 *     "event_name" = "event_name",
 *     "image" = "image",
 *     "user_id" = "user_id",
 *     "created" = "created",
 *     "changed" = "changed",
 *   },
 *   links = {
 *     "canonical" = "/admin/event_entity/{event_entity}",
 *     "edit-form" = "/admin/event_entity/{event_entity}/edit",
 *     "delete-form" = "/admin/event_entity/{event_entity}/delete",
 *     "collection" = "/admin/event_entity/list"
 *  }
 * )
 */
class EventEntity extends ContentEntityBase implements 
EventEntityInterface , EntityPublishedInterface {
....
 public static function baseFieldDefinitions(EntityTypeInterface 
  $entity_type) {
   $fields = parent::baseFieldDefinitions($entity_type);   
    .......

  $fields['event_settings'] = 
    BaseFieldDefinition::create('event_entity_field')
      ->setLabel(t('Event Settings'))
      ->setSettings([
     'multiple' => TRUE,
      ])
      ->setCardinality(2)
      ->setDisplayConfigurable('form', TRUE);
    return $fields;
  }

0 个答案:

没有答案