You are here

protected function FieldCollectionTestTrait::addFieldCollectionFieldToContentType in Field collection 8

Same name and namespace in other branches
  1. 8.3 tests/src/Functional/FieldCollectionTestTrait.php \Drupal\Tests\field_collection\Functional\FieldCollectionTestTrait::addFieldCollectionFieldToContentType()

Helper function for adding the field collection field to a content type.

2 calls to FieldCollectionTestTrait::addFieldCollectionFieldToContentType()
FieldCollectionBasicTestCase::testFieldDeletion in tests/src/Functional/FieldCollectionBasicTestCase.php
Test deleting the field corresponding to a field collection.
FieldCollectionTestTrait::setUpFieldCollectionTest in tests/src/Functional/FieldCollectionTestTrait.php
Sets up the data structures for the tests.

File

tests/src/Functional/FieldCollectionTestTrait.php, line 118

Class

FieldCollectionTestTrait
Provides helper properties and functions for field collection tests.

Namespace

Drupal\Tests\field_collection\Functional

Code

protected function addFieldCollectionFieldToContentType($content_type) {
  $field_collection_definition = [
    'field_name' => $this->field_collection_name,
    'entity_type' => 'node',
    'bundle' => $content_type,
    'field_storage' => $this->field_collection_field_storage,
    'label' => $this
      ->randomMachineName() . '_label',
    'description' => $this
      ->randomMachineName() . '_description',
    'settings' => [],
  ];
  $field_config = FieldConfig::create($field_collection_definition);
  $field_config
    ->save();
  \Drupal::entityTypeManager()
    ->getStorage('entity_view_display')
    ->load("node.{$content_type}.default")
    ->setComponent($this->field_collection_name, [
    'type' => 'field_collection_editable',
  ])
    ->save();
  \Drupal::entityTypeManager()
    ->getStorage('entity_form_display')
    ->load("node.{$content_type}.default")
    ->setComponent($this->field_collection_name, [
    'type' => 'field_collection_embed',
  ])
    ->save();
  return $field_config;
}