protected function ParagraphsTestBaseTrait::setParagraphsWidgetSettings

Sets some of the settings of a paragraphs field widget.

Parameters

string $bundle: Machine name of the bundle (e.g., a content type for nodes, a paragraphs type for paragraphs, etc.) with a paragraphs field.

string $paragraphs_field: Machine name of the paragraphs field whose widget (settings) to change.

array $settings: New setting values keyed by names of settings that are to be set.

string|null $field_widget: (optional) Machine name of the paragraphs field widget to use. NULL to keep the current widget.

string $entity_type: (optional) Machine name of the content entity type that the bundle belongs to. Defaults to "node".

15 calls to ParagraphsTestBaseTrait::setParagraphsWidgetSettings()
ParagraphsAddWidgetTest::testAddWidgetButton in paragraphs/tests/src/FunctionalJavascript/ParagraphsAddWidgetTest.php
Tests the add widget button with modal form.
ParagraphsAdministrationTest::testParagraphsCreation in paragraphs/tests/src/Functional/WidgetStable/ParagraphsAdministrationTest.php
Tests the paragraph creation.
ParagraphsCollectionStyleTest::testStylePluginSummary in paragraphs_collection/tests/src/Functional/ParagraphsCollectionStyleTest.php
Test paragraphs style behavior plugin summary.
ParagraphsHeaderActionsTest::testHeaderActionsWithNesting in paragraphs/tests/src/Functional/WidgetStable/ParagraphsHeaderActionsTest.php
Tests that header actions works fine with nesting.
ParagraphsInlineEntityFormTest::testParagraphsIEFChangeOrder in paragraphs/tests/src/Functional/WidgetStable/ParagraphsInlineEntityFormTest.php
Tests the reordering of previewed paragraphs.

... See full list

File

paragraphs/tests/src/FunctionalJavascript/ParagraphsTestBaseTrait.php, line 204

Class

ParagraphsTestBaseTrait
Test trait for Paragraphs JS tests.

Namespace

Drupal\Tests\paragraphs\FunctionalJavascript

Code

protected function setParagraphsWidgetSettings($bundle, $paragraphs_field, array $settings, $field_widget = NULL, $entity_type = 'node') {

  /** @var \Drupal\Core\Entity\Display\EntityFormDisplayInterface $default_form_display */
  $default_form_display = \Drupal::entityTypeManager()
    ->getStorage('entity_form_display')
    ->load($entity_type . '.' . $bundle . '.default');
  $component = $default_form_display
    ->getComponent($paragraphs_field);
  $updated_component = $component;
  if ($field_widget === NULL || isset($component['type']) && $field_widget === $component['type']) {

    // The widget stays the same.
    $updated_component['settings'] = $settings + $component['settings'];
  }
  else {

    // Change the widget.
    $updated_component['type'] = $field_widget;
    $widget_definition = \Drupal::service('plugin.manager.field.widget')
      ->getDefinition($field_widget);

    /** @var \Drupal\Core\Field\WidgetInterface $class */
    $class = $widget_definition['class'];
    $default_settings = $class::defaultSettings();
    $updated_component['settings'] = $settings + $default_settings;
  }
  $default_form_display
    ->setComponent($paragraphs_field, $updated_component)
    ->save();
}