Import Data Into Content Type Along With File Uploads Drupal 8 Using Yml
Sometimes you may need to import data from a CSV file into Drupal.
We've spoken with OSTraining users who need to import from another CMS, and uses who need to import from a business organisation spreadsheet.
There is no like shooting fish in a barrel fashion do this import using the Drupal 8 core. To import your data from a CSV file, you need to install and enable the Content Import module.
In this tutorial, I'll walk you lot through the procedure of importing data with Content Import.
In this case, we'll import data into a "Customer" content type. This Customer content type will have the post-obit 5 fields:
Field Name | Field Description | Field Type |
Title | The proper noun of the customer / this is the default Drupal title field for each content type | Manifestly text |
Body | Customer information | Long text |
Contract Date | The date when the contract with the customer was signed | In the mm/dd/yy format |
Customer Movie | The picture of the customer | Image |
Disbelieve | This field indicates if the customer qualifies for an actress discount at the terminate of the year | Boolean (Aye/No) |
Step #ane. Create the Customer content type
Afterwards creating the Customer content type and adding fields, yous will accept the following starting point:
There are some details that you accept to take into account to run this process without complications:
- The date field has to be set up as Date and time(this is related to the Unix timestamp. You tin read more than near this here).
- When creating the Customer Moving-picture show paradigm field, configure the file directory for the images every bit [MACHINENAMEOFYOURCONTENTTYPE/images] You'll upload your images to this directory with the help of the IMCE module or some kind of FTP software
- Set the On and Off labels in your Discount boolean field to Yes and No respectively
Pace #two. Prepare your spreadsheet for import
You lot tin can use the spreadsheet awarding of your liking for this. I'm using Google Spreadsheets. The langcode column is mandatory
- Save your spreadsheet as a Comma Separated Values file. Once you practice, your file will accept a .csv file extension.
Step #3. Upload the profile pictures to the specified directory
With the IMCE module:
- Become to yoursite/imce in order to open up the IMCE browser
- Create the /customer folder inside the public directory
- Create the /images sub-binder inside the /client folder
- Upload the profile pictures to this folder past clicking the Upload button on the peak (/customer/images folder in our case)
Pace #four. Import your content from the CSV file
- Click Configuration > Content Authoring > Content Import
You lot will see a screen with ii options.
- Select the Customer selection for the Select Content Blazon
- Click on the Upload File button
- Select the CSV file on your hard drive
- Click Import
Congratulations! If you followed along with my instructions, you should at present see the Content screen of your Drupal installation with your newly imported content.
Troubleshooting Your Drupal CSV Import
While importing content, you may come across the following mistake on the white page:
"The website encountered an unexpected error. Please attempt again subsequently."
To deal with this error, please do the post-obit:
- In your Drupal site root become to modules > contentimport > src > form
- Open up the contentImport.php file in your text or code editor
- Find the following two lines (around line 275):
$dateTime = DateTime::createFromFormat('Y-m-d h:i:southward', $data[$keyIndex[$fieldNames[$f]]]);
$newDateString = $dateTime->format('Y-chiliad-dTh:i:s');
Replace them with the post-obit ii lines:
$dateTimeStamp = strtotime($data[$keyIndex[$fieldNames[$f]]]);
$newDateString = appointment('Y-m-dTH:i:s', $dateTimeStamp);
Yous'll observe more than information about this mistake here.
I promise you enjoyed this tutorial.
If you lot want to learn more Drupal, bring together OSTraining now. You'll get access to a vast library of Drupal grooming videos, plus the acknowledged"Drupal 8 Explained" book!
Source: https://ostraining.com/blog/drupal/content-import-module/
0 Response to "Import Data Into Content Type Along With File Uploads Drupal 8 Using Yml"
Post a Comment