-
-
Save alexpott/874a0480b7097d7d97322c053dec6634 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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