You are here

public function EntityLegalDocumentVersionForm::form in Entity Legal 4.0.x

Same name and namespace in other branches
  1. 8.2 src/Form/EntityLegalDocumentVersionForm.php \Drupal\entity_legal\Form\EntityLegalDocumentVersionForm::form()
  2. 3.0.x src/Form/EntityLegalDocumentVersionForm.php \Drupal\entity_legal\Form\EntityLegalDocumentVersionForm::form()

Gets the actual form array to be built.

Overrides ContentEntityForm::form

See also

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

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

File

src/Form/EntityLegalDocumentVersionForm.php, line 25

Class

EntityLegalDocumentVersionForm
Class EntityLegalDocumentVersionForm.

Namespace

Drupal\entity_legal\Form

Code

public function form(array $form, FormStateInterface $form_state) {
  $form['label'] = [
    '#title' => t('Title'),
    '#type' => 'textfield',
    '#default_value' => $this->entity
      ->label(),
    '#required' => TRUE,
  ];
  $form['name'] = [
    '#type' => 'machine_name',
    '#title' => t('Machine-readable name'),
    '#required' => TRUE,
    '#default_value' => !$this->entity
      ->isNew() ? $this->entity
      ->id() : $this->entity
      ->getDefaultName($this->entity),
    '#machine_name' => [
      'exists' => '\\Drupal\\entity_legal\\Entity\\EntityLegalDocumentVersion::load',
    ],
    '#disabled' => !$this->entity
      ->isNew(),
    '#maxlength' => 64,
  ];
  $form['acceptance_label'] = [
    '#title' => t('Acceptance label'),
    '#type' => 'textfield',
    '#description' => t('e.g. I agree to the terms and conditions, use tokens to provide a link to the document.'),
    '#weight' => 50,
  ];
  if (isset($this->entity
    ->get('acceptance_label')->value)) {
    $form['acceptance_label']['#default_value'] = $this->entity
      ->get('acceptance_label')->value;
  }
  else {
    $form['acceptance_label']['#default_value'] = $this
      ->t('I agree to the <a href="@token_url">@document_label</a> document', [
      '@token_url' => '[entity_legal_document:url]',
      '@document_label' => $this->entity
        ->getDocument()
        ->label(),
    ])
      ->render();
  }
  $form['token_help'] = [
    '#theme' => 'token_tree_link',
    '#token_types' => [
      'entity_legal_document',
    ],
    '#weight' => 51,
  ];
  return parent::form($form, $form_state);
}