protected function ParagraphsTestBaseTrait::addFieldtoParagraphType

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.

20 calls to ParagraphsTestBaseTrait::addFieldtoParagraphType()
ParagraphsBehaviorsTest::testBehaviorPluginsSettingsFiltering in paragraphs/tests/src/Functional/ParagraphsBehaviorsTest.php
Tests that behavior settings have empty leaves removed before being saved.
ParagraphsClientsideButtonsTest::testAddParagraphAboveButton in paragraphs/tests/src/FunctionalJavascript/ParagraphsClientsideButtonsTest.php
Tests the "Add above" button.
ParagraphsCollectionStyleTest::testStylePlugin in paragraphs_collection/tests/src/Functional/ParagraphsCollectionStyleTest.php
Test paragraphs style behavior plugin.
ParagraphsCollectionStyleTest::testStylePluginSummary in paragraphs_collection/tests/src/Functional/ParagraphsCollectionStyleTest.php
Test paragraphs style behavior plugin summary.
ParagraphsContentModerationTest::setUp in paragraphs/modules/paragraphs_library/tests/src/FunctionalJavascript/ParagraphsContentModerationTest.php

... See full list

File

paragraphs/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();
}