Commit 7a81fff9 by Alexander Kochetov

SluggableBehavior updated

parent 22b04c5c
...@@ -20,11 +20,9 @@ use yii\helpers\Inflector; ...@@ -20,11 +20,9 @@ use yii\helpers\Inflector;
class SluggableBehavior extends AttributeBehavior class SluggableBehavior extends AttributeBehavior
{ {
/** /**
* @inheritdoc * @var string
*/ */
public $attributes = [ public $slugAttribute = 'slug';
BaseActiveRecord::EVENT_BEFORE_VALIDATE => 'slug',
];
/** /**
* @var string * @var string
*/ */
...@@ -35,6 +33,12 @@ class SluggableBehavior extends AttributeBehavior ...@@ -35,6 +33,12 @@ class SluggableBehavior extends AttributeBehavior
*/ */
public function init() public function init()
{ {
parent::init();
if (empty($this->attributes)) {
$this->attributes = [BaseActiveRecord::EVENT_BEFORE_VALIDATE => $this->slugAttribute];
}
if ($this->attribute === null && $this->value === null) { if ($this->attribute === null && $this->value === null) {
throw new InvalidConfigException('Either "attribute" or "value" properties must be specified.'); throw new InvalidConfigException('Either "attribute" or "value" properties must be specified.');
} }
......
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