You are here

protected function LingotekNodeCohesionRepeaterTranslationTest::createCohesionField in Lingotek Translation 4.0.x

Same name and namespace in other branches
  1. 3.5.x tests/src/Functional/LingotekNodeCohesionRepeaterTranslationTest.php \Drupal\Tests\lingotek\Functional\LingotekNodeCohesionRepeaterTranslationTest::createCohesionField()
  2. 3.6.x tests/src/Functional/LingotekNodeCohesionRepeaterTranslationTest.php \Drupal\Tests\lingotek\Functional\LingotekNodeCohesionRepeaterTranslationTest::createCohesionField()
  3. 3.7.x tests/src/Functional/LingotekNodeCohesionRepeaterTranslationTest.php \Drupal\Tests\lingotek\Functional\LingotekNodeCohesionRepeaterTranslationTest::createCohesionField()
  4. 3.8.x tests/src/Functional/LingotekNodeCohesionRepeaterTranslationTest.php \Drupal\Tests\lingotek\Functional\LingotekNodeCohesionRepeaterTranslationTest::createCohesionField()
1 call to LingotekNodeCohesionRepeaterTranslationTest::createCohesionField()
LingotekNodeCohesionRepeaterTranslationTest::setUp in tests/src/Functional/LingotekNodeCohesionRepeaterTranslationTest.php

File

tests/src/Functional/LingotekNodeCohesionRepeaterTranslationTest.php, line 246

Class

LingotekNodeCohesionRepeaterTranslationTest
Tests translating a node with multiple locales including paragraphs.

Namespace

Drupal\Tests\lingotek\Functional

Code

protected function createCohesionField($entity_type_id, $bundle, $field_name = 'layout_canvas', $field_label = 'Layout canvas', $target_entity_type = 'cohesion_layout', $selection_handler = 'default', $selection_handler_settings = [], $cardinality = 1) {

  // Look for or add the specified field to the requested entity bundle.
  if (!FieldStorageConfig::loadByName($entity_type_id, $field_name)) {
    FieldStorageConfig::create([
      'field_name' => $field_name,
      'type' => 'cohesion_entity_reference_revisions',
      'entity_type' => $entity_type_id,
      'cardinality' => $cardinality,
      'settings' => [
        'target_type' => $target_entity_type,
      ],
    ])
      ->save();
  }
  if (!FieldConfig::loadByName($entity_type_id, $bundle, $field_name)) {
    FieldConfig::create([
      'field_name' => $field_name,
      'entity_type' => $entity_type_id,
      'bundle' => $bundle,
      'label' => $field_label,
      'settings' => [
        'handler' => $selection_handler,
        'handler_settings' => $selection_handler_settings,
      ],
    ])
      ->save();
  }
  EntityFormDisplay::load("{$entity_type_id}.{$bundle}.default")
    ->setComponent($field_name, [
    'type' => 'cohesion_layout_builder_widget',
    'weight' => 1,
  ])
    ->save();
  EntityViewDisplay::load("{$entity_type_id}.{$bundle}.default")
    ->setComponent($field_name, [
    'label' => 'hidden',
    'type' => 'entity_reference_revisions_entity_view',
  ])
    ->save();
}