| 1 |  |  | <?php | 
            
                                                                                                            
                            
            
                                    
            
            
                | 2 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 3 |  |  | namespace app\modules\page; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 4 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 5 |  |  | use app; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 6 |  |  | use app\modules\event\interfaces\EventInterface; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 7 |  |  | use app\modules\floatPanel\widgets\FloatingPanel; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 8 |  |  | use kartik\icons\Icon; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 9 |  |  | use Yii; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 10 |  |  | use yii\base\Event; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 11 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 12 |  |  | /** | 
            
                                                                                                            
                            
            
                                    
            
            
                | 13 |  |  |  * Base configuration module for DotPlant2 CMS | 
            
                                                                                                            
                            
            
                                    
            
            
                | 14 |  |  |  * @package app\modules\page | 
            
                                                                                                            
                            
            
                                    
            
            
                | 15 |  |  |  */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 16 |  |  | class PageModule extends app\components\BaseModule implements EventInterface | 
            
                                                                                                            
                            
            
                                    
            
            
                | 17 |  |  | { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 18 |  |  |     const BACKEND_PAGE_GRID = 'pageGrid'; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 19 |  |  |     /** | 
            
                                                                                                            
                            
            
                                    
            
            
                | 20 |  |  |      * @var int minimum pages per list to show | 
            
                                                                                                            
                            
            
                                    
            
            
                | 21 |  |  |      */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 22 |  |  |     public $minPagesPerList = 1; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 23 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 24 |  |  |     /** | 
            
                                                                                                            
                            
            
                                    
            
            
                | 25 |  |  |      * @var int maximum pages per list to show | 
            
                                                                                                            
                            
            
                                    
            
            
                | 26 |  |  |      */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 27 |  |  |     public $maxPagesPerList = 50; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 28 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 29 |  |  |     /** | 
            
                                                                                                            
                            
            
                                    
            
            
                | 30 |  |  |      * @var int pages per list to show | 
            
                                                                                                            
                            
            
                                    
            
            
                | 31 |  |  |      */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 32 |  |  |     public $pagesPerList = 10; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 33 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 34 |  |  |     /** | 
            
                                                                                                            
                            
            
                                    
            
            
                | 35 |  |  |      * @var int How much pages to show on search results page | 
            
                                                                                                            
                            
            
                                    
            
            
                | 36 |  |  |      */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 37 |  |  |     public $searchResultsLimit = 10; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 38 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 39 |  |  |     public $controllerMap = [ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 40 |  |  |         'backend' => 'app\modules\page\backend\PageController', | 
            
                                                                                                            
                            
            
                                    
            
            
                | 41 |  |  |     ]; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 42 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 43 |  |  |     /** | 
            
                                                                                                            
                            
            
                                    
            
            
                | 44 |  |  |      * @inheritdoc | 
            
                                                                                                            
                            
            
                                    
            
            
                | 45 |  |  |      */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 46 |  |  |     public function behaviors() | 
            
                                                                                                            
                            
            
                                    
            
            
                | 47 |  |  |     { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 48 |  |  |         return [ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 49 |  |  |             'configurableModule' => [ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 50 |  |  |                 'class' => 'app\modules\config\behaviors\ConfigurableModuleBehavior', | 
            
                                                                                                            
                            
            
                                    
            
            
                | 51 |  |  |                 'configurationView' => '@app/modules/page/views/configurable/_config', | 
            
                                                                                                            
                            
            
                                    
            
            
                | 52 |  |  |                 'configurableModel' => 'app\modules\page\models\ConfigConfigurationModel', | 
            
                                                                                                            
                            
            
                                    
            
            
                | 53 |  |  |             ] | 
            
                                                                                                            
                            
            
                                    
            
            
                | 54 |  |  |         ]; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 55 |  |  |     } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 56 |  |  |  | 
            
                                                                                                            
                                                                
            
                                    
            
            
                | 57 |  |  |     /** @inheritdoc */ | 
            
                                                                        
                            
            
                                    
            
            
                | 58 |  |  |     public function getBackendGrids() | 
            
                                                                        
                            
            
                                    
            
            
                | 59 |  |  |     { | 
            
                                                                        
                            
            
                                    
            
            
                | 60 |  |  |         return [ | 
            
                                                                        
                            
            
                                    
            
            
                | 61 |  |  |             [ | 
            
                                                                        
                            
            
                                    
            
            
                | 62 |  |  |                 'defaultValue' => app\backend\BackendModule::BACKEND_GRID_ONE_TO_ONE, | 
            
                                                                        
                            
            
                                    
            
            
                | 63 |  |  |                 'key' => self::BACKEND_PAGE_GRID, | 
            
                                                                        
                            
            
                                    
            
            
                | 64 |  |  |                 'label' => Yii::t('app', 'Page edit'), | 
            
                                                                        
                            
            
                                    
            
            
                | 65 |  |  |             ], | 
            
                                                                        
                            
            
                                    
            
            
                | 66 |  |  |         ]; | 
            
                                                                        
                            
            
                                    
            
            
                | 67 |  |  |     } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 68 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 69 |  |  |     /** | 
            
                                                                                                            
                            
            
                                    
            
            
                | 70 |  |  |      * @return void | 
            
                                                                                                            
                            
            
                                    
            
            
                | 71 |  |  |      */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 72 |  |  |     public static function attachEventsHandlers() | 
                            
                    |  |  |  | 
                                                                                        
                                                                                     | 
            
                                                                                                            
                            
            
                                    
            
            
                | 73 |  |  |     { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 74 |  |  |         Event::on( | 
            
                                                                                                            
                            
            
                                    
            
            
                | 75 |  |  |             FloatingPanel::class, | 
            
                                                                                                            
                            
            
                                    
            
            
                | 76 |  |  |             FloatingPanel::EVENT_BEFORE_RENDER, | 
            
                                                                                                            
                            
            
                                    
            
            
                | 77 |  |  |             function($event) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 78 |  |  |                 if (in_array(\Yii::$app->requestedRoute, ['/page/page/show', '/page/page/list'])) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 79 |  |  |                     if (isset($_GET['id'])) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 80 |  |  |                         $page = app\modules\page\models\Page::findById($_GET['id']); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 81 |  |  |                         $event->items[] = [ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 82 |  |  |                             'label' => Icon::show('pencil') . ' ' . Yii::t('app', 'Edit page'), | 
            
                                                                                                            
                            
            
                                    
            
            
                | 83 |  |  |                             'url' => [ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 84 |  |  |                                 '/page/backend/edit', | 
            
                                                                                                            
                            
            
                                    
            
            
                | 85 |  |  |                                 'id' => $page->id, | 
            
                                                                                                            
                            
            
                                    
            
            
                | 86 |  |  |                                 'parent_id' =>$page->parent_id, | 
            
                                                                                                            
                            
            
                                    
            
            
                | 87 |  |  |                             ], | 
            
                                                                                                            
                            
            
                                    
            
            
                | 88 |  |  |                         ]; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 89 |  |  |                         if (Yii::$app->requestedRoute == "/page/page/list") { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 90 |  |  |                             $event->items[] = [ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 91 |  |  |                                 'label' => Icon::show('plus') .  Yii::t('app', 'Add child page'), | 
            
                                                                                                            
                            
            
                                    
            
            
                | 92 |  |  |                                 'url' => [ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 93 |  |  |                                     '/page/backend/edit', | 
            
                                                                                                            
                            
            
                                    
            
            
                | 94 |  |  |                                     'parent_id' => $page->id | 
            
                                                                                                            
                            
            
                                    
            
            
                | 95 |  |  |                                 ] | 
            
                                                                                                            
                            
            
                                    
            
            
                | 96 |  |  |                             ]; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 97 |  |  |                         } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 98 |  |  |                     } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 99 |  |  |                 } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 100 |  |  |             } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 101 |  |  |         ); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 102 |  |  |     } | 
            
                                                                                                            
                                                                
            
                                    
            
            
                | 103 |  |  | } | 
            
                                                        
            
                                    
            
            
                | 104 |  |  |  | 
            
                        
Instead of super-globals, we recommend to explicitly inject the dependencies of your class. This makes your code less dependent on global state and it becomes generally more testable: