You are here

public function FlaggingCollectionDeleteForm::buildForm in Flag Lists 8

Same name and namespace in other branches
  1. 4.0.x src/Form/FlaggingCollectionDeleteForm.php \Drupal\flag_lists\Form\FlaggingCollectionDeleteForm::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 ContentEntityDeleteForm::buildForm

File

src/Form/FlaggingCollectionDeleteForm.php, line 18

Class

FlaggingCollectionDeleteForm
Provides a form for deleting Flagging collection entities.

Namespace

Drupal\flag_lists\Form

Code

public function buildForm(array $form, FormStateInterface $form_state) {
  $entity = $this
    ->getEntity();

  // Build a list of Flag list items related to this connection.
  $flagListsService = \Drupal::service('flaglists');
  $flag_list_items = $flagListsService
    ->getFlagListItemIds($entity
    ->getRelatedFlag()
    ->id());
  if (!empty($flag_list_items)) {
    $output = [];
    $items = $flagListsService
      ->getFlagListItems($flag_list_items);
    foreach ($items as $item) {
      $output[] = $item
        ->getName();
    }
    $form['active_items'] = [
      '#theme' => 'item_list',
      '#list_type' => 'ul',
      '#items' => $output,
      '#title' => $this
        ->t('The following connected Flag List Items will be deleted as well:'),
      '#empty' => $this
        ->t('No Flag List Items found'),
    ];
  }
  $form = parent::buildForm($form, $form_state);
  return $form;
}