2

How can I import users fom a CSV file in Drupal 8?

I’ve found this module but it is not updated for Drupal 8:

https://www.drupal.org/project/user_import

I think that I can make an import directly with a MySQL script but is it possible with Drupal (I know I can insert datas directly into database but I don't know if Drupal system will allow that method)?

I’ve found this question but it is not exactly what i need : Importing a bunch of users from csv spreadsheet file into Drupal 8

I import data from a csv file and it is not a migration from a drupal site.

  • 2
    It doesn't matter if the source isn't a Drupal site. Migrate is designed to work with various datasources, which has great support for CSV files of data. – Kevin Sep 21 '17 at 14:09
1

To make it with Migrate you need to setup Migrate Plus, Migrate Tools and Migrate Source CSV together, there is lot of examples in the web already:

http://valuebound.com/resources/blog/how-to-migrate-users-from-a-csv-file-drupal-8

https://agencychief.com/blog/drupal-8-csv-migration

https://www.mtech-llc.com/blog/lucas-hedding/migrating-using-csv

  • Thank you. It is exactly what i need. Your 3 links are really interesting. I’ve used the 1st one and it works. The 2nd is based on a custom module and i will try it. The 3rd is written by the maintainer of the D8 Migrate Source CSV contrib module so it s also an excellent article. – Sébastien Gicquel Sep 22 '17 at 8:59
  • So i can import a list of users. Now, i have to import datas in a custom module that contains datas related to the user. I see it is possible but didn’t try it yet : drupal.org/docs/8/api/migrate-api/migrate-process-plugins/… – Sébastien Gicquel Sep 22 '17 at 9:01
2

I think that I can make an import directly with a MySQL script but is it possible with Drupal (I know I can insert datas directly into database but U don't know if Drupal system will allow that method)?

Instead of MySQL this would be a Drupal method to insert users by using the Entity API:

$user = User::create([
  'name' => 'foobar',
  'mail' => 'foobar@example.com',
  'status' => TRUE,
]);
$user->save();

So if you don't want to use Migrate there are other ways for such a simple import task. You can use a php library of your choice to fetch the data and then add the user entities one by one. I answered a similar question for importing nodes at a time when Migrate was still in alpha: Is there a way to migrate only nodes?

0

Here I found the solution for it. Please follow this link https://github.com/steveoliver/user_import and install the extended module. You can import the user data file through this path (path: '/admin/people/import').

  • Interesting. I’ll try it. But I see that it only handles fname,lname,email. In @drupalranger answer, there are links that explain how to import custom datas (like job, image, etc.) – Sébastien Gicquel Mar 20 '18 at 9:01

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.