Skip to content

Instantly share code, notes, and snippets.

@alexpott
Last active March 8, 2021 16:12
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save alexpott/874a0480b7097d7d97322c053dec6634 to your computer and use it in GitHub Desktop.
Save alexpott/874a0480b7097d7d97322c053dec6634 to your computer and use it in GitHub Desktop.
<?php
use Drupal\node\Entity\Node;
use \Drupal\node\Entity\NodeType;
use Drupal\paragraphs\Entity\Paragraph;
include_once 'core/tests/Drupal/Tests/TestFileCreationTrait.php';
include_once 'core/tests/Drupal/Tests/RandomGeneratorTrait.php';
include_once 'modules/paragraphs/tests/src/FunctionalJavascript/ParagraphsTestBaseTrait.php';
/*
d8reset;
vendor/bin/drush si -y -vd standard --account-mail=alex@vit-al.com --account-name=admin --account-pass=admin --db-url=mysql://dev:dev@localhost/drupal8alt;sudo chmod -R 777 ./sites/default/files; sudo chmod 644 ./sites/default/settings.php
vendor/bin/drush en paragraphs simple_sitemap -y;
vendor/bin/drush scr paragraphs.php;
*/
class ParaBuild {
use \Drupal\Tests\paragraphs\FunctionalJavascript\ParagraphsTestBaseTrait;
use \Drupal\Tests\RandomGeneratorTrait;
public function doIt() {
if (NodeType::load('paragraphed_test')) {
return;
}
$this->addParagraphedContentType('paragraphed_test', 'field_paragraphs');
$this->addParagraphsType('paragraphs_container');
$this->addParagraphsType('text');
$this->addFieldtoParagraphType('text', 'field_text', 'text');
$this->addParagraphsField('paragraphs_container', 'paragraphs_container_paragraphs', 'paragraph');
\Drupal::service('simple_sitemap.generator')->setBundleSettings('node', 'paragraphed_test', [
'index' => TRUE,
'priority' => 0.5,
'changefreq' => 'hourly',
]);
}
public function createNode() {
// Create text paragraph.
$text_paragraph_1 = Paragraph::create([
'type' => 'text',
'field_text' => [
'value' => $this->getRandomGenerator()->sentences(20),
'format' => 'plain_text',
],
]);
$text_paragraph_1->save();
// Create a second text paragraph.
$text_paragraph_2 = Paragraph::create([
'type' => 'text',
'field_text' => [
'value' => $this->getRandomGenerator()->sentences(20),
'format' => 'plain_text',
],
]);
$text_paragraph_2->save();
// Create container that contains the first two text paragraphs.
$paragraph = Paragraph::create([
'type' => 'paragraphs_container',
'paragraphs_container_paragraphs' => [$text_paragraph_1, $text_paragraph_2],
]);
$paragraph->save();
// Add test content with paragraph container.
$node = Node::create([
'type' => 'paragraphed_test',
'title' => $this->getRandomGenerator()->sentences(5),
'field_paragraphs' => [$paragraph],
]);
$node->save();
}
}
$builder = new ParaBuild();
$builder->doIt();
for ($i =0; $i < 5000; $i++) {
$builder->createNode();
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment