Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/drupal/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Drupal 以编程方式翻译嵌套段落_Drupal_Drupal 8 - Fatal编程技术网

Drupal 以编程方式翻译嵌套段落

Drupal 以编程方式翻译嵌套段落,drupal,drupal-8,Drupal,Drupal 8,我已经翻译了带有段落字段的节点(内容已经存在,所有实体都可以翻译)。我在第一个段落字段中添加了一个嵌套段落字段。我的目标是以编程方式添加已翻译的嵌套段落 但当我运行更新时,已翻译节点上的段落仍然是原始语言(未翻译)。我做错了什么 $node = $nodeStorage->load($nid); $paragraphs = $node->get('field_content')->referencedEntities(); // Initialize new $nested i

我已经翻译了带有段落字段的节点(内容已经存在,所有实体都可以翻译)。我在第一个段落字段中添加了一个嵌套段落字段。我的目标是以编程方式添加已翻译的嵌套段落

但当我运行更新时,已翻译节点上的段落仍然是原始语言(未翻译)。我做错了什么

$node = $nodeStorage->load($nid);
$paragraphs = $node->get('field_content')->referencedEntities();
// Initialize new $nested items - THIS PART WORKS.
foreach($paragraphs as $paragraph) {
  $nested = Paragraph::create(['type' => 'my_type',]);
  $nested->set('field_text', 'Some Value.');
  $nested->save();
  $paragraph->get('field_paragraphs')->appendItem($nested);
  $paragraph->save();
  $node->save();
  }
}
// Add $nested translations - THIS PART DOESN'T WORK
$languages = $node->getTranslationLanguages();
  foreach ($languages as $language) {
  $langcode = $language->getId();
  $translation = $node->getTranslation($langcode);
  $paragraphs = $translation->get('field_content')->referencedEntities();
  // Set first picture values.
  foreach ($paragraphs as $paragraph) {
    $paragraph_translation = $paragraph->getTranslation($langcode);
    $nested = $picture->get('field_paragraphs')->referencedEntities();
    $nested = reset($picture_item);
    $newValues = [
      'field_text => 'Translated value',
    ];
    $nested->addTranslation($langcode, $values);
    $nested->save();
    $picture->save();
    $translation->save();
  }
}
$node = $nodeStorage->load($nid);
$paragraphs = $node->get('field_content')->referencedEntities();
// Initialize new $nested items - THIS PART WORKS.
foreach($paragraphs as $paragraph) {
  $nested = Paragraph::create(['type' => 'my_type',]);
  $nested->set('field_text', 'Some Value.');
  $nested->save();
  $paragraph->get('field_paragraphs')->appendItem($nested);
  $paragraph->save();
  $node->save();
  }
}
// Add $nested translations - THIS PART DOESN'T WORK
$languages = $node->getTranslationLanguages();
  foreach ($languages as $language) {
  $langcode = $language->getId();
  $translation = $node->getTranslation($langcode);
  $paragraphs = $translation->get('field_content')->referencedEntities();
  // Set first picture values.
  foreach ($paragraphs as $paragraph) {
    $paragraph_translation = $paragraph->getTranslation($langcode);
    $nested = $picture->get('field_paragraphs')->referencedEntities();
    $nested = reset($picture_item);
    $newValues = [
      'field_text => 'Translated value',
    ];
    $nested->addTranslation($langcode, $values);
    $nested->save();
    $picture->save();
    $translation->save();
  }
}