You are here

public function MenuDeleteItem::buildForm in Menu Delete 8

Same name and namespace in other branches
  1. 8.2 src/Form/MenuDeleteItem.php \Drupal\menu_delete\Form\MenuDeleteItem::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 ConfirmFormBase::buildForm

File

src/Form/MenuDeleteItem.php, line 100

Class

MenuDeleteItem
Class MenuDeleteItem.

Namespace

Drupal\menu_delete\Form

Code

public function buildForm(array $form, FormStateInterface $form_state) {
  $storage = $this->tempStoreFactory
    ->get('menu_delete_item_confirm')
    ->get(\Drupal::currentUser()
    ->id());
  $this->menuId = $storage['menu_id'];
  $this->menuItems = $storage['items'];
  if (empty($this->menuItems)) {
    return new RedirectResponse($this
      ->getCancelUrl()
      ->setAbsolute()
      ->toString());
  }
  $items = [];
  foreach ($this->menuItems as $id => $item) {
    list($entity_type_id, $uuid) = explode(':', $item['id']);
    $link = $this->entityManager
      ->loadEntityByUuid($entity_type_id, $uuid);
    $items[$uuid] = $link
      ->getTitle();
  }
  $form['menu_items'] = array(
    '#theme' => 'item_list',
    '#items' => $items,
  );
  $form = parent::buildForm($form, $form_state);
  return $form;
}