ENHANCEMENT: Macrons, umlauts, etc, are now transliterated when inserted into URLS. API CHANGE: Added Transliterator class, which uses iconv() or strtr() to convert characters with diacritical marks to their ASCII equivalents. API CHANGE: Added Extension hook updateURLSegment for SiteeTree. (from r104671)

git-svn-id: svn://svn.silverstripe.com/silverstripe/open/modules/sapphire/trunk@112365 467b73ca-7a2a-4603-9d3b-597d59a354a9
This commit is contained in:
Ingo Schommer 2010-10-15 00:39:36 +00:00
parent 2b65c57f7c
commit 3135c96fc9

View File

@ -1514,11 +1514,18 @@ class SiteTree extends DataObject implements PermissionProvider,i18nEntityProvid
/**
* Generate a URL segment based on the title provided.
*
* If {@link Extension}s wish to alter URL segment generation, they can do so by defining
* updateURLSegment(&$url, $title). $url will be passed by reference and should be modified.
* $title will contain the title that was originally used as the source of this generated URL.
* This lets decorators either start from scratch, or incrementally modify the generated URL.
*
* @param string $title Page title.
* @return string Generated url segment
*/
function generateURLSegment($title){
$t = strtolower($title);
$t = mb_strtolower($title);
$t = Object::create('Transliterator')->toASCII($title);
$t = str_replace('&','-and-',$t);
$t = str_replace('&','-and-',$t);
$t = ereg_replace('[^A-Za-z0-9]+','-',$t);
@ -1526,7 +1533,12 @@ class SiteTree extends DataObject implements PermissionProvider,i18nEntityProvid
if(!$t || $t == '-' || $t == '-1') {
$t = "page-$this->ID";
}
return trim($t, '-');
$t = trim($t, '-');
// Hook for decorators
$this->extend('updateURLSegment', $t, $title);
return $t;
}
/**