Commit 58516ae8 by Qiang Xue

Fixes #6434: Added `yii\behaviors\SluggableBehavior::immutable` to support…

Fixes #6434: Added `yii\behaviors\SluggableBehavior::immutable` to support keeping the generated slug unchanged
parent 4dd15a66
...@@ -5,9 +5,9 @@ Yii Framework 2 Change Log ...@@ -5,9 +5,9 @@ Yii Framework 2 Change Log
----------------------- -----------------------
- Bug #6404: advanced application template `Alert` widget was generating duplicate IDs in case of multiple flashes (SDKiller) - Bug #6404: advanced application template `Alert` widget was generating duplicate IDs in case of multiple flashes (SDKiller)
- Enh #6434: Added `yii\behaviors\SluggableBehavior::immutable` to support keeping the generated slug unchanged (trntv)
- Enh #6467: `ActiveForm` will scroll to the nearest visible element when the first error input is hidden (newartix) - Enh #6467: `ActiveForm` will scroll to the nearest visible element when the first error input is hidden (newartix)
2.0.1 December 07, 2014 2.0.1 December 07, 2014
----------------------- -----------------------
......
...@@ -77,8 +77,9 @@ class SluggableBehavior extends AttributeBehavior ...@@ -77,8 +77,9 @@ class SluggableBehavior extends AttributeBehavior
*/ */
public $value; public $value;
/** /**
* @var boolean whether to generate new slug if it already filled but attribute was changed. * @var boolean whether to generate a new slug if it has already been generated before.
* If enabled behavior will not generate new slug after attributes in model was changed. * If true, the behavior will not generate a new slug even if [[attribute]] is changed.
* @since 2.0.2
*/ */
public $immutable = false; public $immutable = false;
/** /**
...@@ -138,7 +139,7 @@ class SluggableBehavior extends AttributeBehavior ...@@ -138,7 +139,7 @@ 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;
if(!$this->immutable){ if (!$this->immutable) {
foreach ($attributes as $attribute) { foreach ($attributes as $attribute) {
if ($owner->isAttributeChanged($attribute)) { if ($owner->isAttributeChanged($attribute)) {
$isNewSlug = true; $isNewSlug = true;
......
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