You are here

protected function TaxonomyPermissionsTestBase::setFormDisplay in Taxonomy Permissions 8

Set the widget for a component in a form display.

Parameters

string $form_display_id: The form display id.

string $entity_type: The entity type name.

string $bundle: The bundle name.

string $field_name: The field name to set.

string $widget_id: The widget id to set.

array $settings: The settings of widget.

string $mode: The mode name.

1 call to TaxonomyPermissionsTestBase::setFormDisplay()
TaxonomyPermissionsTestBase::attachFields in src/Tests/TaxonomyPermissionsTestBase.php
Helper function to create and attach a field to a node.

File

src/Tests/TaxonomyPermissionsTestBase.php, line 261

Class

TaxonomyPermissionsTestBase
General setup and helper function for testing taxonomy permissions module.

Namespace

Drupal\taxonomy_permissions\Tests

Code

protected function setFormDisplay($form_display_id, $entity_type, $bundle, $field_name, $widget_id, array $settings, $mode = 'default') {

  // Set article's form display.
  $this->formDisplay = EntityFormDisplay::load($form_display_id);
  if (!$this->formDisplay) {
    EntityFormDisplay::create([
      'targetEntityType' => $entity_type,
      'bundle' => $bundle,
      'mode' => $mode,
      'status' => TRUE,
    ])
      ->save();
    $this->formDisplay = EntityFormDisplay::load($form_display_id);
  }
  if ($this->formDisplay instanceof EntityFormDisplayInterface) {
    $this->formDisplay
      ->setComponent($field_name, [
      'type' => $widget_id,
      'settings' => $settings,
    ])
      ->save();
  }
}