I will assume a scenario where you just need to import some simple data from a csv file into Drupal.
No multi value fields, no reference fields (including image fields), etc.
Such scenario would require a much complicated script.
The solution I’m suggesting (bellow) assumes that you have drush installed and you are willing to run a php script under drush.
Something like the following might work:
<?php
// php -d memory_limit=-1 vendor/bin/drush php:script import_nodes.php
// general options
$csv_file_name = '/the/path/to/file.csv';
$type = 'some_type';
// get csv
$items_to_import = get_array_from_csv ($csv_file_name);
// start import
foreach ($items_to_import as $item) {
// set title
$title = $item['title'];
// create node
$node = \Drupal::entityTypeManager()
->getStorage('node')
->create([
'type' => $type,
'title' => $title,
]);
// set field_foo
$field_foo = $item['field_foo'];
$node->set('field_foo', $field_foo);
// set field_bar
$field_bar = $item['field_bar'];
$node->set('field_bar', $field_bar);
$node->save();
unset ($node);
}
function get_array_from_csv ($filePath) {
$dataArray = [];
$rows = array_map ('str_getcsv', file ($filePath));
$header = array_shift ($rows);
foreach($rows as $row) {
$dataArray[] = array_combine ($header, $row);
}
return $dataArray;
}
Run it (from your site directory) with the command:
php vendor/bin/drush php:script import_nodes.php
Or (if on low allocated memory for php) with the command:
php -d memory_limit=-1 vendor/bin/drush php:script import_nodes.php