You are here

public function LibraryCheckOutBulkForm::buildForm in Library 8

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 FormInterface::buildForm

File

src/Form/LibraryCheckOutBulkForm.php, line 31

Class

LibraryCheckOutBulkForm
Bulk checkout form.

Namespace

Drupal\library\Form

Code

public function buildForm(array $form, FormStateInterface $form_state, $action = NULL) : array {
  if ($action == NULL) {
    $form_state
      ->setErrorByName('action', $this
      ->t('Required parameters missing'));
    return $form;
  }
  $form['action'] = [
    '#type' => 'value',
    '#value' => $action,
  ];
  for ($i = 0; $i < 6; $i++) {
    $form['item_' . $i] = [
      '#type' => 'textfield',
      '#title' => $this
        ->t('Item'),
      '#description' => $this
        ->t('Enter items by barcode'),
      '#maxlength' => 20,
      '#size' => 20,
    ];
  }
  $actionEntity = LibraryAction::load($action);
  if ($actionEntity
    ->action() == LibraryAction::CHANGE_TO_UNAVAILABLE) {
    $form['patron'] = [
      '#type' => 'entity_autocomplete',
      '#target_type' => 'user',
      '#title' => $this
        ->t('Patron'),
      '#required' => TRUE,
    ];
  }
  $form['notes'] = [
    '#type' => 'textarea',
    '#title' => $this
      ->t('Message'),
    '#required' => FALSE,
    '#maxlength' => 250,
    '#default_value' => '',
    '#description' => $this
      ->t('If you are reserving an item, make sure to include the date and time you would like it to be ready.'),
  ];
  $form['submit'] = [
    '#type' => 'submit',
    '#value' => $actionEntity
      ->label(),
  ];
  return $form;
}