src/Titon/Db/Behavior/SlugBehavior.php
public function preSave(Event $event, Query $query, $id, array &$data) {
        $config = $this->allConfig();

        if (empty($data) || empty($data[$config['field']]) || !empty($data[$config['slug']])) {
            return true;

        } else if ($query->getType() === Query::UPDATE && !$config['onUpdate']) {
            return true;
        }

        $slug = static::slugify($data[$config['field']]);

        // Leave a gap of 3 to account for the appended numbers
        if (mb_strlen($slug) > ($config['length'] - 3)) {
            $slug = mb_substr($slug, 0, ($config['length'] - 3));
        }

        if ($config['unique']) {
            $slug = $this->makeUnique($id, $slug);
        }

        $data[$config['slug']] = $slug;

        return true;
    }
public function preSave(Event $event, Query $query, $id, array &$data) {
        $config = $this->allConfig();

        if (empty($data) || empty($data[$config['field']]) || !empty($data[$config['slug']])) {
            return true;

        } else if ($query->getType() === Query::UPDATE && !$config['onUpdate']) {
            return true;
        }

        $slug = static::slugify($data[$config['field']]);

        // Leave a gap of 3 to account for the appended numbers
        if (mb_strlen($slug) > ($config['length'] - 3)) {
            $slug = mb_substr($slug, 0, ($config['length'] - 3));
        }

        if ($config['unique']) {
            $slug = $this->makeUnique($id, $slug);
        }

        $data[$config['slug']] = $slug;

        return true;
    }
public function preSave ( Event $ event , Query $ query , $ id , array & $ data ) { $ config = $ this -> allConfig ( ) ; if ( empty ( $ data ) || empty ( $ data [ $ config [ 'field' ] ] ) || ! empty ( $ data [ $ config [ 'slug' ] ] ) ) { return true ; } else if ( $ query -> getType ( ) === Query :: UPDATE && ! $ config [ 'onUpdate' ] ) { return true ; } $ slug = static :: slugify ( $ data [ $ config [ 'field' ] ] ) ; // Leave a gap of 3 to account for the appended numbers if ( mb_strlen ( $ slug ) > ( $ config [ 'length' ] - 3 ) ) { $ slug = mb_substr ( $ slug , 0 , ( $ config [ 'length' ] - 3 ) ) ; } if ( $ config [ 'unique' ] ) { $ slug = $ this -> makeUnique ( $ id , $ slug ) ; } $ data [ $ config [ 'slug' ] ] = $ slug ; return true ; }
Before a save occurs, generate a unique slug using another field as the base.
If no data exists, or the base doesn't exist, or the slug is already set, exit early.

@param \Titon\Event\Event $event
@param \Titon\Db\Query $query
@param int|int[] $id
@param array $data
@return bool
Before a save occurs generate a unique slug using another field as the base . If no data exists or the base doesn t exist or the slug is already set exit early .