44
55use nullref \cms \components \RelatedBehavior ;
66use Yii ;
7+ use yii \base \Exception ;
78use yii \behaviors \TimestampBehavior ;
89use yii \db \ActiveRecord ;
910
@@ -39,8 +40,8 @@ public static function tableName()
3940 public function behaviors ()
4041 {
4142 return [
42- 'timestamp ' => [
43- 'class ' => TimestampBehavior::className (),
43+ 'timestamp ' => [
44+ 'class ' => TimestampBehavior::className (),
4445 'createdAtAttribute ' => 'createdAt ' ,
4546 'updatedAtAttribute ' => 'updatedAt ' ,
4647 ],
@@ -53,6 +54,16 @@ public function behaviors()
5354 ];
5455 }
5556
57+ /**
58+ * @inheritdoc
59+ */
60+ public function attributeHints ()
61+ {
62+ return [
63+ 'layout ' => Yii::t ('cms ' , 'e.g. @app/views/layouts/main ' ),
64+ ];
65+ }
66+
5667
5768 /**
5869 * @inheritdoc
@@ -63,9 +74,26 @@ public function rules()
6374 [['route ' , 'title ' , 'layout ' ], 'required ' ],
6475 [['createdAt ' , 'updatedAt ' ], 'integer ' ],
6576 [['route ' , 'title ' , 'layout ' ], 'string ' , 'max ' => 255 ],
77+ [['layout ' ], 'validateAlias ' ],
6678 ];
6779 }
6880
81+ /**
82+ * @param $attribute
83+ */
84+ public function validateAlias ($ attribute )
85+ {
86+ try {
87+
88+ $ path = Yii::getAlias ($ this ->{$ attribute });
89+ if (!(file_exists ($ path ) || file_exists ($ path . '.php ' ))) {
90+ $ this ->addError ($ attribute , Yii::t ('cms ' , 'Layout file must exist ' ));
91+ }
92+ } catch (\Exception $ e ) {
93+ $ this ->addError ($ attribute , $ e ->getMessage ());
94+ }
95+ }
96+
6997 /**
7098 * @inheritdoc
7199 */
@@ -95,6 +123,6 @@ public static function find()
95123 */
96124 public function getItems ()
97125 {
98- return $ this ->hasMany (PageHasBlock::className (),['page_id ' => 'id ' ])->orderBy (['order ' => SORT_ASC ]);
126+ return $ this ->hasMany (PageHasBlock::className (), ['page_id ' => 'id ' ])->orderBy (['order ' => SORT_ASC ]);
99127 }
100128}
0 commit comments