| Total Complexity | 6 |
| Total Lines | 67 |
| Duplicated Lines | 0 % |
| Coverage | 86.36% |
| Changes | 0 | ||
| 1 | <?php |
||
| 14 | class CpEditSegment extends Plugin |
||
| 15 | { |
||
| 16 | public static $plugin; |
||
| 17 | |||
| 18 | public $hasCpSettings = true; |
||
| 19 | public $cpTrigger; |
||
| 20 | |||
| 21 | /** |
||
| 22 | * @inheritdoc |
||
| 23 | */ |
||
| 24 | 5 | public function init() |
|
| 25 | { |
||
| 26 | 5 | parent::init(); |
|
| 27 | |||
| 28 | 5 | self::$plugin = $this; |
|
| 29 | |||
| 30 | 5 | $this->cpTrigger = \Craft::$app->getConfig()->getGeneral()->cpTrigger; |
|
| 31 | |||
| 32 | Event::on(UrlManager::class, UrlManager::EVENT_REGISTER_SITE_URL_RULES, function(RegisterUrlRulesEvent $event) |
||
| 33 | { |
||
| 34 | $event->rules = \array_merge($event->rules, $this->getSiteUrlRules()); |
||
| 35 | 5 | }); |
|
| 36 | 5 | } |
|
| 37 | |||
| 38 | /** |
||
| 39 | * @param string|null $trigger |
||
| 40 | * @return array |
||
| 41 | */ |
||
| 42 | 2 | public function getSiteUrlRules() |
|
| 43 | { |
||
| 44 | 2 | $rules = []; |
|
| 45 | 2 | $trigger = $this->getSettings()->trigger; |
|
| 46 | |||
| 47 | 2 | $rules["<elementUri:.*>/$trigger"] = 'cpeditsegment/cp-edit-segment/redirect'; |
|
| 48 | |||
| 49 | 2 | if ($trigger !== $this->cpTrigger) { |
|
| 50 | 1 | $rules[$trigger] = 'cpeditsegment/cp-edit-segment/redirect'; |
|
| 51 | } |
||
| 52 | |||
| 53 | 2 | return $rules; |
|
| 54 | } |
||
| 55 | |||
| 56 | /** |
||
| 57 | * @return mixed|\yii\web\Response |
||
| 58 | */ |
||
| 59 | public function getSettingsResponse() |
||
| 62 | } |
||
| 63 | |||
| 64 | /** |
||
| 65 | * @return Settings |
||
| 66 | */ |
||
| 67 | 3 | public function getSettings() |
|
| 68 | { |
||
| 69 | 3 | return parent::getSettings(); |
|
| 70 | } |
||
| 71 | |||
| 72 | /** |
||
| 73 | * @return Settings |
||
| 74 | */ |
||
| 75 | 3 | protected function createSettingsModel() |
|
| 81 | } |
||
| 82 | } |