1 | <?php |
||
2 | /** |
||
3 | * Retour plugin for Craft CMS |
||
4 | * |
||
5 | * Retour allows you to intelligently redirect legacy URLs, so that you don't |
||
6 | * lose SEO value when rebuilding & restructuring a website |
||
7 | * |
||
8 | * @link https://nystudio107.com/ |
||
0 ignored issues
–
show
Coding Style
introduced
by
![]() |
|||
9 | * @copyright Copyright (c) 2018 nystudio107 |
||
0 ignored issues
–
show
|
|||
10 | */ |
||
0 ignored issues
–
show
|
|||
11 | |||
12 | namespace nystudio107\retour\widgets; |
||
13 | |||
14 | use Craft; |
||
15 | use craft\base\Widget; |
||
16 | use nystudio107\retour\assetbundles\retour\RetourWidgetAsset; |
||
17 | use nystudio107\retour\Retour; |
||
18 | use Twig\Error\LoaderError; |
||
19 | use yii\base\Exception; |
||
20 | use yii\base\InvalidConfigException; |
||
21 | |||
22 | /** @noinspection MissingPropertyAnnotationsInspection */ |
||
0 ignored issues
–
show
|
|||
23 | |||
24 | /** |
||
25 | * Retour Widget |
||
26 | * |
||
27 | * @author nystudio107 |
||
0 ignored issues
–
show
Content of the @author tag must be in the form "Display Name <[email protected]>"
![]() |
|||
28 | * @package Retour |
||
0 ignored issues
–
show
|
|||
29 | * @since 3.0.0 |
||
0 ignored issues
–
show
|
|||
30 | */ |
||
0 ignored issues
–
show
|
|||
31 | class RetourWidget extends Widget |
||
32 | { |
||
33 | // Public Properties |
||
34 | // ========================================================================= |
||
35 | |||
36 | /** |
||
0 ignored issues
–
show
|
|||
37 | * @var int |
||
38 | */ |
||
39 | public int $numberOfDays = 30; |
||
40 | |||
41 | // Static Methods |
||
42 | // ========================================================================= |
||
43 | |||
44 | /** |
||
0 ignored issues
–
show
|
|||
45 | * @inheritdoc |
||
46 | */ |
||
0 ignored issues
–
show
|
|||
47 | public static function displayName(): string |
||
48 | { |
||
49 | return Retour::$settings->pluginName; |
||
50 | } |
||
51 | |||
52 | /** |
||
0 ignored issues
–
show
|
|||
53 | * @inheritdoc |
||
54 | */ |
||
0 ignored issues
–
show
|
|||
55 | public static function iconPath(): bool|string |
||
56 | { |
||
57 | return Craft::getAlias("@nystudio107/retour/web/assets/dist/img/icon-mask.svg"); |
||
58 | } |
||
59 | |||
60 | /** |
||
0 ignored issues
–
show
|
|||
61 | * @inheritdoc |
||
62 | */ |
||
0 ignored issues
–
show
|
|||
63 | public static function maxColspan(): ?int |
||
64 | { |
||
65 | return 1; |
||
66 | } |
||
67 | |||
68 | // Public Methods |
||
69 | // ========================================================================= |
||
70 | |||
71 | /** |
||
0 ignored issues
–
show
|
|||
72 | * @inheritdoc |
||
73 | */ |
||
0 ignored issues
–
show
|
|||
74 | public function rules(): array |
||
75 | { |
||
76 | $rules = parent::rules(); |
||
77 | $rules = array_merge( |
||
78 | $rules, |
||
79 | [ |
||
80 | ['numberOfDays', 'integer', 'min' => 1], |
||
81 | ['numberOfDays', 'default', 'value' => 30], |
||
82 | ] |
||
83 | ); |
||
84 | return $rules; |
||
85 | } |
||
86 | |||
87 | /** |
||
0 ignored issues
–
show
|
|||
88 | * @inheritdoc |
||
89 | */ |
||
0 ignored issues
–
show
|
|||
90 | public function getSettingsHtml(): null|string |
||
91 | { |
||
92 | try { |
||
93 | return Craft::$app->getView()->renderTemplate( |
||
94 | 'retour/_components/widgets/Retour_settings', |
||
95 | [ |
||
96 | 'widget' => $this, |
||
97 | ] |
||
98 | ); |
||
99 | } catch (LoaderError $e) { |
||
100 | Craft::error($e->getMessage(), __METHOD__); |
||
101 | } catch (Exception $e) { |
||
102 | Craft::error($e->getMessage(), __METHOD__); |
||
103 | } |
||
104 | |||
105 | return null; |
||
106 | } |
||
107 | |||
108 | /** |
||
0 ignored issues
–
show
|
|||
109 | * @inheritdoc |
||
110 | */ |
||
0 ignored issues
–
show
|
|||
111 | public function getBodyHtml(): null|string |
||
112 | { |
||
113 | try { |
||
114 | Craft::$app->getView()->registerAssetBundle(RetourWidgetAsset::class); |
||
115 | } catch (InvalidConfigException $e) { |
||
116 | Craft::error($e->getMessage(), __METHOD__); |
||
117 | } |
||
118 | |||
119 | try { |
||
120 | return Craft::$app->getView()->renderTemplate( |
||
121 | 'retour/_components/widgets/Retour_body', |
||
122 | [ |
||
123 | 'numberOfDays' => $this->numberOfDays, |
||
124 | ] |
||
125 | ); |
||
126 | } catch (LoaderError $e) { |
||
127 | Craft::error($e->getMessage(), __METHOD__); |
||
128 | } catch (Exception $e) { |
||
129 | Craft::error($e->getMessage(), __METHOD__); |
||
130 | } |
||
131 | |||
132 | return null; |
||
133 | } |
||
134 | } |
||
135 |