You are here

public function MetaTagDownloadForm::buildForm in Metatag Import Export CSV 8

Form constructor.

Parameters

array $form: An associative array containing the structure of the form.

\Drupal\Core\Form\FormStateInterface $form_state: The current state of the form.

Return value

array The form structure.

Overrides FormInterface::buildForm

File

src/Form/MetaTagDownloadForm.php, line 25

Class

MetaTagDownloadForm
Defines a form that configures forms module settings.

Namespace

Drupal\metatag_import_export_csv\Form

Code

public function buildForm(array $form, FormStateInterface $form_state) {
  $form['entity_type'] = [
    '#title' => $this
      ->t('Entity type'),
    '#type' => 'select',
    '#required' => TRUE,
    '#options' => $this
      ->getEntityTypes(),
    '#default_value' => isset($this
      ->getEntityTypes()['node']) ? 'node' : '',
    '#ajax' => [
      'callback' => '::getBundlesList',
      'event' => 'change',
    ],
  ];
  if ($entity_type = $form_state
    ->getValue('entity_type')) {
    $bundle_options = $this
      ->getBundles($entity_type);
  }
  elseif (!empty($form['entity_type']['#default_value'])) {
    $bundle_options = $this
      ->getBundles($form['entity_type']['#default_value']);
  }
  $form['bundles'] = [
    '#title' => $this
      ->t('Bundle'),
    '#type' => 'select',
    '#multiple' => "multiple",
    '#required' => TRUE,
    '#validated' => TRUE,
    '#options' => $bundle_options,
  ];
  $form['tags'] = [
    '#title' => $this
      ->t('Tags'),
    '#type' => 'select',
    '#required' => TRUE,
    '#multiple' => "multiple",
    '#size' => 30,
    '#options' => $this
      ->getTags(),
  ];
  $form['delimiter'] = [
    '#title' => $this
      ->t('Delimiter'),
    '#type' => 'textfield',
    '#required' => TRUE,
    '#description' => t('Enter the delimiter for CSV.'),
    '#default_value' => ',',
    '#maxlength' => 2,
  ];
  $form['submit'] = [
    '#type' => 'submit',
    '#required' => TRUE,
    '#value' => $this
      ->t("Download"),
  ];
  return $form;
}