You are here

public function DeleteFolderForm::buildForm in Taxonomy File Tree 3.x

Same name and namespace in other branches
  1. 8 src/Form/DeleteFolderForm.php \Drupal\tft\Form\DeleteFolderForm::buildForm()

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/DeleteFolderForm.php, line 50

Class

DeleteFolderForm
Delete a term form.

Namespace

Drupal\tft\Form

Code

public function buildForm(array $form, FormStateInterface $form_state, TermInterface $taxonomy_term = NULL) {
  $tid = $taxonomy_term
    ->id();
  $name = $taxonomy_term
    ->getName();

  // Check that this term has no child terms or files.
  if (!$this
    ->check_term_is_deletable($tid)) {
    $form[] = [
      '#markup' => $this
        ->t("<em>@name</em> contains files and/or child folders. Move or delete these before deleting this folder.", [
        '@name' => $name,
      ]),
    ];
    $cancel_uri = str_replace('%23', '#', $_GET['destination']);
    $form['actions']['cancel'] = [
      '#type' => 'link',
      '#title' => $this
        ->t("cancel"),
      '#url' => Url::fromUri('internal:' . $cancel_uri),
    ];
    return $form;
  }
  $form['#title'] = $this
    ->t("Are you sure you want to delete the folder @term ?", [
    '@term' => $name,
  ]);
  $form['tid'] = [
    '#type' => 'hidden',
    '#value' => $tid,
  ];
  $form['actions']['submit'] = [
    '#type' => 'submit',
    '#value' => $this
      ->t('Delete'),
  ];
  $cancel_uri = str_replace('%23', '#', $_GET['destination']);
  $form['actions']['cancel'] = [
    '#type' => 'link',
    '#title' => $this
      ->t("cancel"),
    '#url' => Url::fromUri('internal:' . $cancel_uri),
  ];
  return $form;
}