Skip to content
Snippets Groups Projects
Commit 7693088b authored by Sascha Grossenbacher's avatar Sascha Grossenbacher
Browse files

Issue #3508707 by berdir: Demo test is failing

parent 0c6e7260
No related branches found
No related tags found
1 merge request!175move from hook_install() to hook_modules_installed()
Pipeline #435063 passed with warnings
<?php
/**
* @file
* Installation hooks for paragraphs_demo module.
*/
use Drupal\node\Entity\Node;
use Drupal\paragraphs\Entity\Paragraph;
use Drupal\paragraphs_library\Entity\LibraryItem;
use Drupal\workflows\Entity\Workflow;
/**
* Implements hook_install().
*/
function paragraphs_demo_install() {
if (version_compare(\Drupal::VERSION, '8.6.99', '<=')) {
// 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([
'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([
'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([
'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([
'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([
'type' => 'nested_paragraph',
'field_paragraphs_demo' => $paragraph4,
]);
$paragraph5->save();
// PARAGRAPH DEMO ITEM: library items.
$library_text_paragraph = Paragraph::create([
'type' => 'text',
'field_text_demo' => [
'value' => 'This is content from the library. We can reuse it multiple times without duplicating it.',
'format' => 'plain_text',
],
]);
$library_text_paragraph->save();
$library_item = LibraryItem::create([
'label' => 'Library item',
'paragraphs' => [
$library_text_paragraph,
],
]);
$library_item->save();
$from_library = Paragraph::create([
'type' => 'from_library',
'field_reusable_paragraph' => [
$library_item,
],
]);
$from_library->save();
// Add demo content with four paragraphs.
$node = Node::create([
'type' => 'paragraphed_content_demo',
'title' => 'Welcome to the Paragraphs Demo module!',
'langcode' => 'en',
'uid' => '0',
'status' => 1,
'field_paragraphs_demo' => [
$paragraph,
$paragraph2,
$paragraph3,
$paragraph5,
$from_library,
],
]);
$node->save();
// Set the node as the front page.
\Drupal::configFactory()->getEditable('system.site')->set('page.front', '/node/' . $node->id())->save();
if (\Drupal::getContainer()->has('search_api.post_request_indexing')) {
\Drupal::service('search_api.post_request_indexing')->destruct();
}
if ($workflow = Workflow::load('editorial')) {
$workflow->getTypePlugin()->addEntityTypeAndBundle('node', 'paragraphed_content_demo');
$workflow->save();
}
}
......@@ -7,6 +7,10 @@
use Drupal\Core\Url;
use Drupal\Core\Routing\RouteMatchInterface;
use Drupal\node\Entity\Node;
use Drupal\paragraphs\Entity\Paragraph;
use Drupal\paragraphs_library\Entity\LibraryItem;
use Drupal\workflows\Entity\Workflow;
/**
* Implements hook_help().
......@@ -40,3 +44,110 @@ function paragraphs_demo_preprocess_node(&$variables) {
$variables['#attached']['library'][] = 'paragraphs_demo/drupal.paragraphs_demo';
}
}
/**
* Implements hook_modules_installed().
*/
function paragraphs_demo_modules_installed($modules, $is_syncing) {
if (in_array('paragraphs_demo', $modules, TRUE)) {
// Create three paragraphs to structure the content.
$paragraph = Paragraph::create([
'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([
'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([
'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([
'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([
'type' => 'nested_paragraph',
'field_paragraphs_demo' => $paragraph4,
]);
$paragraph5->save();
// PARAGRAPH DEMO ITEM: library items.
$library_text_paragraph = Paragraph::create([
'type' => 'text',
'field_text_demo' => [
'value' => 'This is content from the library. We can reuse it multiple times without duplicating it.',
'format' => 'plain_text',
],
]);
$library_text_paragraph->save();
$library_item = LibraryItem::create([
'label' => 'Library item',
'paragraphs' => [
$library_text_paragraph,
],
]);
$library_item->save();
$from_library = Paragraph::create([
'type' => 'from_library',
'field_reusable_paragraph' => [
$library_item,
],
]);
$from_library->save();
// Add demo content with four paragraphs.
$node = Node::create([
'type' => 'paragraphed_content_demo',
'title' => 'Welcome to the Paragraphs Demo module!',
'langcode' => 'en',
'uid' => '0',
'status' => 1,
'field_paragraphs_demo' => [
$paragraph,
$paragraph2,
$paragraph3,
$paragraph5,
$from_library,
],
]);
$node->save();
// Set the node as the front page.
\Drupal::configFactory()->getEditable('system.site')->set('page.front', '/node/' . $node->id())->save();
if ($workflow = Workflow::load('editorial')) {
$workflow->getTypePlugin()->addEntityTypeAndBundle('node', 'paragraphed_content_demo');
$workflow->save();
}
if (\Drupal::getContainer()->has('search_api.post_request_indexing')) {
\Drupal::service('search_api.post_request_indexing')->destruct();
}
}
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment