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 ...@@ -77,6 +77,11 @@ class SluggableBehavior extends AttributeBehavior
*/ */
public $value; 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. * @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 * If enabled behavior will validate slug uniqueness automatically. If validation fails it will attempt
* generating unique slug value from based one until success. * generating unique slug value from based one until success.
...@@ -133,10 +138,12 @@ class SluggableBehavior extends AttributeBehavior ...@@ -133,10 +138,12 @@ class SluggableBehavior extends AttributeBehavior
$owner = $this->owner; $owner = $this->owner;
if (!$owner->getIsNewRecord() && !empty($owner->{$this->slugAttribute})) { if (!$owner->getIsNewRecord() && !empty($owner->{$this->slugAttribute})) {
$isNewSlug = false; $isNewSlug = false;
foreach ($attributes as $attribute) { if(!$this->immutable){
if ($owner->isAttributeChanged($attribute)) { foreach ($attributes as $attribute) {
$isNewSlug = true; if ($owner->isAttributeChanged($attribute)) {
break; $isNewSlug = true;
break;
}
} }
} }
} }
......
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