src/Model/Behavior/SlugBehavior.php
public function beforeSave(Event $event, Entity $entity, ArrayObject $options)
    {
        $onUpdate = $this->getConfig('onUpdate');
        if (!$entity->isNew() && !$onUpdate) {
            return;
        }

        $onDirty = $this->getConfig('onDirty');
        $field = $this->getConfig('field');
        if (!$onDirty
            && $entity->isDirty($field)
            && (!$entity->isNew() || (!empty($entity->{$field})))
        ) {
            return;
        }

        $separator = $this->getConfig('separator');
        if ($entity->isDirty($field) && !empty($entity->{$field})) {
            $slug = $this->slug($entity, $entity->{$field}, $separator);
            $entity->set($field, $slug);

            return;
        }

        $parts = $this->_getPartsFromEntity($entity);
        if (empty($parts)) {
            return;
        }

        $slug = $this->slug($entity, implode($separator, $parts), $separator);
        $entity->set($field, $slug);
    }
public function beforeSave(Event $event, Entity $entity, ArrayObject $options)
    {
        $onUpdate = $this->getConfig('onUpdate');
        if (!$entity->isNew() && !$onUpdate) {
            return;
        }

        $onDirty = $this->getConfig('onDirty');
        $field = $this->getConfig('field');
        if (!$onDirty
            && $entity->isDirty($field)
            && (!$entity->isNew() || (!empty($entity->{$field})))
        ) {
            return;
        }

        $separator = $this->getConfig('separator');
        if ($entity->isDirty($field) && !empty($entity->{$field})) {
            $slug = $this->slug($entity, $entity->{$field}, $separator);
            $entity->set($field, $slug);

            return;
        }

        $parts = $this->_getPartsFromEntity($entity);
        if (empty($parts)) {
            return;
        }

        $slug = $this->slug($entity, implode($separator, $parts), $separator);
        $entity->set($field, $slug);
    }
public function beforeSave ( Event $ event , Entity $ entity , ArrayObject $ options ) { $ onUpdate = $ this -> getConfig ( 'onUpdate' ) ; if ( ! $ entity -> isNew ( ) && ! $ onUpdate ) { return ; } $ onDirty = $ this -> getConfig ( 'onDirty' ) ; $ field = $ this -> getConfig ( 'field' ) ; if ( ! $ onDirty && $ entity -> isDirty ( $ field ) && ( ! $ entity -> isNew ( ) || ( ! empty ( $ entity -> { $ field } ) ) ) ) { return ; } $ separator = $ this -> getConfig ( 'separator' ) ; if ( $ entity -> isDirty ( $ field ) && ! empty ( $ entity -> { $ field } ) ) { $ slug = $ this -> slug ( $ entity , $ entity -> { $ field } , $ separator ) ; $ entity -> set ( $ field , $ slug ) ; return ; } $ parts = $ this -> _getPartsFromEntity ( $ entity ) ; if ( empty ( $ parts ) ) { return ; } $ slug = $ this -> slug ( $ entity , implode ( $ separator , $ parts ) , $ separator ) ; $ entity -> set ( $ field , $ slug ) ; }
Callback for Model.beforeSave event.

@param \Cake\Event\Event $event The afterSave event that was fired.
@param \Cake\ORM\Entity $entity The entity that was saved.
@param \ArrayObject $options Options.
@return void
Callback for Model . beforeSave event .