You are here

public function LogAssignActionForm::buildForm in farmOS 2.x

Form constructor.

Parameters

array $form: An associative array containing the structure of the form.

\Drupal\Core\Form\FormStateInterface $form_state: The current state of the form.

Return value

array The form structure.

Overrides ConfirmFormBase::buildForm

File

modules/core/owner/src/Form/LogAssignActionForm.php, line 139

Class

LogAssignActionForm
Provides a log assign confirmation form.

Namespace

Drupal\farm_owner\Form

Code

public function buildForm(array $form, FormStateInterface $form_state) {
  $this->entityType = $this->entityTypeManager
    ->getDefinition('log');
  $this->entities = $this->tempStore
    ->get($this->user
    ->id());
  if (empty($this->entityType) || empty($this->entities)) {
    return new RedirectResponse($this
      ->getCancelUrl()
      ->setAbsolute()
      ->toString());
  }

  // Load active users.
  $active_users = $this->entityTypeManager
    ->getStorage('user')
    ->loadByProperties([
    'status' => TRUE,
  ]);

  // Build options for form select.
  $user_options = array_map(function ($user) {
    return $user
      ->label();
  }, $active_users);
  $form['users'] = [
    '#type' => 'select',
    '#title' => $this
      ->t('Assign log(s) to'),
    '#description' => $this
      ->t('Select people to assign these logs to.'),
    '#options' => $user_options,
    '#multiple' => TRUE,
  ];
  $form['operation'] = [
    '#type' => 'radios',
    '#title' => $this
      ->t('Append or replace'),
    '#description' => $this
      ->t('Select "Append" if you want to add users to the logs, but keep the existing assignments. Select "Replace" if you want to replace existing assignments with the ones specified above.'),
    '#options' => [
      'append' => $this
        ->t('Append'),
      'replace' => $this
        ->t('Replace'),
    ],
    '#default_value' => 'append',
    '#required' => TRUE,
  ];
  return parent::buildForm($form, $form_state);
}