1 | <?php |
||
2 | |||
3 | namespace GinoPane\AwesomeSocialLinks\Components; |
||
4 | |||
5 | use Cms\Classes\ComponentBase; |
||
0 ignored issues
–
show
|
|||
6 | use GinoPane\AwesomeSocialLinks\Models\LinkItem; |
||
7 | use GinoPane\AwesomeSocialLinks\Plugin; |
||
8 | use GinoPane\AwesomeSocialLinks\Models\Settings; |
||
9 | |||
10 | /** |
||
11 | * Class LinkList |
||
12 | * |
||
13 | * @package GinoPane\AwesomeSocialLinks\Components |
||
14 | */ |
||
15 | class LinkList extends ComponentBase |
||
16 | { |
||
17 | /** |
||
18 | * Works like cache for the case when OctoberCMS calls LinkList::defineProperties several times |
||
19 | * |
||
20 | * @var array |
||
21 | */ |
||
22 | private static $definedProperties = []; |
||
23 | |||
24 | const NAME = 'linkList'; |
||
25 | |||
26 | /** |
||
27 | * @var LinkItem[] |
||
28 | */ |
||
29 | public $links = []; |
||
30 | |||
31 | /** |
||
32 | * @var string |
||
33 | */ |
||
34 | public $linkTarget = Settings::LINK_TARGET_BLANK; |
||
35 | |||
36 | /** |
||
37 | * Component Registration |
||
38 | * |
||
39 | * @return array |
||
40 | */ |
||
41 | public function componentDetails() |
||
42 | { |
||
43 | return [ |
||
44 | 'name' => Plugin::LOCALIZATION_KEY . 'components.link_list.name', |
||
45 | 'description' => Plugin::LOCALIZATION_KEY . 'components.link_list.description' |
||
46 | ]; |
||
47 | } |
||
48 | |||
49 | /** |
||
50 | * Component Properties |
||
51 | * |
||
52 | * @return array |
||
53 | */ |
||
54 | public function defineProperties(): array |
||
55 | { |
||
56 | if (!empty(self::$definedProperties)) { |
||
57 | return self::$definedProperties; |
||
58 | } |
||
59 | |||
60 | /** @var Settings $settings */ |
||
61 | $settings = Settings::instance(); |
||
62 | |||
63 | $links = $settings->getLinks(); |
||
64 | |||
65 | $properties = []; |
||
66 | |||
67 | foreach ($links as $link) { |
||
68 | $name = $link->getName(); |
||
69 | |||
70 | $properties[$name] = [ |
||
71 | 'title' => ucwords($name), |
||
72 | 'type' => 'checkbox', |
||
73 | 'default' => false, |
||
74 | 'showExternalParam' => false |
||
75 | ]; |
||
76 | } |
||
77 | |||
78 | $properties['linkTarget'] = [ |
||
79 | 'group' => Plugin::LOCALIZATION_KEY . 'components.link_list.link_settings_group', |
||
80 | 'title' => Plugin::LOCALIZATION_KEY . 'components.link_list.link_target_title', |
||
81 | 'description' => Plugin::LOCALIZATION_KEY . 'components.link_list.link_target_description', |
||
82 | 'type' => 'dropdown', |
||
83 | 'default' => Settings::LINK_TARGET_BLANK, |
||
84 | 'showExternalParam' => false |
||
85 | ]; |
||
86 | |||
87 | return (self::$definedProperties = $properties); |
||
88 | } |
||
89 | |||
90 | /** |
||
91 | * @return array |
||
92 | */ |
||
93 | public function getLinkTargetOptions(): array |
||
94 | { |
||
95 | return Settings::instance()->getLinkTargets(); |
||
96 | } |
||
97 | |||
98 | /** |
||
99 | * Prepare and set variables |
||
100 | * |
||
101 | * @return void |
||
102 | */ |
||
103 | public function onRun() |
||
104 | { |
||
105 | $this->fillLinks(); |
||
106 | |||
107 | $this->linkTarget = $this->property('linkTarget'); |
||
108 | } |
||
109 | |||
110 | /** |
||
111 | * Fill links from settings, filter by component config |
||
112 | */ |
||
113 | protected function fillLinks() |
||
114 | { |
||
115 | /** @var LinkItem[] $links */ |
||
116 | $links = Settings::instance()->getLinks(); |
||
117 | |||
118 | foreach ($links as $index => $link) { |
||
119 | if (!$this->property($link->getName())) { |
||
120 | unset($links[$index]); |
||
121 | } |
||
122 | } |
||
123 | |||
124 | $this->links = $links; |
||
125 | } |
||
126 | } |
||
127 |
The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g.
excluded_paths: ["lib/*"]
, you can move it to the dependency path list as follows:For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths