Permalink
Browse files

ENHANCEMENT Using new URLPathFilter API in SiteTree->generateURLSegme…

…nt(), allowing customisation of URL filtering and transliteration
  • Loading branch information...
1 parent fc400d9 commit 81aeb8d3785fa99f74e52850ca1fadadb1e6adde @chillu chillu committed Nov 14, 2011
Showing with 7 additions and 12 deletions.
  1. +7 −12 code/model/SiteTree.php
View
@@ -1385,15 +1385,10 @@ protected function onBeforeWrite() {
if((!$this->URLSegment || $this->URLSegment == 'new-page') && $this->Title) {
$this->URLSegment = $this->generateURLSegment($this->Title);
} else if($this->isChanged('URLSegment')) {
- // Make sure the URLSegment is valid for use in a URL
- $segment = ereg_replace('[^A-Za-z0-9]+','-',$this->URLSegment);
- $segment = ereg_replace('-+','-',$segment);
-
+ $filter = Object::create('URLPathFilter');
+ $this->URLSegment = $filter->filter($this->URLSegment);
// If after sanitising there is no URLSegment, give it a reasonable default
- if(!$segment) {
- $segment = "page-$this->ID";
- }
- $this->URLSegment = $segment;
+ if(!$this->URLSegment) $this->URLSegment = "page-$this->ID";
}
// Ensure that this object has a non-conflicting URLSegment value.
@@ -1583,11 +1578,11 @@ public function validURLSegment() {
* @return string Generated url segment
*/
function generateURLSegment($title){
- $t = Convert::raw2url($title);
+ $filter = Object::create('URLPathFilter');
+ $t = $filter->filter($title);
- if(!$t || $t == '-' || $t == '-1') {
- $t = "page-$this->ID";
- }
+ // Fallback to generic page name if path is empty (= no valid, convertable characters)
+ if(!$t || $t == '-' || $t == '-1') $t = "page-$this->ID";
// Hook for extensions
$this->extend('updateURLSegment', $t, $title);

0 comments on commit 81aeb8d

Please sign in to comment.