You are here

function taxonomy_menu_custom_paths_form_taxonomy_vocabulary_form_alter in Taxonomy menu 8

Implements hook_form_FORM_ID_alter().

Adds Taxonomy menu custom path settings on a per-vocabulary basis.

See also

taxonomy_menu_custom_paths_vocabulary_validate()

File

taxonomy_menu_custom_paths/taxonomy_menu_custom_paths.module, line 24
Enables custom paths to Taxonomy Menu.

Code

function taxonomy_menu_custom_paths_form_taxonomy_vocabulary_form_alter(&$form, &$form_state) {

  // Get the vocabulary ID.
  $vid = $form_state['controller']
    ->getEntity()->vid ?: 0;
  $form['taxonomy_menu']['options_custom_path'] = array(
    '#type' => 'details',
    '#title' => t('Custom path options'),
    '#collapsed' => TRUE,
    '#description' => t("<strong>Warning:</strong> These settings uses custom paths that are not registered in Drupal by default. You need to register them <strong>before</strong> you create the taxonomy menu. For example, you could use a view in order to do that."),
    '#states' => array(
      'visible' => array(
        ':input[name="taxonomy_menu[path]"]' => array(
          'value' => 'taxonomy_menu_path_custom',
        ),
      ),
    ),
  );
  $form['taxonomy_menu']['options_custom_path']['custom_path_base'] = array(
    '#title' => t('Base path'),
    '#type' => 'textfield',
    '#default_value' => taxonomy_menu_variable_get('custom_path_base', $vid, ''),
    '#description' => t("Path 'base_path/%' must be available, where the argument is a Term ID (tid)."),
  );
  $form['taxonomy_menu']['options_custom_path']['custom_path_depth'] = array(
    '#title' => t('Depth modifier'),
    '#description' => t("Path 'base_path/%/%' must be available, where the arguments are respectively a Term ID (tid) and a Depth Modifier."),
    '#default_value' => taxonomy_menu_variable_get('custom_path_depth', $vid, ''),
    '#type' => 'textfield',
  );

  // Add a custom validation function.
  array_unshift($form['#validate'], 'taxonomy_menu_custom_paths_vocabulary_validate');
}