You are here

public function DateRecurInterpreterAddForm::form in Recurring Dates Field 3.0.x

Same name and namespace in other branches
  1. 8.2 src/Form/DateRecurInterpreterAddForm.php \Drupal\date_recur\Form\DateRecurInterpreterAddForm::form()
  2. 3.x src/Form/DateRecurInterpreterAddForm.php \Drupal\date_recur\Form\DateRecurInterpreterAddForm::form()
  3. 3.1.x src/Form/DateRecurInterpreterAddForm.php \Drupal\date_recur\Form\DateRecurInterpreterAddForm::form()

Gets the actual form array to be built.

Overrides DateRecurInterpreterEditForm::form

See also

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

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

File

src/Form/DateRecurInterpreterAddForm.php, line 18

Class

DateRecurInterpreterAddForm
Add form for date recur interpreter entities.

Namespace

Drupal\date_recur\Form

Code

public function form(array $form, FormStateInterface $form_state) : array {
  $dateRecurInterpreter = $this
    ->getEntity();
  $form['label'] = [
    '#title' => $this
      ->t('Label'),
    '#type' => 'textfield',
    '#default_value' => $dateRecurInterpreter
      ->label(),
    '#required' => TRUE,
  ];
  $form['id'] = [
    '#type' => 'machine_name',
    '#default_value' => $dateRecurInterpreter
      ->id(),
    '#machine_name' => [
      'exists' => [
        DateRecurInterpreter::class,
        'load',
      ],
    ],
  ];
  $options = array_map(function (array $definition) : string {
    return (string) $definition['label'];
  }, $this->dateRecurInterpreterPluginManager
    ->getDefinitions());
  $form['plugin_type'] = [
    '#type' => 'select',
    '#title' => $this
      ->t('Plugin'),
    '#options' => $options,
    '#required' => TRUE,
  ];
  if ($pluginType = $form_state
    ->getValue('plugin_type')) {
    $dateRecurInterpreter
      ->setPlugin($pluginType);
    $form = parent::form($form, $form_state);
  }
  return $form;
}