1 | <?php |
||
2 | /** |
||
3 | * Retour plugin for Craft CMS 3.x |
||
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 nystudio107\retour\Retour; |
||
15 | use nystudio107\retour\assetbundles\retour\RetourWidgetAsset; |
||
16 | |||
17 | use Craft; |
||
18 | use craft\base\Widget; |
||
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 | |||
34 | // Public Properties |
||
35 | // ========================================================================= |
||
36 | |||
37 | /** |
||
0 ignored issues
–
show
|
|||
38 | * @var int |
||
39 | */ |
||
40 | public $numberOfDays = 30; |
||
41 | |||
42 | // Static Methods |
||
43 | // ========================================================================= |
||
44 | |||
45 | /** |
||
0 ignored issues
–
show
|
|||
46 | * @inheritdoc |
||
47 | */ |
||
0 ignored issues
–
show
|
|||
48 | public static function displayName(): string |
||
49 | { |
||
50 | return Retour::$settings->pluginName; |
||
51 | } |
||
52 | |||
53 | /** |
||
0 ignored issues
–
show
|
|||
54 | * @inheritdoc |
||
55 | */ |
||
0 ignored issues
–
show
|
|||
56 | public static function iconPath() |
||
57 | { |
||
58 | return Craft::getAlias("@nystudio107/retour/assetbundles/retour/dist/img/icon-mask.svg"); |
||
59 | } |
||
60 | |||
61 | /** |
||
0 ignored issues
–
show
|
|||
62 | * @inheritdoc |
||
63 | */ |
||
0 ignored issues
–
show
|
|||
64 | public static function maxColspan() |
||
65 | { |
||
66 | return 1; |
||
67 | } |
||
68 | |||
69 | // Public Methods |
||
70 | // ========================================================================= |
||
71 | |||
72 | /** |
||
0 ignored issues
–
show
|
|||
73 | * @inheritdoc |
||
74 | */ |
||
0 ignored issues
–
show
|
|||
75 | public function rules() |
||
76 | { |
||
77 | $rules = parent::rules(); |
||
78 | $rules = array_merge( |
||
79 | $rules, |
||
80 | [ |
||
81 | ['numberOfDays', 'integer', 'min' => 1], |
||
82 | ['numberOfDays', 'default', 'value' => 30], |
||
83 | ] |
||
84 | ); |
||
85 | return $rules; |
||
86 | } |
||
87 | |||
88 | /** |
||
0 ignored issues
–
show
|
|||
89 | * @inheritdoc |
||
90 | */ |
||
0 ignored issues
–
show
|
|||
91 | public function getSettingsHtml() |
||
92 | { |
||
93 | try { |
||
94 | return Craft::$app->getView()->renderTemplate( |
||
95 | 'retour/_components/widgets/Retour_settings', |
||
96 | [ |
||
97 | 'widget' => $this, |
||
98 | ] |
||
99 | ); |
||
100 | } catch (\Twig\Error\LoaderError $e) { |
||
101 | Craft::error($e->getMessage(), __METHOD__); |
||
102 | } catch (Exception $e) { |
||
103 | Craft::error($e->getMessage(), __METHOD__); |
||
104 | } |
||
105 | } |
||
106 | |||
107 | /** |
||
0 ignored issues
–
show
|
|||
108 | * @inheritdoc |
||
109 | */ |
||
0 ignored issues
–
show
|
|||
110 | public function getBodyHtml() |
||
111 | { |
||
112 | try { |
||
113 | Craft::$app->getView()->registerAssetBundle(RetourWidgetAsset::class); |
||
114 | } catch (InvalidConfigException $e) { |
||
115 | Craft::error($e->getMessage(), __METHOD__); |
||
116 | } |
||
117 | |||
118 | try { |
||
119 | return Craft::$app->getView()->renderTemplate( |
||
120 | 'retour/_components/widgets/Retour_body', |
||
121 | [ |
||
122 | 'numberOfDays' => $this->numberOfDays, |
||
123 | ] |
||
124 | ); |
||
125 | } catch (\Twig\Error\LoaderError $e) { |
||
126 | Craft::error($e->getMessage(), __METHOD__); |
||
127 | } catch (Exception $e) { |
||
128 | Craft::error($e->getMessage(), __METHOD__); |
||
129 | } |
||
130 | } |
||
131 | } |
||
132 |