You are here

protected function ContactStorageExportForm::contactFormSelection in Contact Storage Export 8

Form for choosing a form to export.

Parameters

array $form: The Drupal form.

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

Return value

array The Drupal form.

1 call to ContactStorageExportForm::contactFormSelection()
ContactStorageExportForm::buildForm in src/Form/ContactStorageExportForm.php
Form constructor.

File

src/Form/ContactStorageExportForm.php, line 143

Class

ContactStorageExportForm
Settings form for config devel.

Namespace

Drupal\contact_storage_export\Form

Code

protected function contactFormSelection(array $form, FormStateInterface $form_state) {
  if ($bundles = \Drupal::service('entity_type.bundle.info')
    ->getBundleInfo('contact_message')) {
    $options = [];
    foreach ($bundles as $key => $bundle) {
      $options[$key] = $bundle['label'];
    }
    $form['contact_form'] = [
      '#type' => 'select',
      '#title' => t('Contact form'),
      '#options' => $options,
      '#required' => TRUE,
    ];
    $form['#attributes']['method'] = 'get';
    $form['actions']['#type'] = 'actions';
    $form['actions']['submit'] = [
      '#type' => 'submit',
      '#value' => $this
        ->t('Select form'),
      '#button_type' => 'primary',
    ];
  }
  else {
    $message = $this
      ->t('You must create a contact form first before you can export.');
    $messenger = \Drupal::messenger();
    $messenger
      ->addWarning($message);
  }
  return $form;
}