You are here

public function TaxonomyMenuForm::form in Zircon Profile 8

Same name and namespace in other branches
  1. 8.0 modules/taxonomy_menu/src/Form/TaxonomyMenuForm.php \Drupal\taxonomy_menu\Form\TaxonomyMenuForm::form()

Gets the actual form array to be built.

Overrides EntityForm::form

See also

\Drupal\Core\Entity\EntityForm::processForm()

\Drupal\Core\Entity\EntityForm::afterBuild()

File

modules/taxonomy_menu/src/Form/TaxonomyMenuForm.php, line 23
Contains Drupal\taxonomy_menu\Form\TaxonomyMenuForm.

Class

TaxonomyMenuForm
Class TaxonomyMenuForm.

Namespace

Drupal\taxonomy_menu\Form

Code

public function form(array $form, FormStateInterface $form_state) {
  $form = parent::form($form, $form_state);

  /** @var $taxonomy_menu \Drupal\taxonomy_menu\Entity\TaxonomyMenu */
  $taxonomy_menu = $this->entity;
  $form['label'] = array(
    '#type' => 'textfield',
    '#title' => $this
      ->t('Label'),
    '#maxlength' => 255,
    '#default_value' => $taxonomy_menu
      ->label(),
    '#description' => $this
      ->t("Label for the Taxonomy Menu."),
    '#required' => TRUE,
  );
  $form['id'] = array(
    '#type' => 'machine_name',
    '#default_value' => $taxonomy_menu
      ->id(),
    '#machine_name' => array(
      'exists' => '\\Drupal\\taxonomy_menu\\Entity\\TaxonomyMenu::load',
    ),
    '#disabled' => !$taxonomy_menu
      ->isNew(),
  );

  // Vocabulary selection.
  $options = [];
  $vocabulary_storage = \Drupal::entityManager()
    ->getStorage('taxonomy_vocabulary');
  foreach ($vocabulary_storage
    ->loadMultiple() as $vocabulary) {
    $options[$vocabulary
      ->id()] = $vocabulary
      ->label();
  }
  $form['vocabulary'] = [
    '#type' => 'select',
    '#title' => $this
      ->t('Vocabulary'),
    '#options' => $options,
    '#default_value' => $taxonomy_menu
      ->getVocabulary(),
  ];

  // Menu selection.
  $options = [];
  $menu_storage = \Drupal::entityManager()
    ->getStorage('menu');
  foreach ($menu_storage
    ->loadMultiple() as $menu) {
    $options[$menu
      ->id()] = $menu
      ->label();
  }
  $form['menu'] = [
    '#type' => 'select',
    '#title' => $this
      ->t('Menu'),
    '#options' => $options,
    '#default_value' => $taxonomy_menu
      ->getMenu(),
  ];
  return $form;
}