function field_test_create_entity

Creates a basic test_entity entity.

32 calls to field_test_create_entity()
BulkDeleteTest::setUp in drupal/core/modules/field/lib/Drupal/field/Tests/BulkDeleteTest.php
Set the default field storage backend for fields created during tests.
CrudTest::testDeleteField in drupal/core/modules/field/lib/Drupal/field/Tests/CrudTest.php
Test the deletion of a field.
CrudTest::testUpdateField in drupal/core/modules/field/lib/Drupal/field/Tests/CrudTest.php
Test updating a field.
DisplayApiTest::setUp in drupal/core/modules/field/lib/Drupal/field/Tests/DisplayApiTest.php
Set the default field storage backend for fields created during tests.
FieldAttachOtherTest::testFieldAttachCache in drupal/core/modules/field/lib/Drupal/field/Tests/FieldAttachOtherTest.php
Test field cache.

... See full list

File

drupal/core/modules/field/tests/modules/field_test/field_test.entity.inc, line 149
Defines an entity type.

Code

function field_test_create_entity($id = 1, $vid = 1, $bundle = 'test_bundle', $label = '') {
  $entity = entity_create('test_entity', array(
    'fttype' => $bundle,
  ));

  // Only set id and vid properties if they don't come as NULL (creation form).
  if (isset($id)) {
    $entity->ftid = $id;
  }
  if (isset($vid)) {
    $entity->ftvid = $vid;

    // Flag to make sure that the provided vid is used for a new revision.
    $entity->use_provided_revision_id = $vid;
  }
  $label = !empty($label) ? $label : $bundle . ' label';
  $entity->ftlabel = $label;

  // Make sure the entity will saved even if a primary key is provided.
  $entity
    ->enforceIsNew();
  $entity
    ->setNewRevision();
  return $entity;
}