You are here

public function DomainEntityMapper::createFieldStorage in Domain Access Entity 8

Creates field storage.

Parameters

string $entity_type_id: The entity type ID.

Return value

\Drupal\field\Entity\FieldStorageConfig The field storage.

1 call to DomainEntityMapper::createFieldStorage()
DomainEntityMapper::addDomainField in src/DomainEntityMapper.php
Creates domain fields.

File

src/DomainEntityMapper.php, line 181

Class

DomainEntityMapper
Provides fields operations for domain entity module fields.

Namespace

Drupal\domain_entity

Code

public function createFieldStorage($entity_type_id) {
  if ($field_storage = $this
    ->loadFieldStorage($entity_type_id)) {

    // Prevent creation of existing field storage.
    return $field_storage;
  }
  $storage = $this->entityTypeManager
    ->getStorage('field_storage_config');
  $field_storage = $storage
    ->create([
    'entity_type' => $entity_type_id,
    'field_name' => self::FIELD_NAME,
    'type' => 'entity_reference',
    // @todo Polish to enable UI and optimize storage.
    'persist_with_no_fields' => TRUE,
    'locked' => FALSE,
  ]);
  $field_storage
    ->setCardinality(FieldStorageDefinitionInterface::CARDINALITY_UNLIMITED)
    ->setSetting('target_type', 'domain')
    ->save();
  return $field_storage;
}