public function Drupal8::createDummyNode in Realistic Dummy Content 8.2
Same name and namespace in other branches
- 7.2 api/src/Framework/Drupal8.php \Drupal\realistic_dummy_content_api\Framework\Drupal8::createDummyNode()
- 3.x api/src/Framework/Drupal8.php \Drupal\realistic_dummy_content_api\Framework\Drupal8::createDummyNode()
Create a dummy node.
Return value
object A Drupal node object.
Throws
Exception
2 calls to Drupal8::createDummyNode()
- Drupal8::createEntity in api/
src/ Framework/ Drupal8.php - Drupal8::frameworkSpecificTests in api/
src/ Framework/ Drupal8.php - Perform framework-specific tests, if any.
File
- api/
src/ Framework/ Drupal8.php, line 111
Class
- Drupal8
- Drupal 8-specific code.
Namespace
Drupal\realistic_dummy_content_api\FrameworkCode
public function createDummyNode() {
$entity_type = 'node';
$bundle = 'article';
// Get definition of target entity type.
$entity_def = \Drupal::entityManager()
->getDefinition($entity_type);
// Load up an array for creation.
$new_node = array(
// Set title.
'title' => 'test node',
$entity_def
->get('entity_keys')['bundle'] => $bundle,
);
$new_post = \Drupal::entityManager()
->getStorage($entity_type)
->create($new_node);
$new_post
->save();
return node_load($this
->latestId());
}