@@ -55,11 +55,6 @@ class Section {
55
55
*/
56
56
private $ type ;
57
57
58
- /**
59
- *
60
- * @var Controllable[]
61
- */
62
- private $ controllables ;
63
58
64
59
/**
65
60
* Initializing Tab.
@@ -76,12 +71,24 @@ public function __construct( $slug, $title, $description = '', $type = null ) {
76
71
$ this ->type = $ type ;
77
72
}
78
73
74
+ /**
75
+ * Add controllable items to section.
76
+ *
77
+ * @param array|null $controllables List of controllable items to add.
78
+ * @return void
79
+ */
79
80
public function add_controllables ( $ controllables ) {
80
81
if ( ! empty ( $ controllables ) ) {
81
82
$ this ->generate_fields ( $ controllables );
82
83
}
83
84
}
84
85
86
+ /**
87
+ * Generate settings fields for a list of controllable items.
88
+ *
89
+ * @param Controllable[] $controllables List of controllable items to add.
90
+ * @return void
91
+ */
85
92
private function generate_fields ( $ controllables ) {
86
93
foreach ( $ controllables as $ controllable ) {
87
94
$ label = $ controllable ::get_label ();
@@ -103,7 +110,7 @@ private function generate_fields( $controllables ) {
103
110
if ( ! empty ( $ options ) ) {
104
111
foreach ( $ options as $ option ) {
105
112
$ valid_for = isset ( $ option ['valid_for ' ] ) ? $ option ['valid_for ' ] : null ;
106
- if ( $ valid_for !== null && $ this ->type !== $ valid_for ) {
113
+ if ( null !== $ valid_for && $ this ->type !== $ valid_for ) {
107
114
continue ;
108
115
}
109
116
$ fields [] = $ this ->generate_field ( $ option , $ controllable );
@@ -117,6 +124,13 @@ private function generate_fields( $controllables ) {
117
124
}
118
125
}
119
126
127
+ /**
128
+ * Generate field for a controllable item's option.
129
+ *
130
+ * @param array $option Option name.
131
+ * @param Controllable $controllable Controllable item.
132
+ * @return Checkbox|CheckboxGroup|Inline|Select|Text|Textarea|null
133
+ */
120
134
private function generate_field ( $ option , $ controllable ) {
121
135
switch ( $ option ['type ' ] ) {
122
136
case 'input ' :
@@ -215,14 +229,14 @@ function () use ( $row ) {
215
229
/**
216
230
* Renders the fields for a row.
217
231
*
218
- * @param array $row
232
+ * @param array $row Row of fields.
219
233
*/
220
234
protected function render_row_fields ( $ row ) {
221
235
foreach ( $ row ['fields ' ] as $ key => $ field ) {
222
236
$ field ->render ();
223
237
224
238
// Add linebreak after field if not (last and not checkbox without label).
225
- if ( $ key !== count ( $ row ['fields ' ] ) - 1 ) {
239
+ if ( ( count ( $ row ['fields ' ] ) - 1 ) !== $ key ) {
226
240
if ( $ field instanceof Checkbox && empty ( $ field ->get_label () ) ) {
227
241
continue ;
228
242
}
0 commit comments