-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathCreateController.php
53 lines (44 loc) · 1.42 KB
/
CreateController.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
<?php
/**
* @link https://www.humhub.org/
* @copyright Copyright (c) 2021 HumHub GmbH & Co. KG
* @license https://www.humhub.com/licences
*/
namespace humhub\modules\text_editor\controllers;
use humhub\components\Controller;
use humhub\modules\file\libs\FileHelper;
use humhub\modules\text_editor\models\CreateFile;
use humhub\modules\text_editor\Module;
use Yii;
use yii\helpers\Url;
use yii\web\ForbiddenHttpException;
class CreateController extends Controller
{
/**
* @inheritdoc
* @var Module
*/
public $module;
public function actionIndex()
{
if (!$this->module->canCreate()) {
throw new ForbiddenHttpException('Creation of new text files is not allowed!');
}
$model = new CreateFile();
if ($model->load(Yii::$app->request->post())) {
if ($file = $model->save()) {
return $this->asJson([
'success' => true,
'file' => FileHelper::getFileInfos($file),
'editFormUrl' => $model->openEditForm ? Url::to(['/text-editor/edit', 'guid' => $file->guid]) : false,
]);
} else {
return $this->asJson([
'success' => false,
'output' => $this->renderAjax('index', ['model' => $model]),
]);
}
}
return $this->renderAjax('index', ['model' => $model]);
}
}