File tree Expand file tree Collapse file tree 12 files changed +69
-89
lines changed Expand file tree Collapse file tree 12 files changed +69
-89
lines changed Original file line number Diff line number Diff line change @@ -368,4 +368,34 @@ public function tabIndex(int $value = 0): static
368
368
369
369
return $ this ;
370
370
}
371
+
372
+ /**
373
+ * @param string $key
374
+ * @param array|bool $value
375
+ * @return $this
376
+ */
377
+ public function setPluginAttribute (string $ key , array |bool $ value ): static
378
+ {
379
+ if (is_array ($ value )) {
380
+ $ this ->attributes [$ key ] = array_merge ((array ) ($ this ->attributes [$ key ] ?? []), $ value );
381
+ } else {
382
+ $ this ->attributes [$ key ] = $ value ;
383
+ }
384
+
385
+ return $ this ;
386
+ }
387
+
388
+ /**
389
+ * @param string $plugin
390
+ * @param string|null $key
391
+ * @return mixed
392
+ */
393
+ public function getPluginAttribute (string $ plugin , string $ key = null ): mixed
394
+ {
395
+ if (is_null ($ key )) {
396
+ return $ this ->attributes [$ plugin ] ?? true ;
397
+ }
398
+
399
+ return $ this ->attributes [$ plugin ][$ key ] ?? false ;
400
+ }
371
401
}
Original file line number Diff line number Diff line change @@ -27,19 +27,13 @@ public function autoFillAlwaysAsk(bool $value = true): static
27
27
* Set autoFill option value.
28
28
* Enable and configure the AutoFill extension for DataTables.
29
29
*
30
- * @param bool| array $value
30
+ * @param array|bool $value
31
31
* @return $this
32
32
* @see https://datatables.net/reference/option/autoFill
33
33
*/
34
- public function autoFill (bool | array $ value = true ): static
34
+ public function autoFill (array | bool $ value = true ): static
35
35
{
36
- if (is_array ($ value )) {
37
- $ this ->attributes ['autoFill ' ] = array_merge ((array ) $ this ->attributes ['autoFill ' ], $ value );
38
- } else {
39
- $ this ->attributes ['autoFill ' ] = $ value ;
40
- }
41
-
42
- return $ this ;
36
+ return $ this ->setPluginAttribute ('autoFill ' , $ value );
43
37
}
44
38
45
39
/**
Original file line number Diff line number Diff line change @@ -27,19 +27,13 @@ public function colReorderEnable(bool $value = true): static
27
27
* Set colReorder option value.
28
28
* Enable and configure the AutoFill extension for DataTables.
29
29
*
30
- * @param bool| array $value
30
+ * @param array|bool $value
31
31
* @return $this
32
32
* @see https://datatables.net/reference/option/colReorder
33
33
*/
34
- public function colReorder (bool | array $ value = true ): static
34
+ public function colReorder (array | bool $ value = true ): static
35
35
{
36
- if (is_array ($ value )) {
37
- $ this ->attributes ['colReorder ' ] = array_merge ((array ) $ this ->attributes ['colReorder ' ], $ value );
38
- } else {
39
- $ this ->attributes ['colReorder ' ] = $ value ;
40
- }
41
-
42
- return $ this ;
36
+ return $ this ->setPluginAttribute ('colReorder ' , $ value );
43
37
}
44
38
45
39
/**
Original file line number Diff line number Diff line change @@ -26,19 +26,13 @@ public function fixedColumnsHeightMatch(string $value = 'semiauto'): static
26
26
/**
27
27
* Set fixedColumns option value.
28
28
*
29
- * @param bool| array $value
29
+ * @param array|bool $value
30
30
* @return $this
31
31
* @see https://datatables.net/reference/option/fixedColumns
32
32
*/
33
- public function fixedColumns (bool | array $ value = true ): static
33
+ public function fixedColumns (array | bool $ value = true ): static
34
34
{
35
- if (is_array ($ value )) {
36
- $ this ->attributes ['fixedColumns ' ] = array_merge ((array ) $ this ->attributes ['fixedColumns ' ], $ value );
37
- } else {
38
- $ this ->attributes ['fixedColumns ' ] = $ value ;
39
- }
40
-
41
- return $ this ;
35
+ return $ this ->setPluginAttribute ('fixedColumns ' , $ value );
42
36
}
43
37
44
38
/**
Original file line number Diff line number Diff line change @@ -26,19 +26,13 @@ public function fixedHeaderFooter(bool $value = true): static
26
26
/**
27
27
* Set fixedHeader option value.
28
28
*
29
- * @param bool| array $value
29
+ * @param array|bool $value
30
30
* @return $this
31
31
* @see https://datatables.net/reference/option/fixedHeader
32
32
*/
33
- public function fixedHeader (bool | array $ value = true ): static
33
+ public function fixedHeader (array | bool $ value = true ): static
34
34
{
35
- if (is_array ($ value )) {
36
- $ this ->attributes ['fixedHeader ' ] = array_merge ((array ) $ this ->attributes ['fixedHeader ' ], $ value );
37
- } else {
38
- $ this ->attributes ['fixedHeader ' ] = $ value ;
39
- }
40
-
41
- return $ this ;
35
+ return $ this ->setPluginAttribute ('fixedHeader ' , $ value );
42
36
}
43
37
44
38
/**
Original file line number Diff line number Diff line change @@ -26,19 +26,13 @@ public function keysBlurable(bool $value = true): static
26
26
/**
27
27
* Set keys option value.
28
28
*
29
- * @param bool| array $value
29
+ * @param array|bool $value
30
30
* @return $this
31
31
* @see https://datatables.net/reference/option/keys
32
32
*/
33
- public function keys (bool | array $ value = true ): static
33
+ public function keys (array | bool $ value = true ): static
34
34
{
35
- if (is_array ($ value )) {
36
- $ this ->attributes ['keys ' ] = array_merge ((array ) $ this ->attributes ['keys ' ], $ value );
37
- } else {
38
- $ this ->attributes ['keys ' ] = $ value ;
39
- }
40
-
41
- return $ this ;
35
+ return $ this ->setPluginAttribute ('keys ' , $ value );
42
36
}
43
37
44
38
/**
Original file line number Diff line number Diff line change @@ -26,19 +26,13 @@ public function responsiveBreakpoints(array $value): static
26
26
/**
27
27
* Set responsive option value.
28
28
*
29
- * @param bool| array $value
29
+ * @param array|bool $value
30
30
* @return $this
31
31
* @see https://datatables.net/reference/option/responsive
32
32
*/
33
- public function responsive (bool | array $ value = true ): static
33
+ public function responsive (array | bool $ value = true ): static
34
34
{
35
- if (is_array ($ value )) {
36
- $ this ->attributes ['responsive ' ] = array_merge ((array ) $ this ->attributes ['responsive ' ], $ value );
37
- } else {
38
- $ this ->attributes ['responsive ' ] = $ value ;
39
- }
40
-
41
- return $ this ;
35
+ return $ this ->setPluginAttribute ('responsive ' , $ value );
42
36
}
43
37
44
38
/**
Original file line number Diff line number Diff line change @@ -26,19 +26,13 @@ public function rowGroupUpdate(string $value = 'group'): static
26
26
/**
27
27
* Set rowGroup option value.
28
28
*
29
- * @param bool| array $value
29
+ * @param array|bool $value
30
30
* @return $this
31
31
* @see https://datatables.net/reference/option/rowGroup
32
32
*/
33
- public function rowGroup (bool | array $ value = true ): static
33
+ public function rowGroup (array | bool $ value = true ): static
34
34
{
35
- if (is_array ($ value )) {
36
- $ this ->attributes ['rowGroup ' ] = array_merge ((array ) $ this ->attributes ['rowGroup ' ], $ value );
37
- } else {
38
- $ this ->attributes ['rowGroup ' ] = $ value ;
39
- }
40
-
41
- return $ this ;
35
+ return $ this ->setPluginAttribute ('rowGroup ' , $ value );
42
36
}
43
37
44
38
/**
Original file line number Diff line number Diff line change @@ -26,19 +26,13 @@ public function rowReorderDataSrc(array|int $value = 0): static
26
26
/**
27
27
* Set rowReorder option value.
28
28
*
29
- * @param bool| array $value
29
+ * @param array|bool $value
30
30
* @return $this
31
31
* @see https://datatables.net/reference/option/rowReorder
32
32
*/
33
- public function rowReorder (bool | array $ value = true ): static
33
+ public function rowReorder (array | bool $ value = true ): static
34
34
{
35
- if (is_array ($ value )) {
36
- $ this ->attributes ['rowReorder ' ] = array_merge ((array ) $ this ->attributes ['rowReorder ' ], $ value );
37
- } else {
38
- $ this ->attributes ['rowReorder ' ] = $ value ;
39
- }
40
-
41
- return $ this ;
35
+ return $ this ->setPluginAttribute ('rowReorder ' , $ value );
42
36
}
43
37
44
38
/**
Original file line number Diff line number Diff line change @@ -26,19 +26,13 @@ public function scrollerBoundaryScale(float $value = 0.5): static
26
26
/**
27
27
* Set scroller option value.
28
28
*
29
- * @param bool| array $value
29
+ * @param array|bool $value
30
30
* @return $this
31
31
* @see https://datatables.net/reference/option/scroller
32
32
*/
33
- public function scroller (bool | array $ value = true ): static
33
+ public function scroller (array | bool $ value = true ): static
34
34
{
35
- if (is_array ($ value )) {
36
- $ this ->attributes ['scroller ' ] = array_merge ((array ) $ this ->attributes ['scroller ' ], $ value );
37
- } else {
38
- $ this ->attributes ['scroller ' ] = $ value ;
39
- }
40
-
41
- return $ this ;
35
+ return $ this ->setPluginAttribute ('scroller ' , $ value );
42
36
}
43
37
44
38
/**
Original file line number Diff line number Diff line change @@ -159,19 +159,13 @@ public function selectStyleSingle(): static
159
159
/**
160
160
* Set select option value.
161
161
*
162
- * @param bool| array $value
162
+ * @param array|bool $value
163
163
* @return $this
164
164
* @see https://datatables.net/reference/option/select
165
165
*/
166
166
public function select (bool |array $ value = true ): static
167
167
{
168
- if (is_array ($ value )) {
169
- $ this ->attributes ['select ' ] = array_merge ((array ) $ this ->attributes ['select ' ], $ value );
170
- } else {
171
- $ this ->attributes ['select ' ] = $ value ;
172
- }
173
-
174
- return $ this ;
168
+ return $ this ->setPluginAttribute ('select ' , $ value );
175
169
}
176
170
177
171
/**
Original file line number Diff line number Diff line change @@ -215,4 +215,14 @@ public function it_has_internationalisation_options()
215
215
$ builder ->languageUrl ('languageUrl ' );
216
216
$ this ->assertEquals ('languageUrl ' , $ builder ->getLanguage ('url ' ));
217
217
}
218
+
219
+ /** @test */
220
+ public function it_has_plugin_attribute_getter ()
221
+ {
222
+ $ builder = $ this ->getHtmlBuilder ();
223
+
224
+ $ builder ->selectStyleSingle ();
225
+
226
+ $ this ->assertEquals (Builder::SELECT_STYLE_SINGLE , $ builder ->getPluginAttribute ('select ' , 'style ' ));
227
+ }
218
228
}
You can’t perform that action at this time.
0 commit comments