public function VocabularyFormController::form

Overrides Drupal\Core\Entity\EntityFormController::form().

Overrides EntityFormController::form

File

drupal/core/modules/taxonomy/lib/Drupal/taxonomy/VocabularyFormController.php, line 21
Definition of Drupal\taxonomy\VocabularyFormController.

Class

VocabularyFormController
Base form controller for vocabulary edit forms.

Namespace

Drupal\taxonomy

Code

public function form(array $form, array &$form_state, EntityInterface $vocabulary) {

  // Check whether we need a deletion confirmation form.
  if (isset($form_state['confirm_delete']) && isset($form_state['values']['vid'])) {
    return taxonomy_vocabulary_confirm_delete($form, $form_state, $form_state['values']['vid']);
  }
  $form['name'] = array(
    '#type' => 'textfield',
    '#title' => t('Name'),
    '#default_value' => $vocabulary->name,
    '#maxlength' => 255,
    '#required' => TRUE,
  );
  $form['machine_name'] = array(
    '#type' => 'machine_name',
    '#default_value' => $vocabulary->machine_name,
    '#maxlength' => 255,
    '#machine_name' => array(
      'exists' => 'taxonomy_vocabulary_machine_name_load',
      'source' => array(
        'name',
      ),
    ),
  );
  $form['description'] = array(
    '#type' => 'textfield',
    '#title' => t('Description'),
    '#default_value' => $vocabulary->description,
  );

  // $form['langcode'] is not wrapped in an if (module_exists('language'))
  // check because the language_select form element works also without the
  // language module being installed.
  // http://drupal.org/node/1749954 documents the new element.
  $form['langcode'] = array(
    '#type' => 'language_select',
    '#title' => t('Vocabulary language'),
    '#languages' => LANGUAGE_ALL,
    '#default_value' => $vocabulary->langcode,
  );
  if (module_exists('language')) {
    $form['default_terms_language'] = array(
      '#type' => 'details',
      '#title' => t('Terms language'),
    );
    $form['default_terms_language']['default_language'] = array(
      '#type' => 'language_configuration',
      '#entity_information' => array(
        'entity_type' => 'taxonomy_term',
        'bundle' => $vocabulary->machine_name,
      ),
      '#default_value' => language_get_default_configuration('taxonomy_term', $vocabulary->machine_name),
    );
  }

  // Set the hierarchy to "multiple parents" by default. This simplifies the
  // vocabulary form and standardizes the term form.
  $form['hierarchy'] = array(
    '#type' => 'value',
    '#value' => '0',
  );
  if (isset($vocabulary->vid)) {
    $form['vid'] = array(
      '#type' => 'value',
      '#value' => $vocabulary->vid,
    );
  }
  return parent::form($form, $form_state, $vocabulary);
}