Пример #1
0
 function onBeforeWrite()
 {
     // If there is no URLSegment set, generate one from Title
     if ((!$this->URLSegment || $this->URLSegment == 'new-offer') && $this->Title != 'New Offer') {
         $this->URLSegment = @SiteTree::generateURLSegment($this->Name);
     } else {
         if ($this->isChanged('URLSegment')) {
             // Make sure the URLSegment is valid for use in a URL
             $segment = preg_replace('/[^A-Za-z0-9]+/', '-', $this->URLSegment);
             $segment = preg_replace('/-+/', '-', $segment);
             // If after sanitising there is no URLSegment, give it a reasonable default
             if (!$segment) {
                 $segment = "Offer-{$this->ID}";
             }
             $this->URLSegment = $segment;
         }
     }
     // Ensure that this object has a non-conflicting URLSegment value.
     $count = 2;
     while ($this->LookForExistingURLSegment($this->URLSegment)) {
         $this->URLSegment = preg_replace('/-[0-9]+$/', null, $this->URLSegment) . '-' . $count;
         $count++;
     }
     parent::onBeforeWrite();
 }
Пример #2
0
 /** 
  * Updates the group so the security section is also in sync with
  * the curent newsletters.
  */
 function onBeforeWrite()
 {
     if ($this->ID) {
         $group = $this->Group();
         if ($group->Title != "{$this->Title}") {
             $group->Title = _t('NewsletterType.MAILINGLIST', 'Mailing List:') . ' ' . $this->Title;
             // Otherwise the code would have mailing list in it too :-(
             $group->Code = SiteTree::generateURLSegment($this->Title);
             $group->write();
         }
     }
     parent::onBeforeWrite();
 }
Пример #3
0
 function onBeforeWrite()
 {
     parent::onBeforeWrite();
     if (isset($_POST['AlbumName'])) {
         $clean_name = SiteTree::generateURLSegment($_POST['AlbumName']);
         if ($this->FolderID) {
             $this->Folder()->setName($clean_name);
             $this->Folder()->Title = $clean_name;
             $this->Folder()->write();
         } else {
             $folder = Folder::findOrMake('image-gallery/' . $this->ImageGalleryPage()->RootFolder()->Name . '/' . $clean_name);
             $this->FolderID = $folder->ID;
         }
     }
 }
Пример #4
0
 /**
  * Overloaded to ensure the code is always descent.
  */
 public function setCode($val)
 {
     $this->setField("Code", SiteTree::generateURLSegment($val));
 }