You are here

public function Drupal7::createEntity in Realistic Dummy Content 7.2

Same name and namespace in other branches
  1. 8.2 api/src/Framework/Drupal7.php \Drupal\realistic_dummy_content_api\Framework\Drupal7::createEntity()
2 calls to Drupal7::createEntity()
Drupal7::testHookUserInsert in api/src/Framework/Drupal7.php
Tests $this->hookUserInsert().
Drupal7::testHookUserPresave in api/src/Framework/Drupal7.php
Tests $this->hookUserPresave().

File

api/src/Framework/Drupal7.php, line 315

Class

Drupal7
Drupal 7-specific code.

Namespace

Drupal\realistic_dummy_content_api\Framework

Code

public function createEntity($info = array()) {
  if (isset($info['entity_type'])) {
    $entity_type = $info['entity_type'];
  }
  else {
    $entity_type = 'node';
  }
  $entity = new \stdClass();
  switch ($entity_type) {
    case 'node':
      $entity->title = rand(100000, 999999);
      $entity->type = $this
        ->getDefaultNodeType();
      node_save($entity);
      break;
    case 'user':
      $options = array(
        'name' => rand(1000000, 9999999),
      );
      if (isset($info['dummy']) && $info['dummy']) {
        $options['mail'] = $options['name'] . '@example.invalid';
      }
      $entity = user_save(drupal_anonymous_user(), $options);
      break;
    default:
      throw new \Exception('Unknown entity type ' . $entity_type);
  }
  return $entity;
}