Commit 0a709b10 by Klimov Paul

Model parameter added to `yii\behaviors\Sluggable::uniqueSlugGenerator` callback

parent 0f4d8ac4
...@@ -85,14 +85,6 @@ class SluggableBehavior extends AttributeBehavior ...@@ -85,14 +85,6 @@ class SluggableBehavior extends AttributeBehavior
/** /**
* @var array configuration for slug uniqueness validator. Parameter 'class' may be omitted - by default * @var array configuration for slug uniqueness validator. Parameter 'class' may be omitted - by default
* [[UniqueValidator]] will be used. * [[UniqueValidator]] will be used.
* For example:
*
* ```php
* [
* 'filter' => ['type' => 1, 'status' => 2]
* ]
* ```
*
* @see UniqueValidator * @see UniqueValidator
*/ */
public $uniqueValidator = []; public $uniqueValidator = [];
...@@ -101,7 +93,7 @@ class SluggableBehavior extends AttributeBehavior ...@@ -101,7 +93,7 @@ class SluggableBehavior extends AttributeBehavior
* slug is not unique. This should be a PHP callable with following signature: * slug is not unique. This should be a PHP callable with following signature:
* *
* ```php * ```php
* function ($baseSlug, $iteration) * function ($baseSlug, $iteration, $model)
* { * {
* // return uniqueSlug * // return uniqueSlug
* } * }
...@@ -207,7 +199,7 @@ class SluggableBehavior extends AttributeBehavior ...@@ -207,7 +199,7 @@ class SluggableBehavior extends AttributeBehavior
private function generateUniqueSlug($baseSlug, $iteration) private function generateUniqueSlug($baseSlug, $iteration)
{ {
if (is_callable($this->uniqueSlugGenerator)) { if (is_callable($this->uniqueSlugGenerator)) {
return call_user_func($this->uniqueSlugGenerator, $baseSlug, $iteration); return call_user_func($this->uniqueSlugGenerator, $baseSlug, $iteration, $this->owner);
} else { } else {
return $baseSlug . '-' . ($iteration + 1); return $baseSlug . '-' . ($iteration + 1);
} }
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment