mirror of
https://github.com/yiisoft/yii2.git
synced 2025-11-17 23:09:10 +08:00
made it easier to extend SluggableBehavior slug generation
fixes #10118
This commit is contained in:
@@ -52,6 +52,7 @@ Yii Framework 2 Change Log
|
|||||||
- Enh #9901: Default `Cache.SerializerPermissions` configuration option for `HTMLPurifier` is set to `0775` (klimov-paul)
|
- Enh #9901: Default `Cache.SerializerPermissions` configuration option for `HTMLPurifier` is set to `0775` (klimov-paul)
|
||||||
- Enh #10056: Allowed any callable to be passed to `ActionColumn::$urlCreator` (freezy-sk)
|
- Enh #10056: Allowed any callable to be passed to `ActionColumn::$urlCreator` (freezy-sk)
|
||||||
- Enh #10061: `yii\helpers\BaseInflector::transliterate()` is now public. Introduced different levels of transliteration strictness (silverfire)
|
- Enh #10061: `yii\helpers\BaseInflector::transliterate()` is now public. Introduced different levels of transliteration strictness (silverfire)
|
||||||
|
- Enh #10118: Allow easy extension of slug generation in `yii\behaviors\SluggableBehavior` (cebe, hesna)
|
||||||
- Enh: Added last resort measure for `FileHelper::removeDirectory()` fail to unlink symlinks under Windows (samdark)
|
- Enh: Added last resort measure for `FileHelper::removeDirectory()` fail to unlink symlinks under Windows (samdark)
|
||||||
- Chg #9369: `Yii::$app->user->can()` now returns `false` instead of erroring in case `authManager` component is not configured (creocoder)
|
- Chg #9369: `Yii::$app->user->can()` now returns `false` instead of erroring in case `authManager` component is not configured (creocoder)
|
||||||
- Chg #9411: `DetailView` now automatically sets container tag ID in case it's not specified (samdark)
|
- Chg #9411: `DetailView` now automatically sets container tag ID in case it's not specified (samdark)
|
||||||
|
|||||||
@@ -154,7 +154,7 @@ class SluggableBehavior extends AttributeBehavior
|
|||||||
foreach ($attributes as $attribute) {
|
foreach ($attributes as $attribute) {
|
||||||
$slugParts[] = $owner->{$attribute};
|
$slugParts[] = $owner->{$attribute};
|
||||||
}
|
}
|
||||||
$slug = Inflector::slug(implode('-', $slugParts));
|
$slug = $this->generateSlug($slugParts);
|
||||||
} else {
|
} else {
|
||||||
$slug = $owner->{$this->slugAttribute};
|
$slug = $owner->{$this->slugAttribute};
|
||||||
}
|
}
|
||||||
@@ -173,6 +173,19 @@ class SluggableBehavior extends AttributeBehavior
|
|||||||
return $slug;
|
return $slug;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* This method is called by [[getValue]] to generate the slug.
|
||||||
|
* You may override it to customize slug generation.
|
||||||
|
* The default implementation calls [[\yii\helpers\Inflector::slug()]] on the input strings
|
||||||
|
* concatenated by dashes (`-`).
|
||||||
|
* @param array $slugParts an array of strings that should be concatenated and converted to generate the slug value.
|
||||||
|
* @return string the conversion result.
|
||||||
|
*/
|
||||||
|
protected function generateSlug($slugParts)
|
||||||
|
{
|
||||||
|
return Inflector::slug(implode('-', $slugParts));
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Checks if given slug value is unique.
|
* Checks if given slug value is unique.
|
||||||
* @param string $slug slug value
|
* @param string $slug slug value
|
||||||
|
|||||||
Reference in New Issue
Block a user