1 | <?php |
||
2 | /** |
||
3 | * Typogrify plugin for Craft CMS |
||
4 | * |
||
5 | * Typogrify prettifies your web typography by preventing ugly quotes and 'widows' and more |
||
6 | * |
||
7 | * @link https://nystudio107.com/ |
||
0 ignored issues
–
show
Coding Style
introduced
by
![]() |
|||
8 | * @copyright Copyright (c) nystudio107 |
||
0 ignored issues
–
show
|
|||
9 | */ |
||
0 ignored issues
–
show
|
|||
10 | |||
11 | namespace nystudio107\typogrify; |
||
12 | |||
13 | use Craft; |
||
14 | use craft\base\Model; |
||
15 | use craft\base\Plugin; |
||
16 | use craft\web\twig\variables\CraftVariable; |
||
17 | use nystudio107\typogrify\models\Settings; |
||
18 | use nystudio107\typogrify\services\ServicesTrait; |
||
19 | use nystudio107\typogrify\twigextensions\TypogrifyTwigExtension; |
||
20 | use nystudio107\typogrify\variables\TypogrifyVariable; |
||
21 | use yii\base\Event; |
||
22 | |||
23 | /** |
||
24 | * Class Typogrify |
||
25 | * |
||
26 | * @author nystudio107 |
||
0 ignored issues
–
show
Content of the @author tag must be in the form "Display Name <[email protected]>"
![]() |
|||
27 | * @package Typogrify |
||
0 ignored issues
–
show
|
|||
28 | * @since 1.0.0 |
||
0 ignored issues
–
show
|
|||
29 | * |
||
30 | * @property Settings $settings |
||
0 ignored issues
–
show
|
|||
31 | */ |
||
0 ignored issues
–
show
|
|||
32 | class Typogrify extends Plugin |
||
33 | { |
||
34 | // Traits |
||
35 | // ========================================================================= |
||
36 | |||
37 | use ServicesTrait; |
||
38 | |||
39 | // Static Properties |
||
40 | // ========================================================================= |
||
41 | |||
42 | /** |
||
0 ignored issues
–
show
|
|||
43 | * @var ?Typogrify |
||
44 | */ |
||
45 | public static ?Typogrify $plugin = null; |
||
46 | |||
47 | /** |
||
0 ignored issues
–
show
|
|||
48 | * @var ?TypogrifyVariable |
||
49 | */ |
||
50 | public static ?TypogrifyVariable $variable = null; |
||
51 | |||
52 | // Public Properties |
||
53 | // ========================================================================= |
||
54 | |||
55 | /** |
||
0 ignored issues
–
show
|
|||
56 | * @var string |
||
57 | */ |
||
58 | public string $schemaVersion = '1.0.0'; |
||
59 | |||
60 | /** |
||
0 ignored issues
–
show
|
|||
61 | * @var bool |
||
62 | */ |
||
63 | public bool $hasCpSettings = false; |
||
64 | /** |
||
0 ignored issues
–
show
|
|||
65 | * @var bool |
||
66 | */ |
||
67 | public bool $hasCpSection = false; |
||
68 | |||
69 | // Public Methods |
||
70 | // ========================================================================= |
||
71 | |||
72 | /** |
||
0 ignored issues
–
show
|
|||
73 | * @inheritdoc |
||
74 | */ |
||
0 ignored issues
–
show
|
|||
75 | public function init(): void |
||
76 | { |
||
77 | parent::init(); |
||
78 | self::$plugin = $this; |
||
79 | self::$variable = new TypogrifyVariable(); |
||
80 | |||
81 | Craft::$app->view->registerTwigExtension(new TypogrifyTwigExtension()); |
||
82 | // Register our variables |
||
83 | Event::on( |
||
84 | CraftVariable::class, |
||
85 | CraftVariable::EVENT_INIT, |
||
86 | static function(Event $event) { |
||
0 ignored issues
–
show
|
|||
87 | /** @var CraftVariable $variable */ |
||
0 ignored issues
–
show
|
|||
88 | $variable = $event->sender; |
||
89 | $variable->set('typogrify', self::$variable); |
||
90 | } |
||
91 | ); |
||
92 | |||
93 | Craft::info( |
||
94 | Craft::t( |
||
95 | 'typogrify', |
||
96 | '{name} plugin loaded', |
||
97 | ['name' => $this->name] |
||
98 | ), |
||
99 | __METHOD__ |
||
100 | ); |
||
101 | } |
||
102 | |||
103 | // Protected Methods |
||
104 | // ========================================================================= |
||
105 | |||
106 | /** |
||
0 ignored issues
–
show
|
|||
107 | * @inheritdoc |
||
108 | */ |
||
0 ignored issues
–
show
|
|||
109 | protected function createSettingsModel(): ?Model |
||
110 | { |
||
111 | return new Settings(); |
||
112 | } |
||
113 | } |
||
114 |