1 field.test FieldBulkDeleteTestCase::_generateStubEntities($entity_type, $entities, $field_name = NULL)

Convenience function for Field API tests.

Given an array of potentially fully-populated entities and an optional field name, generate an array of stub entities of the same fieldable type which contains the data for the field name (if given).


$entity_type: The entity type of $entities.

$entities: An array of entities of type $entity_type.

$field_name: Optional; a field name whose data should be copied from $entities into the returned stub entities.

Return value

array An array of stub entities corresponding to $entities.


core/modules/field/tests/field.test, line 3175
Tests for field.module.


Unit test class for field bulk delete and batch purge functionality.


function _generateStubEntities($entity_type, $entities, $field_name = NULL) {
  $stubs = array();
  foreach ($entities as $id => $entity) {
    $stub = entity_create_stub_entity($entity_type, entity_extract_ids($entity_type, $entity));
    if (isset($field_name)) {
      $stub->{$field_name} = $entity->{$field_name};
    $stubs[$id] = $stub;
  return $stubs;