Managed file uploads

Next, we are going to look at how we can work with managed files using a custom form element. And to demonstrate this, we are finally going to create another Product importer plugin. This time, instead of a remote JSON resource, we will allow users to upload a CSV file that contains product data and imports that into Product entities. This is what the example CSV data looks like:

id,name,number
1,Car,45345
2,Motorbike,54534

It basically has the same kind of data as the JSON resource we've been looking at so far, but without the image reference. So let's get going with our new plugin class.

Here is our starting point:

namespace Drupal\products\Plugin\Importer; use Drupal\Core\Entity\EntityTypeManager; use Drupal\Core\StreamWrapper\StreamWrapperManagerInterface; ...

Get Drupal 8 Module Development now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.