diff --git a/README.md b/README.md index 87877b6..335a0f4 100644 --- a/README.md +++ b/README.md @@ -510,6 +510,7 @@ Tab::make('Tab 1'), Tab::make('Tab 2'), Tab::make('Tab 3') ->placement('top') // top, left + ->selected() // specify which tab should be selected by default ->endpoint(), // This will make a break in the tabs and create a new group of tabs ``` diff --git a/examples/gutenberg-block.php b/examples/gutenberg-block.php index cf2c182..0d5b997 100644 --- a/examples/gutenberg-block.php +++ b/examples/gutenberg-block.php @@ -14,9 +14,9 @@ 'fields' => [ PostObject::make('Employee') ->postTypes(['employee']) - ->format('object') + ->format('object'), ], 'location' => [ - Location::where('block', 'acf/employee') + Location::where('block', 'acf/employee'), ], ]); diff --git a/src/Fields/Field.php b/src/Fields/Field.php index 56de4d3..6de20e5 100644 --- a/src/Fields/Field.php +++ b/src/Fields/Field.php @@ -82,7 +82,7 @@ public function key(string $key): static { if (!str_starts_with($key, $this->keyPrefix . '_')) { throw new InvalidArgumentException( - sprintf('The key should have the prefix [%s_].', $this->keyPrefix) + sprintf('The key should have the prefix [%s_].', $this->keyPrefix), ); } @@ -111,21 +111,21 @@ public function get(string|null $parentKey = null): array if (isset($this->settings['conditional_logic'])) { $this->settings['conditional_logic'] = array_map( fn($rules) => $rules->get($parentKey), - $this->settings['conditional_logic'] + $this->settings['conditional_logic'], ); } if (isset($this->settings['layouts'])) { $this->settings['layouts'] = array_map( fn($layout) => $layout->get($key), - $this->settings['layouts'] + $this->settings['layouts'], ); } if (isset($this->settings['sub_fields'])) { $this->settings['sub_fields'] = array_map( fn($field) => $field->get($key), - $this->settings['sub_fields'] + $this->settings['sub_fields'], ); } diff --git a/src/Fields/Settings/ConditionalLogic.php b/src/Fields/Settings/ConditionalLogic.php index dfe1c74..4312f12 100644 --- a/src/Fields/Settings/ConditionalLogic.php +++ b/src/Fields/Settings/ConditionalLogic.php @@ -19,7 +19,7 @@ public function conditionalLogic(array $rules): static { $this->settings['conditional_logic'] = array_merge( $this->settings['conditional_logic'] ?? [], - $rules + $rules, ); return $this; diff --git a/src/Fields/Settings/Wrapper.php b/src/Fields/Settings/Wrapper.php index f5c3e60..4d125c3 100644 --- a/src/Fields/Settings/Wrapper.php +++ b/src/Fields/Settings/Wrapper.php @@ -19,7 +19,7 @@ public function wrapper(array $wrapper): static { $this->settings['wrapper'] = array_merge( $this->settings['wrapper'] ?? [], - $wrapper + $wrapper, ); return $this; diff --git a/src/Fields/Tab.php b/src/Fields/Tab.php index 7b9a357..b11c15e 100644 --- a/src/Fields/Tab.php +++ b/src/Fields/Tab.php @@ -38,4 +38,11 @@ public function placement(string $placement): static return $this; } + + public function selected(): static + { + $this->settings['selected'] = true; + + return $this; + } } diff --git a/src/Fields/WYSIWYGEditor.php b/src/Fields/WYSIWYGEditor.php index e3e59f2..33326da 100644 --- a/src/Fields/WYSIWYGEditor.php +++ b/src/Fields/WYSIWYGEditor.php @@ -73,7 +73,7 @@ public function toolbar(string|array $toolbar): static $this->settings['toolbar'] = implode('_', $toolbar); add_filter('acf/fields/wysiwyg/toolbars', function ( - array $toolbars + array $toolbars, ) use ($toolbar) { $toolbars[$this->settings['toolbar']] = [ 1 => $toolbar, diff --git a/tests/ConditionalLogicTest.php b/tests/ConditionalLogicTest.php index d9f12a2..fd2701d 100644 --- a/tests/ConditionalLogicTest.php +++ b/tests/ConditionalLogicTest.php @@ -29,7 +29,7 @@ public function testConditionalLogic() 'field' => 'field_f5456193', 'operator' => '==', 'value' => 10, - ] + ], ]; $this->assertSame($conditionalLogic, ConditionalLogic::where('age', '==', 10)->get('field')); @@ -59,14 +59,14 @@ public function testResolvedParentKey() ->conditionalLogic([ ConditionalLogic::where('select', '==', 'red'), ]), - ]) + ]), ], - 'location' => [] + 'location' => [], ]); $this->assertSame( $settings['fields'][0]['key'], - $settings['fields'][1]['sub_fields'][0]['conditional_logic'][0][0]['field'] + $settings['fields'][1]['sub_fields'][0]['conditional_logic'][0][0]['field'], ); } @@ -84,16 +84,16 @@ public function testFieldKey() name: 'select', operator: '==', value: 'red', - key: 'field_123abc' + key: 'field_123abc', ), ]), ], - 'location' => [] + 'location' => [], ]); $this->assertSame( 'field_123abc', - $settings['fields'][1]['conditional_logic'][0][0]['field'] + $settings['fields'][1]['conditional_logic'][0][0]['field'], ); } } diff --git a/tests/Fields/Settings/ConditionalLogic.php b/tests/Fields/Settings/ConditionalLogic.php index 0f50e43..7657260 100644 --- a/tests/Fields/Settings/ConditionalLogic.php +++ b/tests/Fields/Settings/ConditionalLogic.php @@ -23,7 +23,7 @@ public function testConditionalLogicExternalGroup() group: 'external', name: 'type', operator: '==empty', - ) + ), ])->get('group'); $this->assertSame('field_21649737', $field['conditional_logic'][0][0]['field']); } @@ -32,7 +32,7 @@ public function testConditionalLogicAnd() { $field = $this->make('Conditional Logic And') ->conditionalLogic([ - \Extended\ACF\ConditionalLogic::where('type', '==', 'video')->and('highlight', '!=', 'true') + \Extended\ACF\ConditionalLogic::where('type', '==', 'video')->and('highlight', '!=', 'true'), ])->get('group'); $this->assertSame('==', $field['conditional_logic'][0][0]['operator']); diff --git a/tests/Fields/TabTest.php b/tests/Fields/TabTest.php index 23210e7..126dca8 100644 --- a/tests/Fields/TabTest.php +++ b/tests/Fields/TabTest.php @@ -36,4 +36,10 @@ public function testPlacement() Tab::make('Invalid Placement')->placement('test')->get(); } + + public function testSelected() + { + $field = Tab::make('Selected')->selected()->get(); + $this->assertTrue($field['selected']); + } }