ParagraphsSetsFunctionalTestTrait.php in Paragraphs Sets 8.2
File
tests/src/Traits/ParagraphsSetsFunctionalTestTrait.php
View source
<?php
namespace Drupal\Tests\paragraphs_sets\Traits;
use Drupal\Core\Serialization\Yaml;
use Drupal\paragraphs_sets\Entity\ParagraphsSet;
use Drupal\Tests\paragraphs\FunctionalJavascript\ParagraphsTestBaseTrait;
trait ParagraphsSetsFunctionalTestTrait {
use ParagraphsTestBaseTrait;
public function addNodeType(string $nodeType) {
$this
->drupalCreateContentType([
'type' => $nodeType,
'name' => $nodeType,
]);
}
public function addParagraphRefFieldInNodeType(string $paragraphRefFieldName, string $nodeType) {
$this
->addParagraphsField($nodeType, $paragraphRefFieldName, 'node', 'paragraphs');
$formDisplay = \Drupal::service('entity_display.repository')
->getFormDisplay('node', $nodeType);
$displaySettings = $formDisplay
->getComponent($paragraphRefFieldName);
$displaySettings['third_party_settings']['paragraphs_sets']['paragraphs_sets']['use_paragraphs_sets'] = 1;
$formDisplay
->setComponent($paragraphRefFieldName, $displaySettings);
$formDisplay
->save();
}
public function addTextFieldInParagraphType(string $textFieldName, string $paragraphType) {
$this
->addFieldtoParagraphType($paragraphType, $textFieldName, 'string', []);
}
public function addParagraphSet(string $paragraphSet, string $config = 'paragraphs: []') {
$decodedConfig = Yaml::decode($config);
$paragraphsSet = ParagraphsSet::create([
'id' => $paragraphSet,
'label' => $paragraphSet,
'description' => $paragraphSet,
'paragraphs' => $decodedConfig['paragraphs'],
]);
$paragraphsSet
->save();
}
}