【发布时间】:2021-10-27 06:47:16
【问题描述】:
我知道有这个解决方案 (https://drupal.stackexchange.com/questions/213379/programmatically-update-an-entity-reference-field)
但我没有为我工作,我有一个错误: Drupal\Core\Entity\EntityStorageException: SQLSTATE[01000]: 警告: 1265 数据在第 1 行被截断为“created”列:INSERT INTO {taxonomy_index} (nid, tid, status, sticky, created) VALUES (:db_insert_placeholder_0, :db_insert_placeholder_1 , :db_insert_placeholder_2, :db_insert_placeholder_3, :db_insert_placeholder_4);数组( [:db_insert_placeholder_0] => 791 [:db_insert_placeholder_1] => 10 [:db_insert_placeholder_2] => 1 [:db_insert_placeholder_3] => 0 [:db_insert_placeholder_4] => 2021-08-17T12:32:12.397 )在 Drupal\Core \Entity\Sql\SqlContentEntityStorage->save()(core\lib\Drupal\Core\Entity\Sql\SqlContentEntityStorage.php 的第 846 行)。
当我尝试使用实体引用字段创建节点时。 该实体是一个分类术语,不需要创建它们。 我使用 API 调用来填充我的内容类型。
这是我的代码:
$newJob = Node::create([
'type' => 'jobs',
'title' => $job->label,
'uid' => 219,
'field_api_id' => $job->id,
'created' => $job->publishedDate,
'field_jobs_title_function' => [
'value' => $job->label
],
'field_jobs_purpose' => [
'value' => !is_object($job->JobDataSet->JobData->role) ? $job->JobDataSet->JobData->role : '',
'format' => 'full_html_no_ckeditor'
],
'field_jobs_how_to_apply' => [
'value' => !is_object($job->JobDataSet->JobData->requiredFiles) ? $job->JobDataSet->JobData->requiredFiles : '',
'format' => 'full_html_no_ckeditor'
],
'field_link_cta' => [
'uri' => !is_object($job->JobDataSet->JobData->applyUrl) ? $job->JobDataSet->JobData->applyUrl : '',
'title' => 'Postuler maintenant !'
],
]);
$newJob->setPublished(TRUE);
$newJob->save();
$newJob->field_domain->target_id = $domain;
$newJob->save();
$domain 是现有分类术语的 int 对应项,当我加载它时它可以工作:
Term::load($domain);
但是当我想创建节点时,我总是遇到错误 SQLSTATE[01000]。
我试过了:
,
'field_domain' => [
'target_id' => $domain
],
$newJob->field_domain->target_id = $domain;
为什么这对 Drupal 不正确? 谢谢你
【问题讨论】:
-
在不添加实体引用的情况下是否可以工作?
-
不,它不起作用