Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save Eduardo-Morales-Alberti/3c36a9262f632fef3b81c4b8a9e62f33 to your computer and use it in GitHub Desktop.
Save Eduardo-Morales-Alberti/3c36a9262f632fef3b81c4b8a9e62f33 to your computer and use it in GitHub Desktop.
Create paragraphs on node
$paragraph_item = Paragraph::create([
'type' => 'html',
'title' => 'Testing',
'field_texto_largo_con_formato' => 'body test',
]);
$paragraph_item->save();
$paragraph_w = ParagraphWrapper::create([
'type' => 'html',
'title' => 'paragraph wrapper',
'paragraph_items' => [
'target_id' => $paragraph_item->id(),
'target_revision_id' => $paragraph_item->getRevisionId(),
],
]);
$paragraph_w->save();
// Create node object with attached file.
$node = Node::create([
'type' => 'ofertas',
'title' => 'Druplicon test 2',
'status' => 1,
'moderation_state' => 'published',
'field_tipo_de_oferta' => 'Empleo',
'field_texto_plano' => 'Locaaalización',
'field_node_paragraphs' => [
'target_id' => $paragraph_w->id(),
'target_revision_id' => $paragraph_w->getRevisionId(),
],
]);
$node->save();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment