You are here

public function LogTypeForm::form in Log entity 8

Same name and namespace in other branches
  1. 2.x src/Form/LogTypeForm.php \Drupal\log\Form\LogTypeForm::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

src/Form/LogTypeForm.php, line 23
Contains \Drupal\log\Form\LogTypeForm.

Class

LogTypeForm
Class LogTypeForm.

Namespace

Drupal\log\Form

Code

public function form(array $form, FormStateInterface $form_state) {
  $form = parent::form($form, $form_state);
  $log_type = $this->entity;
  $form['label'] = array(
    '#type' => 'textfield',
    '#title' => $this
      ->t('Label'),
    '#maxlength' => 255,
    '#default_value' => $log_type
      ->label(),
    '#description' => $this
      ->t("Label for the Log type."),
    '#required' => TRUE,
  );
  $form['id'] = array(
    '#type' => 'machine_name',
    '#default_value' => $log_type
      ->id(),
    '#machine_name' => array(
      'exists' => '\\Drupal\\log\\Entity\\LogType::load',
    ),
    '#disabled' => !$log_type
      ->isNew(),
  );
  $form['description'] = array(
    '#type' => 'textarea',
    '#title' => $this
      ->t('Description'),
    '#default_value' => $log_type
      ->getDescription(),
    '#description' => $this
      ->t("Log type description."),
  );
  $form['name_pattern'] = array(
    '#type' => 'textfield',
    '#title' => $this
      ->t('Name pattern'),
    '#maxlength' => 255,
    '#default_value' => $log_type
      ->getNamePattern(),
    '#desription' => $this
      ->t('When a log name is auto-generated, this is the naming pattern that will be used. Available tokens are below.'),
    // @todo: There is no need to require pattern here.
    '#required' => TRUE,
  );
  $form['name_edit'] = array(
    '#type' => 'checkbox',
    '#title' => $this
      ->t('Allow name editing'),
    '#default_value' => $log_type
      ->isNameEditable(),
    '#description' => t('Check this to allow users to edit log names. Otherwise, log names will always be auto-generated.'),
  );
  $form['done'] = array(
    '#type' => 'checkbox',
    '#title' => $this
      ->t('Automatically done'),
    '#default_value' => $log_type
      ->isAutomaticallyDone(),
    '#description' => t('Automatically mark logs of this type as "done".'),
  );
  $form['new_revision'] = array(
    '#type' => 'checkbox',
    '#title' => $this
      ->t('Create new revision'),
    '#default_value' => $log_type
      ->isNewRevision(),
  );
  return $form;
}