public function MergeTermsConfirm::buildForm in Term Merge 8
Plugin annotation
@SuppressWarnings(camelCase)
@SuppressWarnings("else")
Overrides FormInterface::buildForm
File
- src/
Form/ MergeTermsConfirm.php, line 98
Class
- MergeTermsConfirm
- Term merge confirm form.
Namespace
Drupal\term_merge\FormCode
public function buildForm(array $form, FormStateInterface $form_state, VocabularyInterface $taxonomy_vocabulary = NULL) {
$this->vocabulary = $taxonomy_vocabulary;
$selectedTermIds = $this
->getSelectedTermIds();
if (empty($selectedTermIds)) {
$this
->messenger()
->addError($this
->t("You must submit at least one term."), 'error');
return $form;
}
$target = $this->tempStoreFactory
->get('term_merge')
->get('target');
if (!is_string($target) && !$target instanceof TermInterface) {
throw new \LogicException("Invalid target type. Should be string or implement TermInterface");
}
$arguments = [
'%termCount' => count($selectedTermIds),
'%termName' => is_string($target) ? $target : $target
->label(),
];
if (is_string($target)) {
$form['message']['#markup'] = $this
->t("You are about to merge %termCount terms into new term %termName. This action can't be undone. Are you sure you wish to continue with merging the terms below?", $arguments);
}
else {
$form['message']['#markup'] = $this
->t("You are about to merge %termCount terms into existing term %termName. This action can't be undone. Are you sure you wish to continue with merging the terms below?", $arguments);
}
$form['terms'] = [
'#title' => $this
->t("Terms to be merged"),
'#theme' => 'item_list',
'#items' => $this
->getSelectedTermLabels(),
];
$form['actions'] = [
'#type' => 'actions',
];
$form['actions']['submit'] = [
'#button_type' => 'primary',
'#type' => 'submit',
'#value' => $this
->t('Confirm merge'),
];
return $form;
}