Creates a node of a given bundle.
It uses $this->field_names to populate content of attached fields.
string $bundle: Node type name.
string $sourcelang: Source lang of the node to be created.
\Drupal\node\NodeInterface Newly created node object.
protected function createTranslatableNode($bundle, $sourcelang = 'en') {
$node = array(
'type' => $bundle,
'langcode' => $sourcelang,
);
foreach ($this->field_names['node'][$bundle] as $field_name) {
// @todo: Why are some missing?
if ($field_storage_config = FieldStorageConfig::loadByName('node', $field_name)) {
$cardinality = $field_storage_config
->getCardinality() == FieldStorageDefinitionInterface::CARDINALITY_UNLIMITED ? 1 : $field_storage_config
->getCardinality();
// Create two deltas for each field.
for ($delta = 0; $delta <= $cardinality; $delta++) {
$node[$field_name][$delta]['value'] = $this
->randomMachineName(20);
$node[$field_name][$delta]['format'] = 'plain_text';
if ($field_storage_config
->getType() == 'text_with_summary') {
$node[$field_name][$delta]['summary'] = $this
->randomMachineName(10);
}
}
}
}
return $this
->drupalCreateNode($node);
}