You are here

protected function ParagraphsTestBaseTrait::addFieldtoParagraphType in Paragraphs 8

Adds a field to a given paragraph type.

Parameters

string $paragraph_type_id: Paragraph type ID to be used.

string $field_name: Field name to be used.

string $field_type: Type of the field.

array $storage_settings: Settings for the field storage.

18 calls to ParagraphsTestBaseTrait::addFieldtoParagraphType()
ParagraphsBehaviorsTest::testBehaviorPluginsSettingsFiltering in tests/src/Functional/ParagraphsBehaviorsTest.php
Tests that behavior settings have empty leaves removed before being saved.
ParagraphsClientsideButtonsTest::testAddParagraphAboveButton in tests/src/FunctionalJavascript/ParagraphsClientsideButtonsTest.php
Tests the "Add above" button.
ParagraphsContentModerationTest::setUp in modules/paragraphs_library/tests/src/FunctionalJavascript/ParagraphsContentModerationTest.php
ParagraphsContentModerationTest::testModeratedContentNestedParagraphs in modules/paragraphs_library/tests/src/FunctionalJavascript/ParagraphsContentModerationTest.php
Tests the moderated content that includes nested paragraphs.
ParagraphsDragAndDropModeTest::setUp in tests/src/Functional/WidgetStable/ParagraphsDragAndDropModeTest.php

... See full list

File

tests/src/FunctionalJavascript/ParagraphsTestBaseTrait.php, line 159

Class

ParagraphsTestBaseTrait
Test trait for Paragraphs JS tests.

Namespace

Drupal\Tests\paragraphs\FunctionalJavascript

Code

protected function addFieldtoParagraphType($paragraph_type_id, $field_name, $field_type, array $storage_settings = []) {

  // Add a paragraphs field.
  $field_storage = FieldStorageConfig::create([
    'field_name' => $field_name,
    'entity_type' => 'paragraph',
    'type' => $field_type,
    'cardinality' => 1,
    'settings' => $storage_settings,
  ]);
  $field_storage
    ->save();
  $field = FieldConfig::create([
    'field_storage' => $field_storage,
    'bundle' => $paragraph_type_id,
    'settings' => [],
  ]);
  $field
    ->save();
  $field_type_definition = \Drupal::service('plugin.manager.field.field_type')
    ->getDefinition($field_type);
  $form_display = \Drupal::service('entity_display.repository')
    ->getFormDisplay('paragraph', $paragraph_type_id);
  $form_display
    ->setComponent($field_name, [
    'type' => $field_type_definition['default_widget'],
  ])
    ->save();
  $view_display = \Drupal::service('entity_display.repository')
    ->getViewDisplay('paragraph', $paragraph_type_id);
  $view_display
    ->setComponent($field_name, [
    'type' => $field_type_definition['default_formatter'],
  ]);
  $view_display
    ->save();
}