<commit_before><?php
class SluggableBehavior extends ModelBehavior {
    
    public function setup(Model $Model, $settings = array()) {
        if (!isset($this->settings[$Model->alias])) {
            $this->settings[$Model->alias] = array(
                'titleColumn' => 'title',
                'slugColumn' => 'slug',
                'replacement' => '-'
            );
        }
        $this->settings[$Model->alias] = array_merge($this->settings[$Model->alias], $settings);
    }
    
    public function beforeSave(Model $Model, $options = array()) {
        $titleColumn = $this->settings[$Model->alias]['titleColumn'];
        $slugColumn = $this->settings[$Model->alias]['slugColumn'];
        $replacement = $this->settings[$Model->alias]['replacement'];
        
        if (isset($Model->data[$Model->alias][$titleColumn])) {
            $Model->data[$Model->alias][$slugColumn] = Inflector::slug(strtolower($Model->data[$Model->alias][$titleColumn]), $replacement);
        }
        return true;
    }
}<commit_msg>Make sluggable behavior use model's displayField<commit_after><?php
class SluggableBehavior extends ModelBehavior {
    
    public function setup(Model $Model, $settings = array()) {
        if (!isset($this->settings[$Model->alias])) {
            $this->settings[$Model->alias] = array(
                'slugColumn' => 'slug'
            );
        }
        $this->settings[$Model->alias] = array_merge($this->settings[$Model->alias], $settings);
    }
    
    public function beforeSave(Model $Model, $options = array()) {
        $displayField = $Model->displayField;
        $slugColumn = $this->settings[$Model->alias]['slugColumn'];
        
        if (isset($Model->data[$Model->alias][$displayField])) {
            $Model->data[$Model->alias][$slugColumn] = Inflector::slug(strtolower($Model->data[$Model->alias][$displayField]), '-');
        }
        return true;
    }
}
{'fraction_non_alphanumeric': 0.18106139438085328, 'fraction_numerical': 0.0, 'mean_word_length': 2.800395256916996, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 44, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4106147', 'n_tokens_mistral': 528, 'n_tokens_neox': 536, 'n_words': 83}