public static function createAlias(ActiveRecord $Context, $handle = false)
 {
     if ($handle) {
         $handle = HandleBehavior::getUniqueHandle(__CLASS__, $handle);
     } else {
         $handle = HandleBehavior::generateRandomHandle(__CLASS__, 4);
     }
     return static::create(array('Handle' => $handle, 'Type' => 'Alias', 'Context' => $Context), !$Context->isPhantom);
 }
예제 #2
0
 public function save($deep = true)
 {
     // set code
     if (!$this->Code) {
         $this->Code = \HandleBehavior::getUniqueHandle($this, $this->Title, ['handleField' => 'Code']);
     }
     // call parent
     parent::save($deep);
 }
예제 #3
0
 public static function getFromHandle($handle, $autoCreate = true, $prefix = null)
 {
     $Tag = false;
     if (is_numeric($handle)) {
         $Tag = Tag::getByID($handle);
     }
     if (!$Tag) {
         $Tag = Tag::getByHandle($handle);
     }
     if (!$Tag) {
         $Tag = Tag::getByTitle($handle, $prefix);
     }
     if (!$Tag && $autoCreate) {
         $Tag = Tag::create(array('Title' => $handle, 'Handle' => HandleBehavior::getUniqueHandle(__CLASS__, $prefix ? "{$prefix}.{$handle}" : $handle)), true);
     }
     return $Tag;
 }