Skip to content

Commit c8c3e60

Browse files
author
Sebastian Thulin
committed
fix: refresh view when changing subfooter data
1 parent 80c9a17 commit c8c3e60

2 files changed

Lines changed: 150 additions & 128 deletions

File tree

library/Customizer/Sections/Component/FooterSub.php

Lines changed: 102 additions & 128 deletions
Original file line numberDiff line numberDiff line change
@@ -8,215 +8,189 @@ class FooterSub
88
{
99
public function __construct(string $sectionID)
1010
{
11+
/* TODO: Design */
1112
CustomizerField::addField([
12-
'type' => 'multicolor',
13-
'settings' => 'footer_subfooter_colors',
14-
'label' => esc_html__('Colors', 'municipio'),
15-
'section' => $sectionID,
16-
'priority' => 10,
13+
'type' => 'multicolor',
14+
'settings' => 'footer_subfooter_colors',
15+
'label' => esc_html__('Colors', 'municipio'),
16+
'section' => $sectionID,
17+
'priority' => 10,
1718
'transport' => 'auto',
18-
'alpha' => true,
19-
'choices' => [
19+
'alpha' => true,
20+
'choices' => [
2021
'background' => esc_html__('Background', 'municipio'),
21-
'text' => esc_html__('Base Contrasting', 'municipio'),
22-
'separator' => esc_html__('Text separator', 'municipio'),
22+
'text' => esc_html__('Base Contrasting', 'municipio'),
23+
'separator' => esc_html__('Text separator', 'municipio'),
2324
],
24-
'default' => [
25+
'default' => [
2526
'background' => '#fff',
26-
'text' => '#000',
27-
'separator' => '#A3A3A3',
27+
'text' => '#000',
28+
'separator' => '#A3A3A3',
2829
],
29-
'output' => [
30+
'output' => [
3031
[
31-
'choice' => 'background',
32-
'element' => ':root',
32+
'choice' => 'background',
33+
'element' => ':root',
3334
'property' => '--c-footer-subfooter-color-background',
3435
],
3536
[
36-
'choice' => 'text',
37-
'element' => ':root',
37+
'choice' => 'text',
38+
'element' => ':root',
3839
'property' => '--c-footer-subfooter-color-text',
3940
],
4041
[
41-
'choice' => 'separator',
42-
'element' => ':root',
42+
'choice' => 'separator',
43+
'element' => ':root',
4344
'property' => '--c-footer-subfooter-color-separator',
44-
]
45-
]
45+
],
46+
],
4647
]);
4748

4849
CustomizerField::addField([
49-
'type' => 'select',
50-
'settings' => 'footer_subfooter_logotype',
51-
'label' => esc_html__('Logotype', 'municipio'),
52-
'section' => $sectionID,
50+
'type' => 'select',
51+
'settings' => 'footer_subfooter_logotype',
52+
'label' => esc_html__('Logotype', 'municipio'),
53+
'section' => $sectionID,
5354
'transport' => 'refresh',
54-
'default' => 'hide',
55-
'choices' => [
56-
'hide' => __('None', 'municipio'),
55+
'default' => 'hide',
56+
'choices' => [
57+
'hide' => __('None', 'municipio'),
5758
'standard' => __('Primary', 'municipio'),
5859
'negative' => __('Secondary', 'municipio'),
59-
'custom' => __('Custom', 'municipio')
60+
'custom' => __('Custom', 'municipio'),
6061
],
61-
'output' => [
62-
['type' => 'controller']
62+
'output' => [
63+
['type' => 'controller'],
6364
],
6465
]);
6566

6667
CustomizerField::addField([
67-
'type' => 'upload',
68-
'settings' => 'footer_subfooter_custom_logotype',
69-
'label' => esc_html__('Upload SVG logo', 'municipio'),
70-
'description' => 'Upload a custom .svg file to use as logo.',
71-
'section' => $sectionID,
72-
'priority' => 10,
73-
'transport' => 'refresh',
68+
'type' => 'upload',
69+
'settings' => 'footer_subfooter_custom_logotype',
70+
'label' => esc_html__('Upload SVG logo', 'municipio'),
71+
'description' => 'Upload a custom .svg file to use as logo.',
72+
'section' => $sectionID,
73+
'priority' => 10,
74+
'transport' => 'refresh',
7475
'active_callback' => [
7576
[
76-
'setting' => 'footer_subfooter_logotype',
77+
'setting' => 'footer_subfooter_logotype',
7778
'operator' => '==',
78-
'value' => 'custom',
79-
]
79+
'value' => 'custom',
80+
],
81+
],
82+
'output' => [
83+
['type' => 'controller'],
8084
],
81-
'output' => [
82-
['type' => 'controller']
83-
]
8485
]);
8586

87+
/* TODO: Design */
8688
CustomizerField::addField([
87-
'type' => 'slider',
88-
'settings' => 'footer_subfooter_height_logotype',
89-
'label' => esc_html__('Logotype height', 'municipio'),
90-
'section' => $sectionID,
89+
'type' => 'slider',
90+
'settings' => 'footer_subfooter_height_logotype',
91+
'label' => esc_html__('Logotype height', 'municipio'),
92+
'section' => $sectionID,
9193
'transport' => 'auto',
92-
'default' => 6,
93-
'choices' => [
94-
'min' => 3,
95-
'max' => 24,
94+
'default' => 6,
95+
'choices' => [
96+
'min' => 3,
97+
'max' => 24,
9698
'step' => 1,
9799
],
98-
'output' => [
100+
'output' => [
99101
[
100-
'element' => ':root',
102+
'element' => ':root',
101103
'property' => '--c-footer-subfooter-height-logotype',
102-
]
104+
],
103105
],
104106
]);
105107

108+
/* TODO: Design */
106109
CustomizerField::addField([
107-
'type' => 'slider',
108-
'settings' => 'footer_subfooter_padding',
109-
'label' => esc_html__('Padding', 'municipio'),
110-
'section' => $sectionID,
110+
'type' => 'slider',
111+
'settings' => 'footer_subfooter_padding',
112+
'label' => esc_html__('Padding', 'municipio'),
113+
'section' => $sectionID,
111114
'transport' => 'auto',
112-
'default' => 3,
113-
'choices' => [
114-
'min' => 1,
115-
'max' => 24,
115+
'default' => 3,
116+
'choices' => [
117+
'min' => 1,
118+
'max' => 24,
116119
'step' => 1,
117120
],
118-
'output' => [
121+
'output' => [
119122
[
120-
'element' => ':root',
123+
'element' => ':root',
121124
'property' => '--c-footer-subfooter-padding',
122-
]
123-
],
124-
]);
125-
126-
CustomizerField::addField([
127-
'type' => 'select',
128-
'settings' => 'footer_subfooter_flex_direction',
129-
'label' => esc_html__('Direction', 'municipio'),
130-
'section' => $sectionID,
131-
'transport' => 'refresh',
132-
'default' => 'row',
133-
'choices' => [
134-
'row' => __('Horizontal', 'municipio'),
135-
'column' => __('Vertical', 'municipio')
136-
],
137-
'output' => [
138-
[
139-
'element' => ':root',
140-
'property' => '--c-footer-subfooter-flex-direction',
141125
],
142-
[
143-
'type' => 'component_data',
144-
'dataKey' => 'subfooter.flexDirection',
145-
'context' => [
146-
[
147-
'context' => 'component.footer',
148-
'operator' => '==',
149-
],
150-
]
151-
]
152126
],
153127
]);
154128

155129
CustomizerField::addField([
156-
'type' => 'select',
157-
'settings' => 'footer_subfooter_alignment',
158-
'label' => esc_html__('Content alignment', 'municipio'),
159-
'section' => $sectionID,
130+
'type' => 'select',
131+
'settings' => 'footer_subfooter_alignment',
132+
'label' => esc_html__('Content alignment', 'municipio'),
133+
'section' => $sectionID,
160134
'transport' => 'refresh',
161-
'default' => 'center',
162-
'choices' => [
135+
'default' => 'center',
136+
'choices' => [
163137
'flex-start' => __('Left', 'municipio'),
164-
'center' => __('Center', 'municipio'),
165-
'flex-end' => __('Right', 'municipio')
138+
'center' => __('Center', 'municipio'),
139+
'flex-end' => __('Right', 'municipio'),
166140
],
167-
'output' => [
141+
'output' => [
168142
[
169-
'element' => ':root',
143+
'element' => ':root',
170144
'property' => '--c-footer-subfooter-alignment',
171145
],
172146
[
173-
'type' => 'component_data',
147+
'type' => 'component_data',
174148
'dataKey' => 'subfooter.alignment',
175149
'context' => [
176150
[
177-
'context' => 'component.footer',
151+
'context' => 'component.footer',
178152
'operator' => '==',
179153
],
180-
]
181-
]
154+
],
155+
],
182156
],
183157
]);
184158

185159
CustomizerField::addField([
186-
'type' => 'repeater',
187-
'settings' => 'footer_subfooter_content',
188-
'label' => esc_html__('Content', 'municipio'),
189-
'section' => $sectionID,
190-
'transport' => 'auto',
191-
'fields' => [
192-
'title' => [
193-
'type' => 'text',
194-
'label' => esc_html__('Title', 'muncipio'),
160+
'type' => 'repeater',
161+
'settings' => 'footer_subfooter_content',
162+
'label' => esc_html__('Content', 'municipio'),
163+
'section' => $sectionID,
164+
'transport' => 'refresh',
165+
'fields' => [
166+
'title' => [
167+
'type' => 'text',
168+
'label' => esc_html__('Title', 'muncipio'),
195169
'default' => '',
196170
],
197171
'content' => [
198-
'type' => 'text',
199-
'label' => esc_html__('Text', 'muncipio'),
172+
'type' => 'text',
173+
'label' => esc_html__('Text', 'muncipio'),
200174
'default' => '',
201175
],
202-
'link' => [
203-
'type' => 'url',
204-
'label' => esc_html__('Link', 'muncipio'),
176+
'link' => [
177+
'type' => 'url',
178+
'label' => esc_html__('Link', 'muncipio'),
205179
'default' => '',
206180
],
207181
],
208-
'output' => [
182+
'output' => [
209183
[
210-
'type' => 'component_data',
184+
'type' => 'component_data',
211185
'dataKey' => 'subfooter.content',
212186
'context' => [
213187
[
214-
'context' => 'component.footer',
188+
'context' => 'component.footer',
215189
'operator' => '==',
216190
],
217-
]
218-
]
219-
]
191+
],
192+
],
193+
],
220194
]);
221195
}
222196
}
Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
<?php
2+
3+
namespace Municipio\Customizer\Sections\Component;
4+
5+
use Municipio\Customizer\PanelsRegistry;
6+
use PHPUnit\Framework\Attributes\TestDox;
7+
use PHPUnit\Framework\TestCase;
8+
9+
class FooterSubTest extends TestCase
10+
{
11+
protected function setUp(): void
12+
{
13+
PanelsRegistry::getInstance()->fields = [];
14+
}
15+
16+
#[TestDox('Footer sub content repeater refreshes the preview when component data changes')]
17+
public function testFooterSubContentRepeaterRefreshesPreviewWhenComponentDataChanges(): void
18+
{
19+
new FooterSub('municipio_customizer_section_component_footer_subfooter');
20+
21+
$fields = PanelsRegistry::getInstance()->getRegisteredFields();
22+
$contentField = $this->getFieldBySettings($fields, 'footer_subfooter_content');
23+
24+
$this->assertSame('repeater', $contentField['type']);
25+
$this->assertSame('refresh', $contentField['transport']);
26+
$this->assertSame('component_data', $contentField['output'][0]['type']);
27+
$this->assertSame('subfooter.content', $contentField['output'][0]['dataKey']);
28+
}
29+
30+
/**
31+
* Get a registered Customizer field by its setting identifier.
32+
*
33+
* @param array<int, array<string, mixed>> $fields Registered fields.
34+
* @param string $settings Setting identifier.
35+
*
36+
* @return array<string, mixed>
37+
*/
38+
private function getFieldBySettings(array $fields, string $settings): array
39+
{
40+
foreach ($fields as $field) {
41+
if (($field['settings'] ?? null) === $settings) {
42+
return $field;
43+
}
44+
}
45+
46+
$this->fail(sprintf('Expected field with settings "%s" to be registered.', $settings));
47+
}
48+
}

0 commit comments

Comments
 (0)