1 | <?php |
||
2 | /** |
||
3 | * Code Field plugin for Craft CMS |
||
4 | * |
||
5 | * Provides a Code Field that has a full-featured code editor with syntax highlighting & autocomplete |
||
6 | * |
||
7 | * @link https://nystudio107.com |
||
0 ignored issues
–
show
Coding Style
introduced
by
![]() |
|||
8 | * @copyright Copyright (c) 2022 nystudio107 |
||
0 ignored issues
–
show
|
|||
9 | */ |
||
0 ignored issues
–
show
|
|||
10 | |||
11 | namespace nystudio107\codefield; |
||
12 | |||
13 | use Craft; |
||
14 | use craft\base\Plugin; |
||
15 | use craft\events\PluginEvent; |
||
16 | use craft\events\RegisterComponentTypesEvent; |
||
17 | use craft\services\Fields; |
||
18 | use craft\services\Plugins; |
||
19 | use nystudio107\codefield\fields\Code; |
||
20 | use yii\base\Event; |
||
21 | |||
22 | /** |
||
23 | * Class CodeField |
||
24 | * |
||
25 | * @author nystudio107 |
||
0 ignored issues
–
show
Content of the @author tag must be in the form "Display Name <[email protected]>"
![]() |
|||
26 | * @package CodeField |
||
0 ignored issues
–
show
|
|||
27 | * @since 4.0.0 |
||
0 ignored issues
–
show
|
|||
28 | * |
||
29 | */ |
||
0 ignored issues
–
show
|
|||
30 | class CodeField extends Plugin |
||
31 | { |
||
32 | // Static Properties |
||
33 | // ========================================================================= |
||
34 | |||
35 | /** |
||
0 ignored issues
–
show
|
|||
36 | * @var CodeField |
||
37 | */ |
||
38 | public static ?CodeField $plugin = null; |
||
39 | |||
40 | // Public Properties |
||
41 | // ========================================================================= |
||
42 | |||
43 | /** |
||
0 ignored issues
–
show
|
|||
44 | * @var string |
||
45 | */ |
||
46 | public string $schemaVersion = '1.0.0'; |
||
47 | |||
48 | /** |
||
0 ignored issues
–
show
|
|||
49 | * @var bool |
||
50 | */ |
||
51 | public bool $hasCpSettings = false; |
||
52 | |||
53 | /** |
||
0 ignored issues
–
show
|
|||
54 | * @var bool |
||
55 | */ |
||
56 | public bool $hasCpSection = false; |
||
57 | |||
58 | // Public Methods |
||
59 | // ========================================================================= |
||
60 | |||
61 | /** |
||
0 ignored issues
–
show
|
|||
62 | * @inheritdoc |
||
63 | */ |
||
0 ignored issues
–
show
|
|||
64 | public function init() |
||
65 | { |
||
66 | parent::init(); |
||
67 | self::$plugin = $this; |
||
68 | |||
69 | Event::on( |
||
70 | Fields::class, |
||
71 | Fields::EVENT_REGISTER_FIELD_TYPES, |
||
72 | static function(RegisterComponentTypesEvent $event) { |
||
0 ignored issues
–
show
|
|||
73 | $event->types[] = Code::class; |
||
74 | } |
||
75 | ); |
||
76 | |||
77 | Event::on( |
||
78 | Plugins::class, |
||
79 | Plugins::EVENT_AFTER_INSTALL_PLUGIN, |
||
80 | function(PluginEvent $event) { |
||
0 ignored issues
–
show
|
|||
81 | if ($event->plugin === $this) { |
||
0 ignored issues
–
show
|
|||
82 | } |
||
83 | } |
||
84 | ); |
||
85 | |||
86 | Craft::info( |
||
87 | Craft::t( |
||
88 | 'codefield', |
||
89 | '{name} plugin loaded', |
||
90 | ['name' => $this->name] |
||
91 | ), |
||
92 | __METHOD__ |
||
93 | ); |
||
94 | } |
||
95 | } |
||
96 |