1

public static function baseFieldDefinitionsエンティティを保存しようとしているときにフィールドを削除することで、フィールドが不要になるという印象を受けました。私の関数には、次のもののみが含まれるようになりました。

$fields['id'] = BaseFieldDefinition::create('integer')
  ->setLabel(t('ID'))
  ->setDescription(t('The ID of the Content entity.'))
  ->setReadOnly(TRUE);

$fields['name'] = BaseFieldDefinition::create('string')
  ->setLabel(t('Name'))
  ->setDescription(t('The name of the Content entity.'))
  ->setSettings(array(
    'max_length' => 50,
    'text_processing' => 0,
  ))
  ->setDefaultValue('')
  ->setDisplayOptions('view', array(
    'label' => 'above',
    'type' => 'string',
    'weight' => -4,
  ))
  ->setDisplayOptions('form', array(
    'type' => 'string_textfield',
    'weight' => -4,
  ))
  ->setDisplayConfigurable('form', TRUE)
  ->setDisplayConfigurable('view', TRUE);

ただし、エンティティを追加しようとすると、次の例外が返されます。Uncaught PHP Exception InvalidArgumentException: "Field changed is unknown." at /var/www/html/core/lib/Drupal/Core/Entity/ContentEntityBase.php line 474

コンテンツ エンティティを作成するのはこれが初めての試みなので、間違っている可能性があります。

4

0 に答える 0