+++ /dev/null
-<?php
-/**
- * @file
- * Installation hooks for paragraphs_demo module.
- */
-
-use Drupal\node\Entity\Node;
-use Drupal\paragraphs\Entity\Paragraph;
-
-/**
- * Implements hook_install().
- */
-function paragraphs_demo_install() {
- // Ensure the translation fields are created in the database.
- \Drupal::service('entity.definition_update_manager')->applyUpdates();
-
- // Create three paragraphs to structure the content.
- $paragraph = Paragraph::create([
- 'title' => 'Paragraph 1',
- 'type' => 'text',
- 'field_text_demo' => [
- 'value' => '<h2>Paragraphs is the new way of content creation!</h2>
- <p>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.</p>',
- 'format' => 'basic_html',
- ],
- ]);
- $paragraph->save();
-
- $paragraph2 = Paragraph::create([
- 'title' => 'Paragraph 2',
- 'type' => 'text',
- 'field_text_demo' => [
- '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>',
- 'format' => 'basic_html',
- ],
- ]);
- $paragraph2->save();
-
- $paragraph3 = Paragraph::create([
- 'title' => 'Paragraph 3',
- 'type' => 'text',
- 'field_text_demo' => [
- 'value' => '<p>Apart from the included Paragraph types, you can create your own simply by going to Structure -> Paragraphs types.</p>',
- 'format' => 'basic_html',
- ],
- ]);
- $paragraph3->save();
-
- $paragraph4 = Paragraph::create([
- 'title' => 'Paragraph 4',
- 'type' => 'text',
- 'field_text_demo' => [
- 'value' => '<p>A search api example can be found <a href="/paragraphs_search">here</a></p>',
- '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();
-}