You are here

public function EmailOverrideForm::form in Easy Email 8

Same name and namespace in other branches
  1. 2.0.x modules/easy_email_override/src/Form/EmailOverrideForm.php \Drupal\easy_email_override\Form\EmailOverrideForm::form()

Gets the actual form array to be built.

Overrides EntityForm::form

See also

\Drupal\Core\Entity\EntityForm::processForm()

\Drupal\Core\Entity\EntityForm::afterBuild()

File

modules/easy_email_override/src/Form/EmailOverrideForm.php, line 167

Class

EmailOverrideForm
Class EmailOverrideForm.

Namespace

Drupal\easy_email_override\Form

Code

public function form(array $form, FormStateInterface $form_state) {
  $form = parent::form($form, $form_state);
  $form['#tree'] = TRUE;

  /** @var \Drupal\easy_email_override\Entity\EmailOverrideInterface $easy_email_override */
  $easy_email_override = $this->entity;
  $form['label'] = [
    '#type' => 'textfield',
    '#title' => $this
      ->t('Label'),
    '#maxlength' => 255,
    '#default_value' => $easy_email_override
      ->label(),
    '#description' => $this
      ->t("Label for the Email Override."),
    '#required' => TRUE,
  ];
  $form['id'] = [
    '#type' => 'machine_name',
    '#default_value' => $easy_email_override
      ->id(),
    '#machine_name' => [
      'exists' => '\\Drupal\\easy_email_override\\Entity\\EmailOverride::load',
    ],
    '#disabled' => !$easy_email_override
      ->isNew(),
  ];
  $email_id = $this
    ->getEmailDefaultValue();
  $form['email_id'] = [
    '#type' => 'select',
    '#title' => $this
      ->t('Email to Override'),
    '#options' => $this
      ->getEmailOptions(),
    '#default_value' => $email_id,
    '#disabled' => !is_null($email_id),
    '#required' => TRUE,
  ];
  $easy_email_type = $easy_email_override
    ->getEasyEmailType();
  $form['easy_email_type'] = [
    '#type' => 'select',
    '#title' => $this
      ->t('Easy Email Template'),
    '#options' => $this
      ->getEasyEmailTemplateOptions(),
    '#default_value' => $easy_email_type,
    '#disabled' => !is_null($easy_email_type),
    '#required' => TRUE,
  ];
  if (!empty($email_id) && !empty($easy_email_type)) {
    $form['mappings'] = [
      '#type' => 'fieldset',
      '#title' => $this
        ->t('Parameter Mapping'),
    ];
    $possible_mappings = $this
      ->getPossibleMappings($email_id, $easy_email_type);
    foreach ($possible_mappings as $source_id => $mapping_info) {
      $form['mappings'][$source_id] = [
        '#type' => 'select',
        '#title' => $mapping_info['label'],
        '#options' => array_merge([
          '' => '',
        ], $mapping_info['options']),
        '#default_value' => $this
          ->getMappingDefaultValue($source_id),
      ];
    }
  }
  return $form;
}