diff --git a/tests/src/FunctionalJavascript/ParagraphsTestBaseTrait.php b/tests/src/FunctionalJavascript/ParagraphsTestBaseTrait.php new file mode 100644 index 0000000..7dcddfd --- /dev/null +++ b/tests/src/FunctionalJavascript/ParagraphsTestBaseTrait.php @@ -0,0 +1,104 @@ + $content_type_name, + 'name' => $content_type_name, + ]); + $node_type->save(); + + $this->addParagraphsField($content_type_name, $paragraphs_field_name, 'node', $paragraphs_type); + } + + /** + * Adds a Paragraphs field to a given entity type. + * + * @param string $entity_type_name + * Entity type name to be used. + * @param string $paragraphs_field_name + * Paragraphs field name to be used. + * @param string $entity_type + * Entity type where to add the field. + * @param string $paragraphs_type + * Declares if we use experimental or classic widget. + */ + protected function addParagraphsField($entity_type_name, $paragraphs_field_name, $entity_type, $paragraphs_type) { + // Add a paragraphs field. + $field_storage = FieldStorageConfig::create([ + 'field_name' => $paragraphs_field_name, + 'entity_type' => $entity_type, + 'type' => 'entity_reference_revisions', + 'cardinality' => '-1', + 'settings' => [ + 'target_type' => 'paragraph', + ], + ]); + $field_storage->save(); + $field = FieldConfig::create([ + 'field_storage' => $field_storage, + 'bundle' => $entity_type_name, + 'settings' => [ + 'handler' => 'default:paragraph', + 'handler_settings' => ['target_bundles' => NULL], + ], + ]); + $field->save(); + + $form_display = EntityFormDisplay::create([ + 'targetEntityType' => $entity_type, + 'bundle' => $entity_type_name, + 'mode' => 'default', + 'status' => TRUE, + ]) + ->setComponent($paragraphs_field_name, ['type' => $paragraphs_type]); + $form_display->save(); + + $view_display = EntityViewDisplay::create([ + 'targetEntityType' => $entity_type, + 'bundle' => $entity_type_name, + 'mode' => 'default', + 'status' => TRUE, + ])->setComponent($paragraphs_field_name, ['type' => 'entity_reference_revisions_entity_view']); + $view_display->save(); + } + + /** + * Adds a Paragraphs type. + * + * @param string $paragraphs_type_name + * Paragraph type name used to create. + */ + protected function addParagraphsType($paragraphs_type_name) { + $paragraphs_type = ParagraphsType::create([ + 'id' => $paragraphs_type_name, + 'label' => $paragraphs_type_name, + ]); + $paragraphs_type->save(); + } + +}