You are here

public function AccessSchemeForm::form in Workbench Access 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/AccessSchemeForm.php, line 52

Class

AccessSchemeForm
Provides the access scheme form.

Namespace

Drupal\workbench_access\Form

Code

public function form(array $form, FormStateInterface $form_state) {
  $form = parent::form($form, $form_state);
  $access_scheme = $this->entity;
  $form['label'] = [
    '#type' => 'textfield',
    '#title' => $this
      ->t('Label'),
    '#maxlength' => 255,
    '#default_value' => $access_scheme
      ->label(),
    '#description' => $this
      ->t("Label for the Access scheme."),
    '#required' => TRUE,
  ];
  $form['id'] = [
    '#type' => 'machine_name',
    '#default_value' => $access_scheme
      ->id(),
    '#machine_name' => [
      'exists' => '\\Drupal\\workbench_access\\Entity\\AccessScheme::load',
    ],
    '#disabled' => !$access_scheme
      ->isNew(),
  ];
  $form['plural_label'] = [
    '#type' => 'textfield',
    '#title' => $this
      ->t('Plural Label'),
    '#maxlength' => 255,
    '#default_value' => $access_scheme
      ->getPluralLabel(),
    '#description' => $this
      ->t("Plural Label for the Access scheme."),
    '#required' => TRUE,
  ];
  if ($access_scheme
    ->getAccessScheme()
    ->hasFormClass('configure')) {
    $form['scheme_settings'] = [
      '#tree' => TRUE,
    ];
    $subform_state = SubformState::createForSubform($form['scheme_settings'], $form, $form_state);
    $form['scheme_settings'] += $access_scheme
      ->getAccessScheme()
      ->buildConfigurationForm($form['scheme_settings'], $subform_state);
  }
  return $form;
}