public function Drupal8::createDummyNode in Realistic Dummy Content 3.x
Same name and namespace in other branches
- 8.2 api/src/Framework/Drupal8.php \Drupal\realistic_dummy_content_api\Framework\Drupal8::createDummyNode()
- 7.2 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 - Create an entity.
- Drupal8::frameworkSpecificTests in api/
src/ Framework/ Drupal8.php - Perform framework-specific tests, if any.
File
- api/
src/ Framework/ Drupal8.php, line 103
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.
// @phpstan-ignore-next-line
$entity_def = \Drupal::entityTypeManager()
->getDefinition($entity_type);
// Load up an array for creation.
$new_node = [
// Set title.
'title' => 'test node',
$entity_def
->get('entity_keys')['bundle'] => $bundle,
];
// @phpstan-ignore-next-line
$new_post = \Drupal::entityTypeManager()
->getStorage($entity_type)
->create($new_node);
$new_post
->save();
return Node::load($this
->latestId());
}