This repository has been archived by the owner on Dec 3, 2018. It is now read-only.
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #106 from davidnewcomb/custom_sluggable_behavior
add Podium.slugGenerator to specify your own slugGenerator
- Loading branch information
Showing
6 changed files
with
84 additions
and
8 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
<?php | ||
|
||
namespace bizley\podium\slugs; | ||
|
||
use yii\behaviors\SluggableBehavior; | ||
|
||
/** | ||
* Slug generator behavior | ||
* | ||
* To implement your own slug generators create a class that extends | ||
* PodiumSluggableBehavior and override SluggableBehavior::generateSlug(). | ||
* | ||
* For example add to configuration: | ||
* | ||
* ``` | ||
* 'modules' => [ | ||
* 'podium' => [ | ||
* 'class' => 'bizley\podium\Podium', | ||
* 'slugGenerator' => MyPodiumSlugGenerator::className(), | ||
* ``` | ||
* | ||
* and then create a class: | ||
* | ||
* ``` | ||
* class MyPodiumSlugGenerator extends PodiumSluggableBehavior | ||
* { | ||
* | ||
* protected function generateSlug($slugParts) | ||
* { | ||
* if ($this->type == self::THREAD) { | ||
* $s = substr($slugParts[0], 1); | ||
* return str_replace("/", "-", $s); | ||
* } else { | ||
* return parent::generateSlug ( $slugParts ); | ||
* } | ||
* } | ||
* } | ||
* ``` | ||
* | ||
* @author David Newcomb <david.newcomb@bigsoft.co.uk> | ||
* @since 0.8 | ||
*/ | ||
|
||
class PodiumSluggableBehavior extends SluggableBehavior | ||
{ | ||
|
||
const CATEGORY = "category"; | ||
const FORUM = "forum"; | ||
const THREAD = "thread"; | ||
const USER = "user"; | ||
|
||
/** | ||
* @var string Use PodiumSluggableBehavior::CATEGORY,... | ||
*/ | ||
public $type; | ||
|
||
} |