-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathModule.php
57 lines (47 loc) · 1.28 KB
/
Module.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
<?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;
use humhub\modules\file\models\File;
use humhub\modules\text_editor\models\forms\ConfigForm;
use yii\helpers\Url;
class Module extends \humhub\components\Module
{
public $resourcesPath = 'resources';
/**
* @inheritdoc
*/
public function getConfigUrl()
{
return Url::to(['/text-editor/config']);
}
/**
* Check the file type is supported by this module
*
* @param File|null $file
* @return bool
*/
public function isSupportedType(?File $file): bool
{
return $file !== null && is_string($file->mime_type) && strpos($file->mime_type, 'text/') === 0;
}
public function canCreate(): bool
{
return (new ConfigForm())->allowNewFiles;
}
public function canEdit(File $file): bool
{
return $this->isSupportedType($file) &&
$file->canDelete() &&
is_writable($file->getStore()->get());
}
public function canView(File $file): bool
{
return $this->isSupportedType($file) &&
$file->canRead() &&
is_readable($file->getStore()->get());
}
}