Commit 4dd15a66 by Eugine Terentev Committed by Qiang Xue

Adds immutable property fit SluggableBehavior fixes #6430

parent 9f20c06d
......@@ -77,6 +77,11 @@ class SluggableBehavior extends AttributeBehavior
*/
public $value;
/**
* @var boolean whether to generate new slug if it already filled but attribute was changed.
* If enabled behavior will not generate new slug after attributes in model was changed.
*/
public $immutable = false;
/**
* @var boolean whether to ensure generated slug value to be unique among owner class records.
* If enabled behavior will validate slug uniqueness automatically. If validation fails it will attempt
* generating unique slug value from based one until success.
......@@ -133,6 +138,7 @@ class SluggableBehavior extends AttributeBehavior
$owner = $this->owner;
if (!$owner->getIsNewRecord() && !empty($owner->{$this->slugAttribute})) {
$isNewSlug = false;
if(!$this->immutable){
foreach ($attributes as $attribute) {
if ($owner->isAttributeChanged($attribute)) {
$isNewSlug = true;
......@@ -140,6 +146,7 @@ class SluggableBehavior extends AttributeBehavior
}
}
}
}
if ($isNewSlug) {
$slugParts = [];
......
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