You are here

protected function WorkbenchAccessTestTrait::setUpTaxonomyFieldForEntityType in Workbench Access 8

Sets up a taxonomy field on a given entity type and bundle.

Parameters

string $entity_type_id: Entity type ID.

string $bundle: Bundle ID.

string $vocabulary_id: Vocabulary ID.

string $field_name: Field machine name.

string $title: Field display title.

int $cardinality: Indicates the number of values to save. -1 is unlimited.

$field_type: The type of field widget to enable: options_select|options_buttons

Return value

field The created field entity.

14 calls to WorkbenchAccessTestTrait::setUpTaxonomyFieldForEntityType()
AccessByRoleFormTest::testAccessByRoleForm in tests/src/Functional/AccessByRoleFormTest.php
Tests that the correct roles are displayed on the access by role form.
AccessByUserFormTest::testAccessByUserForm in tests/src/Functional/AccessByUserFormTest.php
Tests that the correct users are displayed on the access by user form.
AccessCacheTest::testNodeEdit in tests/src/Functional/AccessCacheTest.php
Tests that the user can edit the node when allowed.
AssignUserFormTest::testAssignUserForm in tests/src/Functional/AssignUserFormTest.php
Tests that the AssignUserForm works correctly.
ConfigDependenciesTest::setUp in tests/src/Kernel/ConfigDependenciesTest.php

... See full list

File

tests/src/Traits/WorkbenchAccessTestTrait.php, line 66

Class

WorkbenchAccessTestTrait
Contains helper classes for tests to set up various configuration.

Namespace

Drupal\Tests\workbench_access\Traits

Code

protected function setUpTaxonomyFieldForEntityType($entity_type_id, $bundle, $vocabulary_id, $field_name = WorkbenchAccessManagerInterface::FIELD_NAME, $title = 'Section', $cardinality = 1, $field_type = 'options_select') {

  // Create an instance of the access field on the bundle.
  $handler_id = 'workbench_access:taxonomy_term:editorial_section';
  if (!AccessScheme::load('editorial_section')) {

    // The scheme doesn't exist yet so there is no plugin yet.
    $handler_id = 'default:taxonomy_term';
  }
  $field = $this
    ->createEntityReferenceField($entity_type_id, $bundle, $field_name, $title, 'taxonomy_term', $handler_id, [
    'target_bundles' => [
      $vocabulary_id => $vocabulary_id,
    ],
  ], $cardinality);

  // Set the field to display as a dropdown on the form.
  if (!($form_display = EntityFormDisplay::load("{$entity_type_id}.{$bundle}.default"))) {
    $form_display = EntityFormDisplay::create([
      'targetEntityType' => $entity_type_id,
      'bundle' => $bundle,
      'mode' => 'default',
      'status' => TRUE,
    ]);
  }
  $form_display
    ->setComponent($field_name, [
    'type' => $field_type,
  ]);
  $form_display
    ->save();
  return FieldConfig::loadByName($entity_type_id, $bundle, $field_name);
}