4 * Installation hooks for paragraphs_demo module.
7 use Drupal\node\Entity\Node;
8 use Drupal\paragraphs\Entity\Paragraph;
11 * Implements hook_install().
13 function paragraphs_demo_install() {
14 // Ensure the translation fields are created in the database.
15 \Drupal::service('entity.definition_update_manager')->applyUpdates();
17 // Create three paragraphs to structure the content.
18 $paragraph = Paragraph::create([
19 'title' => 'Paragraph 1',
21 'field_text_demo' => [
22 'value' => '<h2>Paragraphs is the new way of content creation!</h2>
23 <p>It allows you — Site Builders — to make things cleaner so that you can give more editing power to your end-users.
24 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.</p>',
25 'format' => 'basic_html',
30 $paragraph2 = Paragraph::create([
31 'title' => 'Paragraph 2',
33 'field_text_demo' => [
34 'value' => '<p>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.</p>',
35 'format' => 'basic_html',
40 $paragraph3 = Paragraph::create([
41 'title' => 'Paragraph 3',
43 'field_text_demo' => [
44 'value' => '<p>Apart from the included Paragraph types, you can create your own simply by going to Structure -> Paragraphs types.</p>',
45 'format' => 'basic_html',
50 $paragraph4 = Paragraph::create([
51 'title' => 'Paragraph 4',
53 'field_text_demo' => [
54 'value' => '<p>A search api example can be found <a href="/paragraphs_search">here</a></p>',
55 'format' => 'basic_html',
60 $paragraph5 = Paragraph::create([
61 'title' => 'Paragraph 4',
62 'type' => 'nested_paragraph',
63 'field_paragraphs_demo' => $paragraph4,
67 // Add demo content with four paragraphs.
68 $node = Node::create(array(
69 'type' => 'paragraphed_content_demo',
70 'title' => 'Welcome to the Paragraphs Demo module!',
74 'field_paragraphs_demo' => array(
76 'target_id' => $paragraph->id(),
77 'target_revision_id' => $paragraph->getRevisionId(),
80 'target_id' => $paragraph2->id(),
81 'target_revision_id' => $paragraph2->getRevisionId(),
84 'target_id' => $paragraph3->id(),
85 'target_revision_id' => $paragraph3->getRevisionId(),
88 'target_id' => $paragraph5->id(),
89 'target_revision_id' => $paragraph5->getRevisionId(),
94 // Set the node as the front page.
95 \Drupal::configFactory()->getEditable('system.site')->set('page.front', '/node/' . $node->id())->save();