Need the ability here to have a settings page like pathauto where we can set the Separator and Character case at very minimum.

For now I have hacked the stable release with...

Old

$item['link_path'] = token_replace($menu_token_enabled[$mlid], array('global'));

New

$item['link_path'] = strtolower(str_replace(' ', '-', token_replace($menu_token_enabled[$mlid], array('global'))));

At least I can use this now, but I assume most people will be wanting to use this module in tandem with pathauto and need the ability to 'match' the token that are generated off that.

CommentFileSizeAuthor
#2 1180498_menu_token_pathauto.patch648 bytescweagans

Comments

roam2345’s picture

Here is that magic function off pathauto... I don't know if it would be wise to make this module dependent on it as I assume most people would be using that then you can simply just use the function and not have to worry about keeping the two in sync... duno what yourr thought are.

/**
 * Clean up a string segment to be used in an URL alias.
 *
 * Performs the following possible alterations:
 * - Process the string through the transliteration module.
 * - Replace or remove punctuation with the separator character.
 * - Remove back-slashes.
 * - Replace non-ascii and non-numeric characters with the separator.
 * - Remove common words.
 * - Replace whitespace with the separator character.
 * - Trim duplicate, leading, and trailing separators.
 * - Convert to lower-case.
 * - Shorten to a desired length and logical position based on word boundaries.
 *
 * This function should *not* be called on URL alias or path strings because it
 * is assumed that they are already clean.
 *
 * @param $string
 *   A string to clean.
 * @return
 *   The cleaned string.
 */
function pathauto_cleanstring($string) {
  $output = $string;

  // Remove all HTML tags from the string.
  $output = strip_tags($string);

  // Optionally transliterate (by running through the Transliteration module)
  if (variable_get('pathauto_transliterate', FALSE)) {
    if (module_exists('transliteration')) {
      $output = transliteration_get($output);
    }
    else {
      drupal_set_message(t('Pathauto could not transliterate the path, as the Transliteration module has been disabled.'), 'error');
    }
  }

  // Replace or drop punctuation based on user settings
  $separator = variable_get('pathauto_separator', '-');
  $punctuation = pathauto_punctuation_chars();
  foreach ($punctuation as $name => $details) {
    $action = variable_get('pathauto_punctuation_' . $name, PATHAUTO_PUNCTUATION_REMOVE);
    if ($action != PATHAUTO_PUNCTUATION_DO_NOTHING) {
      // Slightly tricky inline if which either replaces with the separator or nothing
      $output = str_replace($details['value'], ($action ? $separator : ''), $output);
    }
  }

  // Reduce strings to letters and numbers
  if (variable_get('pathauto_reduce_ascii', FALSE)) {
    $pattern = '/[^a-zA-Z0-9\/]+/';
    $output = preg_replace($pattern, $separator, $output);
  }

  // Calculate and statically cache the ignored words regex expression.
  $ignore_words_regex = &drupal_static('pathauto_cleanstring:ignore_words_regex');
  if (!isset($ignore_words_regex)) {
    $ignore_words = variable_get('pathauto_ignore_words', PATHAUTO_IGNORE_WORDS);
    $ignore_words_regex = preg_replace(array('/^[,\s]+|[,\s]+$/', '/[,\s]+/'), array('', '\b|\b'), $ignore_words);
    if ($ignore_words_regex) {
      $ignore_words_regex = '\b' . $ignore_words_regex . '\b';
    }
  }

  // Get rid of words that are on the ignore list
  if ($ignore_words_regex) {
    if (function_exists('mb_eregi_replace')) {
      $words_removed = mb_eregi_replace($ignore_words_regex, '', $output);
    }
    else {
      $words_removed = preg_replace("/$ignore_words_regex/i", '', $output);
    }
    if (drupal_strlen(trim($words_removed)) > 0) {
      $output = $words_removed;
    }
  }

  // Always replace whitespace with the separator.
  $output = preg_replace('/\s+/', $separator, $output);

  // Trim duplicates and remove trailing and leading separators.
  $output = _pathauto_clean_separators($output);

  // Optionally convert to lower case.
  if (variable_get('pathauto_case', PATHAUTO_CASE_LOWER)) {
    $output = drupal_strtolower($output);
  }

  // Shorten to a logical place based on word boundaries.
  $maxlength = min(variable_get('pathauto_max_component_length', 100), _pathauto_get_schema_alias_maxlength());
  $output = truncate_utf8($output, $maxlength, TRUE);

  return $output;
}
cweagans’s picture

Status: Active » Needs review
StatusFileSize
new648 bytes

So maybe something like this?

cweagans’s picture

Eh, no. That's not going to work, actually. However, have you taken a look at #1320842: Work with the Path Auto module?

develcuy’s picture

Status: Needs review » Closed (works as designed)

Menu token module is not intended to filter paths, it just replaces tokens within a path and looks for the corresponding path alias to use it if that is the case.