function _paragraphs_collection_demo_create_demo_article_1

Creates demo content.

Return value

\Drupal\Core\Entity\EntityInterface Returns node.

1 call to _paragraphs_collection_demo_create_demo_article_1()
paragraphs_collection_demo_install in paragraphs_collection/modules/paragraphs_collection_demo/paragraphs_collection_demo.install
Implements hook_install().

File

paragraphs_collection/modules/paragraphs_collection_demo/paragraphs_collection_demo.install, line 294
Installation hooks for paragraphs_collection_demo module.

Code

function _paragraphs_collection_demo_create_demo_article_1() {
  $paragraphs = [];

  // Create title paragraph.
  $title_paragraph = Paragraph::create([
    'type' => 'title',
    'paragraphs_title' => [
      'value' => 'The awesome new paragraph types',
    ],
  ]);
  $title_paragraph
    ->save();
  $paragraphs[] = $title_paragraph;

  // Create subtitle paragraph.
  $title_paragraph = Paragraph::create([
    'type' => 'subtitle',
    'paragraphs_subtitle' => [
      'value' => 'Exploring all new types',
    ],
  ]);
  $title_paragraph
    ->save();
  $paragraphs[] = $title_paragraph;

  // Create intro paragraph.
  $intro_paragraph = Paragraph::create([
    'type' => 'intro',
    'paragraphs_intro' => [
      'value' => '<p>Introduces powerful plugin system to attach behaviors to paragraph types.</p>',
      'format' => 'basic_html',
    ],
  ]);
  $intro_paragraph
    ->save();
  $paragraphs[] = $intro_paragraph;

  // Create text paragraph.
  $intro_paragraph = Paragraph::create([
    'type' => 'text',
    'paragraphs_text' => [
      'value' => '<p>Donec efficitur nisl diam, at finibus odio maximus ut. Ut diam nulla, tempus eget lacinia a, feugiat quis sapien. Mauris at erat pellentesque, malesuada mauris nec, vulputate leo. Nulla ultricies pharetra finibus. Integer placerat tempus orci, in bibendum lorem venenatis sit amet. Morbi viverra congue sapien, ac rhoncus sapien gravida sed. Donec malesuada turpis eu erat consectetur, sed semper elit finibus. Curabitur efficitur fringilla urna sollicitudin ultricies. Phasellus consectetur risus quis ex ultricies luctus.</p>
<p>In semper massa ante, vitae viverra metus sollicitudin varius. Mauris tempor lectus maximus nulla mattis maximus. In at volutpat diam. Nulla at velit ornare, sollicitudin neque sit amet, molestie massa. In et justo quis nibh mollis elementum. Fusce eget metus a tortor rutrum ornare quis a orci. Fusce volutpat sem ac mi pretium, eu rhoncus nisi convallis. Morbi sollicitudin tellus sit amet dui ultrices malesuada eget nec lacus. Vivamus pulvinar mattis vehicula. Cras dictum ut quam non pellentesque.</p>',
      'format' => 'basic_html',
    ],
  ]);
  $intro_paragraph
    ->save();
  $paragraphs[] = $intro_paragraph;

  // Create separator paragraph.
  $separator_paragraph = Paragraph::create([
    'type' => 'separator',
  ]);
  $separator_paragraph
    ->save();
  $paragraphs[] = $separator_paragraph;

  // Create quote paragraph.
  $quote_paragraph = Paragraph::create([
    'type' => 'quote',
    'paragraphs_quote_text' => [
      'value' => '<p>You must be the change you wish to see in the world.</p>',
      'format' => 'basic_html',
    ],
    'paragraphs_quote_author' => [
      'value' => 'Mahatma Gandhi',
    ],
  ]);
  $quote_paragraph
    ->save();
  $paragraphs[] = $quote_paragraph;

  // Create an image.
  $filename = 'nasa-43566.jpg';
  \Drupal::service('file_system')
    ->copy(\Drupal::service('extension.list.module')
    ->getPath('paragraphs_collection_demo') . '/files/' . $filename, 'public://' . $filename);
  $image = File::create([
    'uri' => 'public://' . $filename,
  ]);
  $image
    ->save();

  // Create image + text paragraph.
  $images_text_paragraph = Paragraph::create([
    'type' => 'image_text',
    'paragraphs_image' => [
      'target_id' => $image
        ->id(),
      'alt' => 'alternative text for an image',
      'title' => 'Image title',
    ],
    'paragraphs_text' => [
      'value' => '<p>This is an example text that goes along with the image in an Images + Text paragraph type.</p>',
      'format' => 'basic_html',
    ],
  ]);
  $images_text_paragraph
    ->save();
  $paragraphs[] = $images_text_paragraph;

  // Create user paragraph.
  $user = User::getAnonymousUser();
  $user_paragraph = Paragraph::create([
    'type' => 'user',
    'paragraphs_user' => [
      'target_id' => $user
        ->id(),
    ],
  ]);
  $user_paragraph
    ->save();
  $paragraphs[] = $user_paragraph;

  // Create footer paragraph.
  $footer_paragraph = Paragraph::create([
    'type' => 'footer',
    'paragraphs_footer' => [
      'value' => '<p>So what awesome solution YOU are going to build with paragraphs?</p>',
      'format' => 'basic_html',
    ],
  ]);
  $footer_paragraph
    ->save();
  $paragraphs[] = $footer_paragraph;

  // Create the demo node.
  return _paragraphs_collection_demo_create_node('Paragraphs Collection Fundamental Types', $paragraphs);
}