-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathModule.php
More file actions
55 lines (46 loc) · 1.24 KB
/
Module.php
File metadata and controls
55 lines (46 loc) · 1.24 KB
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
<?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
{
/**
* @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) && str_starts_with($file->mime_type, 'text/');
}
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->canView()
&& is_readable($file->getStore()->get());
}
}