1
|
|
|
<?php |
2
|
|
|
/** |
3
|
|
|
* Spoon plugin for Craft CMS 3.x |
4
|
|
|
* |
5
|
|
|
* Enhance Matrix |
6
|
|
|
* |
7
|
|
|
* @link https://angell.io |
8
|
|
|
* @copyright Copyright (c) 2018 Angell & Co |
9
|
|
|
*/ |
10
|
|
|
|
11
|
|
|
namespace angellco\spoon; |
12
|
|
|
|
13
|
|
|
use angellco\spoon\models\Settings; |
14
|
|
|
use angellco\spoon\services\Fields as FieldsService; |
15
|
|
|
use angellco\spoon\services\BlockTypes as BlockTypesService; |
16
|
|
|
use angellco\spoon\services\Loader as LoaderService; |
17
|
|
|
|
18
|
|
|
use Craft; |
19
|
|
|
use craft\base\Plugin; |
20
|
|
|
use craft\events\RegisterUrlRulesEvent; |
21
|
|
|
use craft\services\Plugins; |
22
|
|
|
|
23
|
|
|
use craft\web\UrlManager; |
24
|
|
|
use yii\base\Event; |
25
|
|
|
|
26
|
|
|
/** |
27
|
|
|
* Craft plugins are very much like little applications in and of themselves. We’ve made |
28
|
|
|
* it as simple as we can, but the training wheels are off. A little prior knowledge is |
29
|
|
|
* going to be required to write a plugin. |
30
|
|
|
* |
31
|
|
|
* For the purposes of the plugin docs, we’re going to assume that you know PHP and SQL, |
32
|
|
|
* as well as some semi-advanced concepts like object-oriented programming and PHP namespaces. |
33
|
|
|
* |
34
|
|
|
* https://craftcms.com/docs/plugins/introduction |
35
|
|
|
* |
36
|
|
|
* @author Angell & Co |
37
|
|
|
* @package Spoon |
38
|
|
|
* @since 3.0.0 |
39
|
|
|
* |
40
|
|
|
* @property FieldsService $fields |
41
|
|
|
* @property BlockTypesService $blockTypes |
42
|
|
|
* @property LoaderService $loader |
43
|
|
|
* @method Settings getSettings() |
44
|
|
|
*/ |
45
|
|
|
class Spoon extends Plugin |
46
|
|
|
{ |
47
|
|
|
// Static Properties |
48
|
|
|
// ========================================================================= |
49
|
|
|
|
50
|
|
|
/** |
51
|
|
|
* Static property that is an instance of this plugin class so that it can be accessed via |
52
|
|
|
* Spoon::$plugin |
53
|
|
|
* |
54
|
|
|
* @var Spoon |
55
|
|
|
*/ |
56
|
|
|
public static $plugin; |
57
|
|
|
|
58
|
|
|
// Public Properties |
59
|
|
|
// ========================================================================= |
60
|
|
|
|
61
|
|
|
/** |
62
|
|
|
* To execute your plugin’s migrations, you’ll need to increase its schema version. |
63
|
|
|
* |
64
|
|
|
* @var string |
65
|
|
|
*/ |
66
|
|
|
public $schemaVersion = '3.0.0'; |
67
|
|
|
|
68
|
|
|
/** |
69
|
|
|
* @var bool Whether the plugin has its own section in the CP |
70
|
|
|
*/ |
71
|
|
|
public $hasCpSection = true; |
72
|
|
|
|
73
|
|
|
|
74
|
|
|
// Public Methods |
75
|
|
|
// ========================================================================= |
76
|
|
|
|
77
|
|
|
/** |
78
|
|
|
* Set our $plugin static property to this class so that it can be accessed via |
79
|
|
|
* Spoon::$plugin |
80
|
|
|
* |
81
|
|
|
* Called after the plugin class is instantiated; do any one-time initialization |
82
|
|
|
* here such as hooks and events. |
83
|
|
|
* |
84
|
|
|
* If you have a '/vendor/autoload.php' file, it will be loaded for you automatically; |
85
|
|
|
* you do not need to load it in your init() method. |
86
|
|
|
* |
87
|
|
|
*/ |
88
|
|
|
public function init() |
89
|
|
|
{ |
90
|
|
|
parent::init(); |
91
|
|
|
self::$plugin = $this; |
92
|
|
|
|
93
|
|
|
Event::on( |
94
|
|
|
UrlManager::class, |
95
|
|
|
UrlManager::EVENT_REGISTER_CP_URL_RULES, |
96
|
|
|
function(RegisterUrlRulesEvent $event) { |
97
|
|
|
$event->rules['spoon'] = 'spoon/block-types/index'; |
98
|
|
|
} |
99
|
|
|
); |
100
|
|
|
|
101
|
|
|
// Wait until all the plugins have loaded before running the loader |
102
|
|
|
Event::on( |
103
|
|
|
Plugins::class, |
104
|
|
|
Plugins::EVENT_AFTER_LOAD_PLUGINS, |
105
|
|
|
function() { |
106
|
|
|
if ($this->isInstalled && !Craft::$app->plugins->doesPluginRequireDatabaseUpdate($this)) { |
107
|
|
|
$this->loader->run(); |
108
|
|
|
} |
109
|
|
|
} |
110
|
|
|
); |
111
|
|
|
|
112
|
|
|
Craft::info( |
113
|
|
|
Craft::t( |
114
|
|
|
'spoon', |
115
|
|
|
'{name} plugin loaded', |
116
|
|
|
['name' => $this->name] |
117
|
|
|
), |
118
|
|
|
__METHOD__ |
119
|
|
|
); |
120
|
|
|
} |
121
|
|
|
|
122
|
|
|
// Protected Methods |
123
|
|
|
// ========================================================================= |
124
|
|
|
|
125
|
|
|
/** |
126
|
|
|
* @inheritdoc |
127
|
|
|
*/ |
128
|
|
|
protected function createSettingsModel() |
129
|
|
|
{ |
130
|
|
|
return new Settings(); |
131
|
|
|
} |
132
|
|
|
|
133
|
|
|
} |
134
|
|
|
|