Issues (223)

src/CodeField.php (1 issue)

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
8
 * @copyright Copyright (c) 2022 nystudio107
9
 */
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
26
 * @package   CodeField
27
 * @since     4.0.0
28
 *
29
 */
30
class CodeField extends Plugin
31
{
32
    // Static Properties
33
    // =========================================================================
34
35
    /**
36
     * @var CodeField
37
     */
38
    public static ?CodeField $plugin = null;
39
40
    // Public Properties
41
    // =========================================================================
42
43
    /**
44
     * @var string
45
     */
46
    public string $schemaVersion = '1.0.0';
47
48
    /**
49
     * @var bool
50
     */
51
    public bool $hasCpSettings = false;
52
53
    /**
54
     * @var bool
55
     */
56
    public bool $hasCpSection = false;
57
58
    // Public Methods
59
    // =========================================================================
60
61
    /**
62
     * @inheritdoc
63
     */
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) {
73
                $event->types[] = Code::class;
74
            }
75
        );
76
77
        Event::on(
78
            Plugins::class,
79
            Plugins::EVENT_AFTER_INSTALL_PLUGIN,
80
            function(PluginEvent $event) {
81
                if ($event->plugin === $this) {
0 ignored issues
show
The condition $event->plugin === $this is always false.
Loading history...
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