1313use yii \base \Event ;
1414use yii \base \Widget ;
1515use yii \helpers \Html ;
16+ use dmstr \modules \prototype \models \Html as HtmlModel ;
1617
18+ /**
19+ *
20+ * @property array $menuItems
21+ * @property string|null $key
22+ * @property string $moduleId
23+ * @property bool $enableFlash
24+ * @property bool $registerMenuItems
25+ * @property bool $renderEmpty
26+ * @property Html $_model
27+ */
1728class HtmlWidget extends Widget
1829{
1930 const SETTINGS_SECTION = 'app.html ' ;
2031 const ACCESS_ROLE = 'Editor ' ;
2132
2233 public $ key = null ;
2334 public $ enableFlash = false ;
35+ public $ moduleId = 'prototype ' ;
2436 public $ registerMenuItems = true ;
2537 public $ renderEmpty = true ;
2638
@@ -29,22 +41,22 @@ class HtmlWidget extends Widget
2941 public function init ()
3042 {
3143 parent ::init ();
32- $ this ->_model = \ dmstr \ modules \ prototype \ models \Twig ::findOne (['key ' => $ this ->generateKey ()]);
44+ $ this ->_model = HtmlModel ::findOne (['key ' => $ this ->generateKey ()]);
3345 if ($ this ->registerMenuItems ) {
3446 \Yii::$ app ->trigger ('registerMenuItems ' , new Event (['sender ' => $ this ]));
3547 }
3648 }
3749
3850 public function run ()
3951 {
40- $ this ->_model = $ model = \ dmstr \ modules \ prototype \ models \Html ::findOne (['key ' => $ this ->generateKey ()]);
52+ $ this ->_model = $ model = HtmlModel ::findOne (['key ' => $ this ->generateKey ()]);
4153 $ html = '' ;
4254
4355 if (\Yii::$ app ->user ->can (self ::ACCESS_ROLE )) {
44- $ link = ( $ model) ? $ this ->generateEditLink ($ model ->id ) : $ this ->generateCreateLink ();
56+ $ link = $ model ? $ this ->generateEditLink ($ model ->id ) : $ this ->generateCreateLink ();
4557 if ($ this ->enableFlash ) {
4658 \Yii::$ app ->session ->addFlash (
47- ( $ model) ? 'success ' : 'info ' ,
59+ $ model ? 'success ' : 'info ' ,
4860 "Edit contents in {$ link }, key: <code> {$ this ->generateKey ()}</code> "
4961 );
5062 }
@@ -67,7 +79,7 @@ public function getMenuItems()
6779 [
6880 'label ' => ($ this ->_model ? FA ::icon (FA ::_EDIT ) :
6981 FA ::icon (FA ::_PLUS_SQUARE )).' <b> ' .$ this ->generateKey ().'</b> <span class="label label-danger">HTML</span> ' ,
70- 'url ' => ( $ this ->_model ) ? $ this ->generateEditRoute ($ this ->_model ->id ) : $ this ->generateCreateRoute (),
82+ 'url ' => $ this ->_model ? $ this ->generateEditRoute ($ this ->_model ->id ) : $ this ->generateCreateRoute (),
7183 ],
7284 ];
7385 }
@@ -76,32 +88,32 @@ private function generateKey()
7688 {
7789 if ($ this ->key ) {
7890 return $ this ->key ;
79- } else {
80- $ key = \Yii::$ app ->request ->getQueryParam ('id ' );
8191 }
92+
93+ $ key = \Yii::$ app ->request ->getQueryParam ('id ' );
8294 return \Yii::$ app ->language .'/ ' .\Yii::$ app ->controller ->route .($ key ? '/ ' .$ key : '' );
8395 }
8496
8597 private function generateCreateLink ()
8698 {
8799
88100 return Html::a (FA ::icon (FA ::_PLUS_SQUARE ) . ' HTML ' ,
89- ['/prototype /html/create ' , 'Html ' => ['key ' => $ this ->generateKey ()]]);
101+ ['/ ' . $ this -> moduleId . ' /html/create ' , 'Html ' => ['key ' => $ this ->generateKey ()]]);
90102 }
91103
92104 private function generateEditLink ($ id )
93105 {
94- return Html::a (' prototype module ' , ['/prototype /html/update ' , 'id ' => $ id ]);
106+ return Html::a ($ this -> moduleId . ' module ' , ['/ ' . $ this -> moduleId . ' /html/update ' , 'id ' => $ id ]);
95107 }
96108
97109 private function generateCreateRoute ()
98110 {
99- return ['/prototype /html/create ' , 'Html ' => ['key ' => $ this ->generateKey ()]];
111+ return ['/ ' . $ this -> moduleId . ' /html/create ' , 'Html ' => ['key ' => $ this ->generateKey ()]];
100112 }
101113
102114 private function generateEditRoute ($ id )
103115 {
104- return ['/prototype /html/update ' , 'id ' => $ id ];
116+ return ['/ ' . $ this -> moduleId . ' /html/update ' , 'id ' => $ id ];
105117 }
106118
107119 private function renderEmpty ()
0 commit comments