There are a lot of configurable symbols in the pathauto settings (admin/config/search/path/settings).

However there aren't any settings for registered trademark (®) and trademark (™) symbols. I have a client that has a lot of node titles containing these characters, so I have patched the module to include them.

CommentFileSizeAuthor
#1 pathauto-trademark_symbols-2065369.patch1.02 KBzhuber
Support from Acquia helps fund testing for Drupal Acquia logo

Comments

zhuber’s picture

Status: Active » Needs review
FileSize
1.02 KB

I also added the copyright symbol, for good measure.

Dave Reid’s picture

You could just enable the 'Reduce to ASCII' option in Pathauto?

zhuber’s picture

Ahh...I didn't see that option.

Well, I think this is still a viable alternative if you didn't want to use the 'Reduce to ASCII' option.

enekoalonso’s picture

@Dave Reid, that solution does not work if you want to allow unicode URLs (for other languages).

In my opinion, Pathauto should allow to provide a custom list of symbols to be replaced, the same way it allows providing a list of words to be removed.

enekoalonso’s picture

Actually, it seems like there is a hook that can be used for this purpose (still would be nice to be able to do it through the UI):

/**
 * Alter the list of punctuation characters for Pathauto control.
 *
 * @param $punctuation
 *   An array of punctuation to be controlled by Pathauto during replacement
 *   keyed by punctuation name. Each punctuation record should be an array
 *   with the following key/value pairs:
 *   - value: The raw value of the punctuation mark.
 *   - name: The human-readable name of the punctuation mark. This must be
 *     translated using t() already.
 */
function hook_pathauto_punctuation_chars_alter(array &$punctuation) {
  // Add the trademark symbol.
  $punctuation['trademark'] = array('value' => '™', 'name' => t('Trademark symbol'));

  // Remove the dollar sign.
  unset($punctuation['dollar']);
}
joshuautley’s picture

Issue summary: View changes

I patched the production release for this module and while I see the options on settings the registration symbol is not being removed.

Per Dave's suggestion I do not see "Reduce to ASCII" option in settings. Is this only available in the dev release?

Thanks in advance for any input on this.

mibfire’s picture

joshuautley,

If you dont want to use unicode urls

then you have to turn off "Transliterate prior to creating alias" option, enable "Reduce strings to letters and numbers" option, and you dont need any patch for this or hook_pathauto_punctuation_chars_alter.

But there is a problem if your string contains characters with accent cos this case you have to use "Transliterate prior to creating alias" option and symbol will be converted with transliteration(for example: ™ -> TM) and after you cant remove this using "Punctuation" settings!

Solution:

/**
 * Implements hook_tokens_alter().
 */
function MYMODULE_tokens_alter(&$replacements, $context) {
	// Remove symbols from path generated with pathauto
	if (isset($context['options']['pathauto']) && $context['options']['pathauto']) {
		foreach($replacements as $key => $value) {
			$value = str_replace(array('®', '™'), array('', ''), $value);
			$replacements[$key] = $value;
		}
	}
}

If you want to use unicode urls

then you have to turn off "Transliterate prior to creating alias" and "Reduce strings to letters and numbers" options, and use https://www.drupal.org/node/2065369#comment-7755491 patch to remove the symbols.

JABurns103’s picture

The simplest solution is to select "Reduce strings to letters and numbers", and then you have to add the html character codes to the "Strings to Remove" box.

For example
Trademark ™ = & #8482;
Registered ® = & #174;
Copyright © = & #169;

*remove the space after the &

temkin’s picture

Status: Needs review » Closed (works as designed)

Please see a comment here.