diff --git a/README.md b/README.md index 20320701..682a572c 100644 --- a/README.md +++ b/README.md @@ -271,8 +271,10 @@ use Extended\ACF\Fields\Gallery; Gallery::make('Images') ->instructions('Add the gallery images.') ->mimeTypes(['jpg', 'jpeg', 'png']) - ->height(500, 1400) - ->width(1000, 2000) + ->minHeight(500) + ->maxHeight(1400) + ->minWidth(1000) + ->maxWidth(2000) ->min(1) ->max(6) ->minSize('400 KB') @@ -291,8 +293,10 @@ use Extended\ACF\Fields\Image; Image::make('Background Image') ->instructions('Add an image in at least 12000x100px and only in the formats **jpg**, **jpeg** or **png**.') ->mimeTypes(['jpg', 'jpeg', 'png']) - ->height(500, 1400) - ->width(1000, 2000) + ->minHeight(500) + ->maxHeight(1400) + ->minWidth(1000) + ->maxWidth(2000) ->minSize('400 KB') ->maxSize(5) // MB if entered as int ->library('all') // all, uploadedTo @@ -867,28 +871,42 @@ The upgrade guide provides information about the breaking changes in the package +Image::make('Background')->minSize('400 KB')->maxSize(5) ``` -9\. The `CharacterLimit` trait has been renamed to `MaxLength`. +9\. The `height` method has been split into two methods `minHeight` and `maxHeight`. + +```diff +-Gallery::make('Background')->height(100, 1000) ++Gallery::make('Background')->minHeight(100)->maxHeight(1000) +``` + +10\. The `width` method has been split into two methods `minWidth` and `maxWidth`. + +```diff +-Gallery::make('Background')->width(100, 1000) ++Gallery::make('Background')->minWidth(100)->maxWidth(1000) +``` + +11\. The `CharacterLimit` trait has been renamed to `MaxLength`. ```diff -use Extended\ACF\Fields\Settings\CharacterLimit; +use Extended\ACF\Fields\Settings\MaxLength; ``` -10\. The `Pending` trait has been renamed to `Affixable`. +12\. The `Pending` trait has been renamed to `Affixable`. ```diff -use Extended\ACF\Fields\Settings\Pending; +use Extended\ACF\Fields\Settings\Affixable; ``` -11\. The `Writable` trait has been renamed to `Immutable`. +13\. The `Writable` trait has been renamed to `Immutable`. ```diff -use Extended\ACF\Fields\Settings\Writable; +use Extended\ACF\Fields\Settings\Immutable; ``` -12\. The `SubFields` trait has been renamed to `Fields`. +14\. The `SubFields` trait has been renamed to `Fields`. ```diff -use Extended\ACF\Fields\Settings\SubFields; diff --git a/src/Fields/Settings/Dimensions.php b/src/Fields/Settings/Dimensions.php index 75058272..02da51b2 100644 --- a/src/Fields/Settings/Dimensions.php +++ b/src/Fields/Settings/Dimensions.php @@ -15,28 +15,30 @@ trait Dimensions { - public function height(int|null $min = null, int|null $max = null): static + public function maxHeight(int $max): static { - if ($min !== null) { - $this->settings['min_height'] = $min; - } + $this->settings['max_height'] = $max; - if ($max !== null) { - $this->settings['max_height'] = $max; - } + return $this; + } + + public function minHeight(int $min): static + { + $this->settings['min_height'] = $min; return $this; } - public function width(int|null $min = null, int|null $max = null): static + public function maxWidth(int $max): static { - if ($min !== null) { - $this->settings['min_width'] = $min; - } + $this->settings['max_width'] = $max; - if ($max !== null) { - $this->settings['max_width'] = $max; - } + return $this; + } + + public function minWidth(int $min): static + { + $this->settings['min_width'] = $min; return $this; } diff --git a/tests/Fields/GalleryTest.php b/tests/Fields/GalleryTest.php index 4f646bd0..b3e50a88 100644 --- a/tests/Fields/GalleryTest.php +++ b/tests/Fields/GalleryTest.php @@ -36,29 +36,27 @@ public function testInsert() Gallery::make('Invalid Insert')->insert('test')->get(); } - public function testHeight() + public function testMaxHeight() { - $field = Gallery::make('Height')->height(10, 20)->get(); - $this->assertSame(10, $field['min_height']); + $field = Gallery::make('Gallery Max Height')->maxHeight(20)->get(); $this->assertSame(20, $field['max_height']); - - $field = Gallery::make('Min Height')->height(30)->get(); - $this->assertArrayNotHasKey('max_height', $field); - - $field = Gallery::make('Max Height')->height(null, 40)->get(); - $this->assertArrayNotHasKey('min_height', $field); } - public function testWidth() + public function testMinHeight() { - $field = Gallery::make('Width')->width(10, 20)->get(); - $this->assertSame(10, $field['min_width']); - $this->assertSame(20, $field['max_width']); + $field = Gallery::make('Gallery Min Height')->minHeight(10)->get(); + $this->assertSame(10, $field['min_height']); + } - $field = Gallery::make('Min Width')->width(30)->get(); - $this->assertArrayNotHasKey('max_width', $field); + public function testMaxWidth() + { + $field = Gallery::make('Gallery Max Width')->maxWidth(40)->get(); + $this->assertSame(40, $field['max_width']); + } - $field = Gallery::make('Max Width')->width(null, 40)->get(); - $this->assertArrayNotHasKey('min_width', $field); + public function testMinWidth() + { + $field = Gallery::make('Gallery Min Width')->minWidth(30)->get(); + $this->assertSame(30, $field['min_width']); } }