function _monitoring_setup_create_node in Monitoring 8
Same name and namespace in other branches
- 7 monitoring.setup.inc \_monitoring_setup_create_node()
Creates nodes for testing purposes.
Parameters
array $settings: Node data.
Return value
\Drupal\node\Entity\Node Created node.
1 call to _monitoring_setup_create_node()
- monitoring_demo_install in modules/
demo/ monitoring_demo.install - Implements hook_install().
File
- modules/
demo/ monitoring_demo.install, line 173 - Install file of the monitoring_demo module.
Code
function _monitoring_setup_create_node($settings = array()) {
$random = new Random();
// Populate defaults array.
$settings += array(
'body' => array(
array(),
),
'title' => $random
->name(8),
'revision' => 1,
'log' => '',
'status' => NodeInterface::PUBLISHED,
'type' => 'page',
'langcode' => LanguageInterface::LANGCODE_NOT_SPECIFIED,
);
// If the node's user uid is not specified manually, use the currently
// logged in user if available, or else the user running the test.
if (!isset($settings['uid'])) {
$user = \Drupal::currentUser();
$settings['uid'] = $user
->id();
}
// Merge body field value and format separately.
$settings['body'][0] += array(
'value' => $random
->name(32),
'format' => filter_default_format(),
);
$node = Node::create($settings);
if (!empty($settings['revision'])) {
$node
->setNewRevision();
}
$node
->save();
return $node;
}