You are here

public function YamlFormEntityForm::form in YAML Form 8

Gets the actual form array to be built.

Overrides EntityForm::form

See also

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

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

File

src/YamlFormEntityForm.php, line 115

Class

YamlFormEntityForm
Base for controller for form.

Namespace

Drupal\yamlform

Code

public function form(array $form, FormStateInterface $form_state) {

  /** @var \Drupal\yamlform\YamlFormInterface $yamlform */
  $yamlform = $this
    ->getEntity();

  // Only display id, title, and description for new forms.
  // Once a form is created this information is moved to the form's settings
  // tab.
  if ($yamlform
    ->isNew()) {
    $form['id'] = [
      '#type' => 'machine_name',
      '#default_value' => $yamlform
        ->id(),
      '#machine_name' => [
        'exists' => '\\Drupal\\yamlform\\Entity\\YamlForm::load',
        'source' => [
          'title',
        ],
      ],
      '#maxlength' => 32,
      '#disabled' => (bool) $yamlform
        ->id() && $this->operation != 'duplicate',
      '#required' => TRUE,
    ];
    $form['title'] = [
      '#type' => 'textfield',
      '#title' => $this
        ->t('Title'),
      '#maxlength' => 255,
      '#default_value' => $yamlform
        ->label(),
      '#required' => TRUE,
      '#id' => 'title',
      '#attributes' => [
        'autofocus' => 'autofocus',
      ],
    ];
    $form['description'] = [
      '#type' => 'yamlform_html_editor',
      '#title' => $this
        ->t('Administrative description'),
      '#default_value' => $yamlform
        ->get('description'),
    ];
    $form = $this
      ->protectBundleIdElement($form);
  }

  // Call the isolated edit form that can be overridden by the
  // yamlform_ui.module.
  $form = $this
    ->editForm($form, $form_state);
  return parent::form($form, $form_state);
}