applyUpdates(); // Create three paragraphs to structure the content. $paragraph = Paragraph::create([ 'title' => 'Paragraph 1', 'type' => 'text', 'field_text_demo' => [ 'value' => '

Paragraphs is the new way of content creation!

It allows you — Site Builders — to make things cleaner so that you can give more editing power to your end-users. Instead of putting all their content in one WYSIWYG body field including images and videos, end-users can now choose on-the-fly between pre-defined Paragraph Types independent from one another. Paragraph Types can be anything you want from a simple text block or image to a complex and configurable slideshow.

', 'format' => 'basic_html', ], ]); $paragraph->save(); $paragraph2 = Paragraph::create([ 'title' => 'Paragraph 2', 'type' => 'text', 'field_text_demo' => [ 'value' => '

This demo creates some default Paragraph types from which you can easily create some content (Nested Paragraph, Text, Image + Text, Text + Image, Image and User). It also includes some basic styling and assures that the content is responsive on any device.

', 'format' => 'basic_html', ], ]); $paragraph2->save(); $paragraph3 = Paragraph::create([ 'title' => 'Paragraph 3', 'type' => 'text', 'field_text_demo' => [ 'value' => '

Apart from the included Paragraph types, you can create your own simply by going to Structure -> Paragraphs types.

', 'format' => 'basic_html', ], ]); $paragraph3->save(); $paragraph4 = Paragraph::create([ 'title' => 'Paragraph 4', 'type' => 'text', 'field_text_demo' => [ 'value' => '

A search api example can be found here

', 'format' => 'basic_html', ], ]); $paragraph4->save(); $paragraph5 = Paragraph::create([ 'title' => 'Paragraph 4', 'type' => 'nested_paragraph', 'field_paragraphs_demo' => $paragraph4, ]); $paragraph5->save(); // Add demo content with four paragraphs. $node = Node::create(array( 'type' => 'paragraphed_content_demo', 'title' => 'Welcome to the Paragraphs Demo module!', 'langcode' => 'en', 'uid' => '0', 'status' => 1, 'field_paragraphs_demo' => array( array( 'target_id' => $paragraph->id(), 'target_revision_id' => $paragraph->getRevisionId(), ), array( 'target_id' => $paragraph2->id(), 'target_revision_id' => $paragraph2->getRevisionId(), ), array( 'target_id' => $paragraph3->id(), 'target_revision_id' => $paragraph3->getRevisionId(), ), array( 'target_id' => $paragraph5->id(), 'target_revision_id' => $paragraph5->getRevisionId(), ), ), )); $node->save(); // Set the node as the front page. \Drupal::configFactory()->getEditable('system.site')->set('page.front', '/node/' . $node->id())->save(); }