/**
* @inheritdoc
*/
protected function getValue($event)
{
/* @var $owner ActiveRecord */
$owner = $this->owner;
if (!empty($owner->{$this->slugAttribute}) && !$this->slugIsEmpty && $this->immutable) {
$slug = $owner->{$this->slugAttribute};
} else {
if ($owner->getIsNewRecord()) {
$this->slugIsEmpty = true;
}
if ($this->attribute !== null) {
$attributes = $this->attribute;
$slugParts = array_map(function ($attribute) {
return ArrayHelper::getValue($this->owner, $attribute);
}, $attributes);
$slug = $this->slugify(implode($this->replacement, $slugParts), $this->replacement, $this->lowercase);
if (!$owner->getIsNewRecord() && $this->slugIsEmpty) {
$owner->{$this->slugAttribute} = $slug;
$owner->save(false, [$this->slugAttribute]);
}
} else {
$slug = parent::getValue($event);
}
}
if ($this->ensureUnique) {
$baseSlug = $slug;
$iteration = 0;
while (!$this->validateSlug($slug)) {
$iteration++;
$slug = $this->generateUniqueSlug($baseSlug, $iteration);
}
}
return $slug;
}