Issues (76)

Components/ListComponents/functions.php (2 issues)

Labels
Severity
1
<?php
2
3
namespace Flynt\Components\ListComponents;
4
5
use Flynt\FieldVariables;
0 ignored issues
show
The type Flynt\FieldVariables was not found. Maybe you did not declare it correctly or list all dependencies?

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:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
6
use Flynt\ComponentManager;
7
use Flynt\Utils\Options;
8
use Flynt\Utils\Asset;
9
use Parsedown;
10
11
add_filter('Flynt/addComponentData?name=ListComponents', function ($data) {
12
    if (!empty($data['componentBlocks'])) {
13
        $templatePaths = [
14
            'dir' => trailingslashit(get_template_directory()),
15
            'uri' => trailingslashit(get_template_directory_uri()),
16
        ];
17
        $data['componentBlocks'] = array_map(function ($block) use ($templatePaths) {
18
            $block['component'] = substr($block['component'], strpos($block['component'], 'Components/'));
19
20
            $imagePath = $templatePaths['dir'] . $block['component'] . 'screenshot.png';
21
            if (file_exists($imagePath)) {
22
                $src = $templatePaths['uri'] . $block['component'] . 'screenshot.png';
23
                list($width, $height) = getimagesize($imagePath);
24
25
                $block['componentScreenshot'] = [
26
                    'src' => $src,
27
                    'aspect' => $width / $height
28
                ];
29
            }
30
31
            $readme = $templatePaths['dir'] . $block['component'] . 'README.md';
32
33
            if (file_exists($readme)) {
34
                $readmeLines = explode(PHP_EOL, Parsedown::instance()->setUrlsLinked(false)->text(file_get_contents($readme)));
35
                $block['readme'] = [
36
                    'title' => strip_tags($readmeLines[0]),
37
                    'description' => implode(PHP_EOL, array_slice($readmeLines, 1))
38
                ];
39
            }
40
41
            return $block;
42
        }, $data['componentBlocks']);
43
    }
44
45
    return $data;
46
});
47
48
add_filter('acf/load_field/name=component', function ($field) {
49
    $componentManager = ComponentManager::getInstance();
50
    $field['choices'] = array_flip($componentManager->getAll());
51
    return $field;
52
});
53
54
function getACFLayout()
55
{
56
    return [
57
        'name' => 'listComponents',
58
        'label' => 'List: Components',
59
        'sub_fields' => [
60
            [
61
                'label' => __('General', 'flynt'),
62
                'name' => 'generalTab',
63
                'type' => 'tab',
64
                'placement' => 'top',
65
                'endpoint' => 0
66
            ],
67
            [
68
                'label' => __('Title', 'flynt'),
69
                'name' => 'preContentHtml',
70
                'type' => 'wysiwyg',
71
                'tabs' => 'visual,text',
72
                'media_upload' => 0,
73
                'delay' => 1,
74
                'instructions' => __('Want to add a headline? And a paragraph? Go ahead! Or just leave it empty and nothing will be shown.', 'flynt'),
75
            ],
76
            [
77
                'label' => __('Component Blocks', 'flynt'),
78
                'name' => 'componentBlocks',
79
                'type' => 'repeater',
80
                'collapsed' => 0,
81
                'min' => 1,
82
                'layout' => 'table',
83
                'button_label' => __('Add Component Block', 'flynt'),
84
                'sub_fields' => [
85
                    [
86
                        'label' => __('Component', 'flynt'),
87
                        'name' => 'component',
88
                        'type' => 'select',
89
                        'ui' => 1,
90
                        'ajax' => 0,
91
                        'choices' => [],
92
                        'wrapper' => [
93
                            'width' => 50
94
                        ],
95
                    ],
96
                    [
97
                        'label' => __('Calls To Action', 'flynt'),
98
                        'name' => 'ctas',
99
                        'type' => 'group',
100
                        'collapsed' => 0,
101
                        'layout' => 'row',
102
                        'sub_fields' => [
103
                            [
104
                                'label' => __('Preview', 'flynt'),
105
                                'name' => 'primary',
106
                                'type' => 'text'
107
                            ],
108
                            [
109
                                'label' => __('GitHub', 'flynt'),
110
                                'name' => 'secondary',
111
                                'type' => 'url'
112
                            ],
113
                        ],
114
                    ],
115
                ],
116
            ],
117
            [
118
                'label' => __('Options', 'flynt'),
119
                'name' => 'optionsTab',
120
                'type' => 'tab',
121
                'placement' => 'top',
122
                'endpoint' => 0
123
            ],
124
            [
125
                'label' => '',
126
                'name' => 'options',
127
                'type' => 'group',
128
                'layout' => 'row',
129
                'sub_fields' => [
130
                    FieldVariables\getTheme(),
0 ignored issues
show
The function getTheme was not found. Maybe you did not declare it correctly or list all dependencies? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

130
                    /** @scrutinizer ignore-call */ 
131
                    FieldVariables\getTheme(),
Loading history...
131
                ],
132
            ]
133
        ]
134
    ];
135
}
136
137
Options::addTranslatable('ListComponents', [
138
    [
139
        'label' => __('Labels', 'flynt'),
140
        'name' => 'labelsTab',
141
        'type' => 'tab',
142
        'placement' => 'top',
143
        'endpoint' => 0
144
    ],
145
    [
146
        'label' => '',
147
        'name' => 'labels',
148
        'type' => 'group',
149
        'sub_fields' => [
150
            [
151
                'label' => __('Code', 'flynt'),
152
                'name' => 'code',
153
                'type' => 'text',
154
                'default_value' => 'Code',
155
                'required' => 1,
156
                'wrapper' => [
157
                    'width' => '50',
158
                ],
159
            ],
160
            [
161
                'label' => __('Preview', 'flynt'),
162
                'name' => 'preview',
163
                'type' => 'text',
164
                'default_value' => 'Preview',
165
                'required' => 1,
166
                'wrapper' => [
167
                    'width' => '50',
168
                ],
169
            ],
170
        ],
171
    ]
172
]);
173