Skip to content

Commit

Permalink
Split height and width into four methods
Browse files Browse the repository at this point in the history
  • Loading branch information
vinkla committed Oct 19, 2023
1 parent a3f8e7b commit db6eff3
Show file tree
Hide file tree
Showing 3 changed files with 57 additions and 39 deletions.
34 changes: 26 additions & 8 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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')
Expand All @@ -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
Expand Down Expand Up @@ -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;
Expand Down
30 changes: 16 additions & 14 deletions src/Fields/Settings/Dimensions.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down
32 changes: 15 additions & 17 deletions tests/Fields/GalleryTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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']);
}
}

0 comments on commit db6eff3

Please sign in to comment.