Email us at info@henrytech.org to discuss your Drupal Migration today!
Create a paragraph
use Drupal\node\Entity\Node; use Drupal\paragraphs\Entity\Paragraph; $paragraph_1 = Paragraph::create([ 'type' => 'paragraph_type_1', //machine name of paragraph 'field_text' => [ 'value' => 'Some text', 'format' => 'full_html', ], ]); $paragraph_1->save();
Create a nested paragraph
$paragraph_2 = Paragraph::create([ 'type' => 'paragraph_type_2', //machine name of paragraph 'field_text' => [ 'value' => 'Jesus Saves', 'format' => 'full_html', ], 'field_paragraph_reference' => $paragraph_1, ]); $paragraph_2->save();
$node->field_content->appendItem($paragraph_2); $node->save();
Comments