You are here

protected function ToggleEditableFieldsUiTest::createBooleanField in Toggle Editable fields 8

Create a new boolean field configured to use our formatter.

Parameters

string $label: The label of the new field. Defaults to a random string.

string $name: The name of the new field (all lowercase), exclude the "field_" prefix.

string $type_name: The node type that this field will be added to.

string $widget_name: The name of the widget.

array $storage_settings: A list of field storage settings that will be added to the defaults.

array $field_settings: A list of instance settings that will be added to the instance defaults.

array $widget_settings: A list of widget settings that will be added to the widget defaults.

Throws

\Drupal\Component\Plugin\Exception\InvalidPluginDefinitionException

\Drupal\Core\Entity\EntityStorageException In case of failures an exception is thrown.

1 call to ToggleEditableFieldsUiTest::createBooleanField()
ToggleEditableFieldsUiTest::setUp in tests/src/Functional/ToggleEditableFieldsUiTest.php

File

tests/src/Functional/ToggleEditableFieldsUiTest.php, line 168

Class

ToggleEditableFieldsUiTest
Tests the Form mode manager user interfaces.

Namespace

Drupal\Tests\toggle_editable_fields\Functional

Code

protected function createBooleanField($label, $name, $type_name, $widget_name, array $storage_settings = [], array $field_settings = [], array $widget_settings = []) {
  $type_path = 'admin/structure/types/manage/' . $type_name;
  $this
    ->fieldUIAddNewField($type_path, $name, $label, 'boolean', $storage_settings, $field_settings);
  $this->field = [
    'name' => "field_" . $name,
    'label' => $label,
  ];
  $widget_settings += [
    'type' => $widget_name,
  ];

  /** @var \Drupal\Core\Entity\Display\EntityViewDisplayInterface $view_display */
  $view_display = \Drupal::entityTypeManager()
    ->getStorage('entity_view_display')
    ->load('node.' . $type_name . '.default');
  $view_display
    ->setComponent($this->field['name'], $widget_settings)
    ->save();
}