You are here

public function WebformMapping::form in Webform 8.5

Same name and namespace in other branches
  1. 6.x src/Plugin/WebformElement/WebformMapping.php \Drupal\webform\Plugin\WebformElement\WebformMapping::form()

Gets the actual configuration webform array to be built.

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 An associative array contain the element's configuration webform without any default values.

Overrides WebformElementBase::form

File

src/Plugin/WebformElement/WebformMapping.php, line 362

Class

WebformMapping
Provides a 'mapping' element.

Namespace

Drupal\webform\Plugin\WebformElement

Code

public function form(array $form, FormStateInterface $form_state) {
  $form = parent::form($form, $form_state);
  $form['mapping'] = [
    '#type' => 'fieldset',
    '#title' => $this
      ->t('Mapping settings'),
  ];
  $form['mapping']['arrow'] = [
    '#type' => 'textfield',
    '#title' => $this
      ->t('Arrow character'),
    '#size' => 10,
  ];
  $form['mapping']['mapping_source'] = [
    '#type' => 'fieldset',
    '#title' => $this
      ->t('Mapping source'),
  ];
  $form['mapping']['mapping_source']['source__title'] = [
    '#type' => 'textfield',
    '#title' => $this
      ->t('Source title'),
  ];
  $form['mapping']['mapping_source']['source'] = [
    '#type' => 'webform_element_options',
    '#title' => $this
      ->t('Source options'),
    '#label' => $this
      ->t('source'),
    '#labels' => $this
      ->t('sources'),
    '#required' => TRUE,
    '#options_description' => TRUE,
  ];
  $form['mapping']['mapping_source']['source__description_display'] = [
    '#title' => $this
      ->t('Source description display'),
    '#type' => 'select',
    '#options' => [
      'description' => $this
        ->t('Description'),
      'help' => $this
        ->t('Help text'),
    ],
  ];
  $form['mapping']['mapping_destination'] = [
    '#type' => 'fieldset',
    '#title' => $this
      ->t('Mapping destination'),
  ];
  $form['mapping']['mapping_destination']['destination__type'] = [
    '#type' => 'select',
    '#title' => $this
      ->t('Destination type'),
    '#options' => [
      'select' => $this
        ->t('Select'),
      'webform_select_other' => $this
        ->t('Select other'),
      'textfield' => $this
        ->t('Textfield'),
      'email' => $this
        ->t('Email'),
      'tel' => $this
        ->t('Telephone'),
      'url' => $this
        ->t('Url'),
      'webform_email_multiple' => $this
        ->t('Email multiple'),
    ],
    '#other__description' => $this
      ->t('Please enter an element type.'),
  ];
  $form['mapping']['mapping_destination']['destination__title'] = [
    '#type' => 'textfield',
    '#title' => $this
      ->t('Destination title'),
  ];
  $form['mapping']['mapping_destination']['destination__description'] = [
    '#type' => 'webform_html_editor',
    '#title' => $this
      ->t('Destination description'),
  ];
  $form['mapping']['mapping_destination']['destination'] = [
    '#type' => 'webform_element_options',
    '#title' => $this
      ->t('Destination options'),
    '#label' => $this
      ->t('destination'),
    '#labels' => $this
      ->t('destinations'),
    '#states' => [
      'visible' => [
        [
          ':input[name="properties[destination__type][select]"]' => [
            'value' => 'select',
          ],
        ],
        'or',
        [
          ':input[name="properties[destination__type][select]"]' => [
            'value' => 'webform_select_other',
          ],
        ],
      ],
    ],
  ];
  return $form;
}