You are here

protected function EntityHierarchyWorkbenchAccessTest::setupBooleanEditorialField in Entity Reference Hierarchy 3.x

Same name and namespace in other branches
  1. 8.2 modules/entity_hierarchy_workbench_access/tests/src/Kernel/EntityHierarchyWorkbenchAccessTest.php \Drupal\Tests\entity_hierarchy_workbench_access\Kernel\EntityHierarchyWorkbenchAccessTest::setupBooleanEditorialField()

Creates a new boolean field for flagging entity as section.

Parameters

string $entity_type_id: Entity type to add the field to.

string $bundle: Bundle of field.

string $field_name: Field name.

bool $create_field_first: TRUE to create the field storage config too.

1 call to EntityHierarchyWorkbenchAccessTest::setupBooleanEditorialField()
EntityHierarchyWorkbenchAccessTest::setUp in modules/entity_hierarchy_workbench_access/tests/src/Kernel/EntityHierarchyWorkbenchAccessTest.php

File

modules/entity_hierarchy_workbench_access/tests/src/Kernel/EntityHierarchyWorkbenchAccessTest.php, line 114

Class

EntityHierarchyWorkbenchAccessTest
Tests interaction between entity_hierarchy and workbench_access.

Namespace

Drupal\Tests\entity_hierarchy_workbench_access\Kernel

Code

protected function setupBooleanEditorialField($entity_type_id, $bundle, $field_name, $create_field_first = TRUE) {
  if ($create_field_first) {
    $storage = FieldStorageConfig::create([
      'entity_type' => $entity_type_id,
      'field_name' => $field_name,
      'id' => "{$entity_type_id}.{$field_name}",
      'type' => 'boolean',
    ]);
    $storage
      ->save();
  }
  $config = FieldConfig::create([
    'field_name' => $field_name,
    'entity_type' => $entity_type_id,
    'bundle' => $bundle,
    'id' => "{$entity_type_id}.{$bundle}.{$field_name}",
    'label' => Unicode::ucfirst($field_name),
  ]);
  $config
    ->save();
}