3 namespace Drupal\paragraphs\Tests\Experimental;
5 use Drupal\Core\Entity\Entity\EntityFormDisplay;
6 use Drupal\Core\Entity\Entity\EntityViewDisplay;
7 use Drupal\field\Entity\FieldConfig;
8 use Drupal\field\Entity\FieldStorageConfig;
9 use Drupal\field_ui\Tests\FieldUiTestTrait;
10 use Drupal\paragraphs\Tests\Classic\ParagraphsTestBase;
13 * Base class for tests.
15 abstract class ParagraphsExperimentalTestBase extends ParagraphsTestBase {
20 * Adds a Paragraphs field to a given $entity_type.
22 * @param string $entity_type_name
23 * Entity type name to be used.
24 * @param string $paragraphs_field_name
25 * Paragraphs field name to be used.
26 * @param string $entity_type
27 * Entity type where to add the field.
29 protected function addParagraphsField($entity_type_name, $paragraphs_field_name, $entity_type) {
30 // Add a paragraphs field.
31 $field_storage = FieldStorageConfig::create([
32 'field_name' => $paragraphs_field_name,
33 'entity_type' => $entity_type,
34 'type' => 'entity_reference_revisions',
35 'cardinality' => '-1',
37 'target_type' => 'paragraph',
40 $field_storage->save();
41 $field = FieldConfig::create([
42 'field_storage' => $field_storage,
43 'bundle' => $entity_type_name,
45 'handler' => 'default:paragraph',
46 'handler_settings' => ['target_bundles' => NULL],
51 $form_display = EntityFormDisplay::create([
52 'targetEntityType' => $entity_type,
53 'bundle' => $entity_type_name,
57 ->setComponent($paragraphs_field_name, ['type' => 'paragraphs']);
58 $form_display->save();
60 $view_display = EntityViewDisplay::create([
61 'targetEntityType' => $entity_type,
62 'bundle' => $entity_type_name,
65 ])->setComponent($paragraphs_field_name, ['type' => 'entity_reference_revisions_entity_view']);
66 $view_display->save();
70 * Sets the Paragraphs widget add mode.
72 * @param string $content_type
73 * Content type name where to set the widget mode.
74 * @param string $paragraphs_field
75 * Paragraphs field to change the mode.
77 * Mode to be set. ('dropdown', 'select' or 'button').
79 protected function setAddMode($content_type, $paragraphs_field, $mode) {
80 $form_display = EntityFormDisplay::load('node.' . $content_type . '.default')
81 ->setComponent($paragraphs_field, [
82 'type' => 'paragraphs',
83 'settings' => ['add_mode' => $mode]
85 $form_display->save();
89 * Removes the default paragraph type.
91 * @param $content_type
92 * Content type name that contains the paragraphs field.
94 protected function removeDefaultParagraphType($content_type) {
95 $this->drupalGet('node/add/' . $content_type);
96 $this->drupalPostForm(NULL, [], 'Remove');
97 $this->assertNoText('No paragraphs added yet.');