protected function EntityTranslationTestBase::createEntity

Creates the entity to be translated.

Parameters

array $values: An array of initial values for the entity.

string $langcode: The initial language code of the entity.

string $bundle_name: (optional) The entity bundle, if the entity uses bundles. Defaults to NULL. If left NULL, $this->bundle will be used.

Return value

The entity id.

6 calls to EntityTranslationTestBase::createEntity()
1 method overrides EntityTranslationTestBase::createEntity()

File

drupal/core/modules/translation_entity/lib/Drupal/translation_entity/Tests/EntityTranslationTestBase.php, line 201
Contains \Drupal\entity\Tests\EntityTranslationTestBase.

Class

EntityTranslationTestBase
Tests entity translation workflows.

Namespace

Drupal\translation_entity\Tests

Code

protected function createEntity($values, $langcode, $bundle_name = NULL) {
  $entity_values = $values;
  $entity_values['langcode'] = $langcode;
  $info = entity_get_info($this->entityType);
  if (!empty($info['entity_keys']['bundle'])) {
    $entity_values[$info['entity_keys']['bundle']] = $bundle_name ?: $this->bundle;
  }
  $controller = $this->container
    ->get('plugin.manager.entity')
    ->getStorageController($this->entityType);
  if (!$controller instanceof DatabaseStorageControllerNG) {
    foreach ($values as $property => $value) {
      if (is_array($value)) {
        $entity_values[$property] = array(
          $langcode => $value,
        );
      }
    }
  }
  $entity = entity_create($this->entityType, $entity_values);
  $entity
    ->save();
  return $entity
    ->id();
}