public function DeleteTermsConfirm::buildForm in Taxonomy Multi-delete Terms 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/ DeleteTermsConfirm.php, line 141
Class
- DeleteTermsConfirm
- Defines a confirmation form for deleting term data.
Namespace
Drupal\taxonomy_multidelete_terms\FormCode
public function buildForm(array $form, FormStateInterface $form_state) {
$term_data = $this
->getTermsId();
$form['terms'] = array(
'#prefix' => '<ul>',
'#suffix' => '</ul>',
'#tree' => TRUE,
);
foreach ($term_data as $tid) {
$val = \Drupal::entityTypeManager()
->getStorage('taxonomy_term')
->load($tid);
if (!$val) {
$form_state
->setRedirectUrl($this
->getRedirectUrl());
$response = new RedirectResponse($this
->getCancelUrl()
->toString());
$response
->send();
return $response;
}
$termname = Term::load($tid)
->get('name')->value;
$form['terms'][$tid] = array(
'#type' => 'hidden',
'#value' => $tid,
'#prefix' => '<li>',
'#suffix' => $termname . "</li>\n",
);
}
$form['operation'] = array(
'#type' => 'hidden',
'#value' => 'cancel',
);
$form = parent::buildForm($form, $form_state);
return $form;
}