You are here

function taxonomy_unique_form_taxonomy_vocabulary_form_alter in Taxonomy unique 8

Same name and namespace in other branches
  1. 8.2 taxonomy_unique.module \taxonomy_unique_form_taxonomy_vocabulary_form_alter()

File

./taxonomy_unique.module, line 3

Code

function taxonomy_unique_form_taxonomy_vocabulary_form_alter(&$form, \Drupal\Core\Form\FormStateInterface $form_state, $form_id) {
  $form['unique_container'] = array(
    '#type' => 'fieldset',
    '#title' => t('Taxonomy unique'),
    '#collapsible' => TRUE,
    '#collapsed' => TRUE,
  );
  $unique_default_value = \Drupal::config('taxonomy_unique.settings')
    ->get($form_state
    ->getFormObject()
    ->getEntity()
    ->id());
  if (is_array($unique_default_value) || empty($unique_default_value)) {
    $unique_default_value = FALSE;
  }
  $form['unique_container']['unique'] = array(
    '#type' => 'checkbox',
    '#title' => t('Terms should be unique.'),
    '#default_value' => $unique_default_value,
  );
  $unique_message_default_value = \Drupal::config('taxonomy_unique.settings')
    ->get($form_state
    ->getFormObject()
    ->getEntity()
    ->id() . '_message');
  if (empty($unique_message_default_value)) {
    $unique_message_default_value = TAXONOMY_UNIQUE_DEFAULT_MESSAGE;
  }
  $form['unique_container']['unique_message'] = array(
    '#type' => 'textfield',
    '#title' => t('Message to show if term already exists'),
    '#description' => t('Placeholders: %term and %vocabulary'),
    '#default_value' => $unique_message_default_value,
  );
  $form['actions']['submit']['#submit'][] = 'taxonomy_unique_taxonomy_form_vocabulary_submit';
}