O'Reilly logo

Drupal 8 Module Development by Daniel Sipos

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Managed file form element

The other obligatory method we need to implement is getConfigurationForm(), by which we define the form elements needed to configure this particular plugin. Here, we will create the file field allowing users to upload the CSV file:

/**
 * {@inheritdoc}
 */
public function getConfigurationForm(\Drupal\products\Entity\ImporterInterface $importer) {
  $form = [];
  $config = $importer->getPluginConfiguration();
  $form['file'] = [
    '#type' => 'managed_file',
    '#default_value' => isset($config['file']) ? $config['file'] : '',
    '#title' => $this->t('File'),
    '#description' => $this->t('The CSV file containing the product records.'),
    '#required' => TRUE,
  ];

  return $form;
}

The form element type is called managed_file (implemented ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required