You are here

public function InformBlockForm::form in Data Policy 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/Form/InformBlockForm.php, line 38

Class

InformBlockForm
Form handler for the InformBlock add and edit forms.

Namespace

Drupal\data_policy\Form

Code

public function form(array $form, FormStateInterface $form_state) {
  $form = parent::form($form, $form_state);
  $informblock = $this->entity;
  $form['status'] = [
    '#type' => 'checkbox',
    '#title' => $this
      ->t('Enable on this page'),
    '#default_value' => isset($informblock->status) ? $informblock->status : TRUE,
    '#disabled' => !$this
      ->currentUser()
      ->hasPermission('change inform and consent setting status'),
  ];
  $form['label'] = [
    '#type' => 'textfield',
    '#title' => $this
      ->t('Title'),
    '#maxlength' => 255,
    '#default_value' => $informblock
      ->label(),
    '#description' => $this
      ->t('Indicate what will be explained on this page.'),
    '#required' => TRUE,
  ];
  $form['page'] = [
    '#type' => 'textfield',
    '#title' => $this
      ->t('Page'),
    '#maxlength' => 255,
    '#default_value' => $informblock->page,
    '#description' => $this
      ->t('Specify page by using their path. An example path is %user-wildcard for every user edit page. %front is the front page.', [
      '%user-wildcard' => '/user/*/edit',
      '%front' => '<front>',
    ]),
    '#required' => TRUE,
  ];
  $form['id'] = [
    '#type' => 'machine_name',
    '#default_value' => $informblock
      ->id(),
    '#machine_name' => [
      'exists' => [
        $this,
        'exist',
      ],
    ],
    '#disabled' => !$informblock
      ->isNew(),
  ];
  $form['summary'] = [
    '#type' => 'text_format',
    '#title' => $this
      ->t('Summary'),
    '#default_value' => $informblock->summary['value'],
    '#format' => $informblock->summary['format'],
    '#required' => TRUE,
    '#description' => $this
      ->t('Summarise what data is collected.'),
  ];
  $form['body'] = [
    '#type' => 'text_format',
    '#title' => $this
      ->t('Description'),
    '#default_value' => $informblock->body['value'],
    '#format' => $informblock->body['format'],
    '#required' => FALSE,
    '#description' => $this
      ->t('Describe in detail what data is collected and how it is used.'),
  ];
  return $form;
}