You are here

function nodeorder_form_taxonomy_vocabulary_form_alter in Node Order 8

Implements hook_form_FORM_ID_alter() for taxonomy_form_vocabulary().

Related topics

File

./nodeorder.module, line 59
Nodeorder module.

Code

function nodeorder_form_taxonomy_vocabulary_form_alter(&$form, FormStateInterface $form_state) {
  if ($form_state
    ->get('confirm_delete')) {
    return;
  }

  /** @var \Drupal\nodeorder\NodeOrderManagerInterface $nodeorder_manager */
  $nodeorder_manager = \Drupal::service('nodeorder.manager');
  $vocabulary = $form_state
    ->getFormObject()
    ->getEntity();
  $form['nodeorder'] = [
    '#type' => 'fieldset',
    '#title' => t('Node Order'),
    '#weight' => 1,
  ];
  $form['nodeorder']['orderable'] = [
    '#type' => 'checkbox',
    '#title' => t('Orderable'),
    '#description' => t('If enabled, nodes may be ordered within this vocabulary.'),
    '#default_value' => $nodeorder_manager
      ->vocabularyIsOrderable($vocabulary
      ->id()),
  ];

  // Add a submit handler for saving the orderable settings.
  $form['actions']['submit']['#submit'][] = 'nodeorder_taxonomy_vocabulary_form_submit';
}