You are here

public function AbrconfigForm::form in Access by Reference 8.2

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/AbrconfigForm.php, line 149

Class

AbrconfigForm
Form handler for the Example add and edit forms.

Namespace

Drupal\access_by_ref\Form

Code

public function form(array $form, FormStateInterface $form_state) {
  $form = parent::form($form, $form_state);

  /** @var \Drupal\access_by_ref\Entity\Abrconfig $example */
  $example = $this->entity;
  $form['label'] = [
    '#type' => 'textfield',
    '#title' => $this
      ->t('Label'),
    '#maxlength' => 255,
    '#default_value' => $example
      ->label(),
    '#description' => $this
      ->t("Label for the abr config entry."),
    '#required' => TRUE,
  ];
  $form['id'] = [
    '#type' => 'machine_name',
    '#default_value' => $example
      ->id(),
    '#machine_name' => [
      'exists' => [
        $this,
        'exist',
      ],
    ],
    '#disabled' => !$example
      ->isNew(),
  ];
  $form['bundle'] = [
    '#type' => 'select',
    '#empty_option' => $this
      ->t('- Select -'),
    '#options' => $this
      ->getBundlesList('node'),
    '#title' => $this
      ->t('Bundle'),
    '#default_value' => $example
      ->getBundle(),
    '#description' => $this
      ->t("Bundle of the abr config entry."),
    '#required' => TRUE,
  ];
  $form['field'] = [
    '#type' => 'select',
    '#empty_option' => $this
      ->t('- Select -'),
    '#options' => $this
      ->getFieldsList(),
    '#title' => $this
      ->t('Field'),
    '#default_value' => $example
      ->getField(),
    '#description' => $this
      ->t("The field of the bundle."),
    '#required' => TRUE,
  ];
  $form['reference_type'] = [
    '#type' => 'select',
    '#empty_option' => $this
      ->t('- Select -'),
    '#options' => $this
      ->getReferenceTypesList(),
    '#title' => $this
      ->t('Reference type'),
    '#default_value' => $example
      ->getReferenceType(),
    '#description' => $this
      ->t("Reference type of the abr config entry."),
    '#required' => TRUE,
  ];
  $form['extra'] = [
    '#type' => 'select',
    '#empty_option' => $this
      ->t('- Select -'),
    '#options' => $this
      ->getUserFieldsList(),
    '#title' => $this
      ->t('Extra field'),
    '#default_value' => $example
      ->getExtra(),
    '#description' => $this
      ->t("In case of matching a node value with user 'profile value', specify here the user field that has to match."),
    '#required' => FALSE,
  ];
  $form['rights_type'] = [
    '#type' => 'select',
    '#empty_option' => $this
      ->t('- Select -'),
    '#options' => $this
      ->getRightsTypeList(),
    '#title' => $this
      ->t('Rights type field'),
    '#default_value' => $example
      ->getRightsType(),
    '#description' => $this
      ->t("Select against which operation the 'parent' node / element needs to be checked."),
    '#required' => FALSE,
  ];
  $form['rights_read'] = [
    '#type' => 'checkbox',
    '#title' => $this
      ->t('Assign read rights?'),
    '#default_value' => $example
      ->getRightsRead(),
    '#description' => $this
      ->t(""),
    '#required' => FALSE,
  ];
  $form['rights_update'] = [
    '#type' => 'checkbox',
    '#title' => $this
      ->t('Assign update rights?'),
    '#default_value' => $example
      ->getRightsUpdate(),
    '#description' => $this
      ->t(""),
    '#required' => FALSE,
  ];
  $form['rights_delete'] = [
    '#type' => 'checkbox',
    '#title' => $this
      ->t('Assign delete rights?'),
    '#default_value' => $example
      ->getRightsDelete(),
    '#description' => $this
      ->t(""),
    '#required' => FALSE,
  ];
  $form['#attached']['library'][] = 'access_by_ref/configform';

  // You will need additional form elements for your custom properties.
  return $form;
}