You are here

public function Mp3playerDeleteForm::buildForm in MP3 Player 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 ConfirmFormBase::buildForm

File

src/Form/Mp3playerDeleteForm.php, line 62
Contains \Drupal\mp3player\Form\ExampleForm.

Class

Mp3playerDeleteForm
Implements Mp3playerDeleteForm.

Namespace

Drupal\mp3player\Form

Code

public function buildForm(array $form, FormStateInterface $form_state, $pid = NULL) {
  $player = Mp3playerController::mp3player_players($pid);
  if ($pid) {
    $player = $player[$pid];
    $this->pid = $pid;
    $this->name = $player['name'];
  }
  if (empty($player)) {
    drupal_set_message(t('The specified player was not found.'), 'error');
    $response = new RedirectResponse(Drupal::url('mp3player.player_list'));
    $response
      ->send();
  }
  if ($player['name'] == 'Default') {
    drupal_set_message(t('You cannot delete the Default player.'), 'error');
    $response = new RedirectResponse(Drupal::url('mp3player.player_list'));
    $response
      ->send();
  }
  $form['pid'] = array(
    '#type' => 'value',
    '#value' => $pid,
  );
  return parent::buildForm($form, $form_state);
}