function path_form_taxonomy_term_form_alter

Implements hook_form_FORM_ID_alter() for taxonomy_term_form().

File

drupal/core/modules/path/path.module, line 232
Enables users to rename URLs.

Code

function path_form_taxonomy_term_form_alter(&$form, $form_state) {

  // Make sure this does not show up on the delete confirmation form.
  if (empty($form_state['confirm_delete'])) {
    $term = $form_state['controller']
      ->getEntity();
    $path = $term
      ->id() ? Drupal::service('path.crud')
      ->load(array(
      'source' => 'taxonomy/term/' . $term
        ->id(),
    )) : array();
    if ($path === FALSE) {
      $path = array();
    }
    $path += array(
      'pid' => NULL,
      'source' => $term
        ->id() ? 'taxonomy/term/' . $term
        ->id() : NULL,
      'alias' => '',
      'langcode' => Language::LANGCODE_NOT_SPECIFIED,
    );
    $form['path'] = array(
      '#access' => user_access('create url aliases') || user_access('administer url aliases'),
      '#tree' => TRUE,
      '#element_validate' => array(
        'path_form_element_validate',
      ),
    );
    $form['path']['alias'] = array(
      '#type' => 'textfield',
      '#title' => t('URL alias'),
      '#default_value' => $path['alias'],
      '#maxlength' => 255,
      '#weight' => 0,
      '#description' => t("Optionally specify an alternative URL by which this term can be accessed. Use a relative path and don't add a trailing slash or the URL alias won't work."),
    );
    $form['path']['pid'] = array(
      '#type' => 'value',
      '#value' => $path['pid'],
    );
    $form['path']['source'] = array(
      '#type' => 'value',
      '#value' => $path['source'],
    );
    $form['path']['langcode'] = array(
      '#type' => 'value',
      '#value' => $path['langcode'],
    );
  }
}