-
Notifications
You must be signed in to change notification settings - Fork 8
/
Copy pathWidgetController.php
74 lines (64 loc) · 2.42 KB
/
WidgetController.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
<?php
namespace hrzg\widget\controllers\crud;
use hrzg\widget\assets\WidgetAsset;
use hrzg\widget\models\crud\WidgetContent;
use yii\filters\VerbFilter;
use yii\helpers\Url;
/**
* Class WidgetController
* @package hrzg\widget\controllers\crud
* @author Christopher Stebe <[email protected]>
*/
class WidgetController extends \hrzg\widget\controllers\crud\base\WidgetController
{
public function behaviors()
{
$behaviors = parent::behaviors();
$behaviors['verbs'] = [
'class' => VerbFilter::class,
'actions' => [
'delete' => [
'DELETE',
'POST'
]
]
];
return $behaviors;
}
public function beforeAction($action)
{
WidgetAsset::register($this->view);
// if set use CKEditor configurations from settings module else use default configuration.
$json = \Yii::$app->settings->get('ckeditor.config', 'widgets');
$ckeditorConfiguration = isset($json->scalar) ? $json->scalar : "{}";
$CKConfigScript = "window.CKCONFIG = {$ckeditorConfiguration};";
\Yii::$app->view->registerJs($CKConfigScript, \yii\web\View::POS_HEAD);
// if set use FILEFLYCONFIG configurations from settings module else use default configuration.
$json = \Yii::$app->settings->get('filefly.config', 'widgets');
$fileflyConfiguration = isset($json->scalar) ? $json->scalar : "{}";
$fileflyConfigScript = "window.FILEFLYCONFIG = {$fileflyConfiguration};";
\Yii::$app->view->registerJs($fileflyConfigScript, \yii\web\View::POS_HEAD);
return parent::beforeAction($action);
}
/**
* Creates a new Widget model.
* If creation is successful, the browser will be redirected to the 'view' page.
*
* @return mixed
*/
public function actionCreateFromTemplate($templateId = null)
{
$model = new WidgetContent();
try {
if ($model->load($_POST) && $model->save()) {
return $this->redirect(['view','id' => $model->id]);
} elseif (!\Yii::$app->request->isPost) {
$model->load($_GET);
}
} catch (\Exception $e) {
$msg = (isset($e->errorInfo[2])) ? $e->errorInfo[2] : $e->getMessage();
$model->addError('_exception', $msg);
}
return $this->render('create', ['model' => $model]);
}
}