public function FlagForListDeleteForm::buildForm in Flag Lists 8
Same name and namespace in other branches
- 4.0.x src/Form/FlagForListDeleteForm.php \Drupal\flag_lists\Form\FlagForListDeleteForm::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 EntityConfirmFormBase::buildForm
File
- src/
Form/ FlagForListDeleteForm.php, line 17
Class
- FlagForListDeleteForm
- Builds the form to delete Flag for list entities.
Namespace
Drupal\flag_lists\FormCode
public function buildForm(array $form, FormStateInterface $form_state) {
// Check if this Flag For List is in use.
$flagListService = \Drupal::service('flaglists');
$flaggingCollections = $flagListService
->getAllFlaggingCollections();
$output = [];
foreach ($flaggingCollections as $flag) {
if ($flag
->getBaseFlag()
->id() == $this->entity
->id()) {
$output[] = $flag
->getName();
}
}
// If we are using this Flag For List let the user know.
if (!empty($output)) {
$form['active_items'] = [
'#theme' => 'item_list',
'#list_type' => 'ul',
'#items' => $output,
'#title' => $this
->t('Please remove the following Flagging Collections before proceding:'),
'#empty' => $this
->t('No Flag List Items found'),
];
}
$form = parent::buildForm($form, $form_state);
if (!empty($output)) {
// Unset the options for submitting the form.
unset($form['actions']['submit']);
unset($form['description']);
}
return $form;
}