1 | <?php |
||
10 | class SluggableBehavior extends Behavior |
||
11 | { |
||
12 | |||
13 | /** |
||
14 | * Default config. |
||
15 | * |
||
16 | * @var array |
||
17 | */ |
||
18 | protected $_defaultConfig = [ |
||
19 | 'field' => 'title', |
||
20 | 'slug' => 'slug', |
||
21 | 'replacement' => '-', |
||
22 | ]; |
||
23 | |||
24 | /** |
||
25 | * Slug a field passed in the default config with its replacement. |
||
26 | * |
||
27 | * @param \Cake\ORM\Entity $entity The entity that is going to be updated. |
||
28 | * |
||
29 | * @return void |
||
30 | */ |
||
31 | public function slug(Entity $entity) |
||
32 | { |
||
33 | $config = $this->config(); |
||
34 | $value = $entity->get($config['field']); |
||
35 | $entity->set($config['slug'], strtolower(Inflector::slug($value, $config['replacement']))); |
||
36 | } |
||
37 | |||
38 | /** |
||
39 | * BeforeSave handle. |
||
40 | * |
||
41 | * @param \Cake\Event\Event $event The beforeSave event that was fired. |
||
42 | * @param \Cake\ORM\Entity $entity The entity that is going to be saved. |
||
43 | * |
||
44 | * @return void |
||
45 | */ |
||
46 | public function beforeSave(Event $event, Entity $entity) |
||
50 | |||
51 | /** |
||
52 | * Custom finder by slug. |
||
53 | * |
||
54 | * @param \Cake\ORM\Query $query The query finder. |
||
55 | * @param array $options The options passed in the query builder. |
||
56 | * |
||
57 | * @return \Cake\ORM\Query |
||
58 | */ |
||
59 | public function findSlug(Query $query, array $options) |
||
65 | } |
||
66 |
This check looks from parameters that have been defined for a function or method, but which are not used in the method body.