public function DemoEntity::createContent in Open Social 8.9
Same name and namespace in other branches
- 8 modules/custom/social_demo/src/DemoEntity.php \Drupal\social_demo\DemoEntity::createContent()
- 8.2 modules/custom/social_demo/src/DemoEntity.php \Drupal\social_demo\DemoEntity::createContent()
- 8.3 modules/custom/social_demo/src/DemoEntity.php \Drupal\social_demo\DemoEntity::createContent()
- 8.4 modules/custom/social_demo/src/DemoEntity.php \Drupal\social_demo\DemoEntity::createContent()
- 8.5 modules/custom/social_demo/src/DemoEntity.php \Drupal\social_demo\DemoEntity::createContent()
- 8.6 modules/custom/social_demo/src/DemoEntity.php \Drupal\social_demo\DemoEntity::createContent()
- 8.7 modules/custom/social_demo/src/DemoEntity.php \Drupal\social_demo\DemoEntity::createContent()
- 8.8 modules/custom/social_demo/src/DemoEntity.php \Drupal\social_demo\DemoEntity::createContent()
- 10.3.x modules/custom/social_demo/src/DemoEntity.php \Drupal\social_demo\DemoEntity::createContent()
- 10.0.x modules/custom/social_demo/src/DemoEntity.php \Drupal\social_demo\DemoEntity::createContent()
- 10.1.x modules/custom/social_demo/src/DemoEntity.php \Drupal\social_demo\DemoEntity::createContent()
- 10.2.x modules/custom/social_demo/src/DemoEntity.php \Drupal\social_demo\DemoEntity::createContent()
Creates content.
Return value
array An array with list of created entities.
Overrides DemoContentInterface::createContent
File
- modules/
custom/ social_demo/ src/ DemoEntity.php, line 39
Class
- DemoEntity
- Class DemoEntity.
Namespace
Drupal\social_demoCode
public function createContent($generate = FALSE, $max = NULL) {
$data = $this
->fetchData();
if ($generate === TRUE) {
$data = $this
->scrambleData($data, $max);
}
$entity_type_id = $this->entityStorage
->getEntityTypeId();
foreach ($data as $uuid => $item) {
// Must have uuid and same key value.
if ($uuid !== $item['uuid']) {
drush_log(dt("{$entity_type_id} with uuid: {$uuid} has a different uuid in content."), LogLevel::ERROR);
continue;
}
// Check whether comment with same uuid already exists.
$entities = $this->entityStorage
->loadByProperties([
'uuid' => $uuid,
]);
if ($entities) {
drush_log(dt("{$entity_type_id} with uuid: {$uuid} already exists."), LogLevel::WARNING);
continue;
}
$entry = $this
->getEntry($item);
$entity = $this->entityStorage
->create($entry);
$entity
->save();
if ($entity
->id()) {
$this->content[$entity
->id()] = $entity;
}
}
}