Skip to content

Commit

Permalink
Allow width to be passed as argument
Browse files Browse the repository at this point in the history
  • Loading branch information
ptrckvzn committed Oct 1, 2021
1 parent 03e3d7f commit 4fe4a64
Showing 1 changed file with 9 additions and 26 deletions.
35 changes: 9 additions & 26 deletions src/Models/Source.php
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,8 @@ class Source implements Arrayable

protected $sizes;

protected $width;

/**
* Build a Source to be used with A17\Twill\Image\Models\Image
*
Expand All @@ -77,6 +79,7 @@ public function __construct(
$this->setImageArray();
$this->setSources($args['sources'] ?? null);
$this->setSizes($args['sizes'] ?? null);
$this->setWidth($args['width'] ?? null);
}

protected function setSources($sources)
Expand All @@ -93,24 +96,9 @@ protected function setSizes($sizes)
$this->sizes = $sizes ?? $this->preset['sizes'] ?? null;
}

/**
* Provide the width of the default crop
*
* @return int
*/
public function width(): int
protected function setWidth($width)
{
return $this->imageArray['width'];
}

/**
* Provide the height of the default crop
*
* @return int
*/
public function height(): int
{
return $this->imageArray['height'];
$this->width = $width ?? $this->preset['width'] ?? self::DEFAULT_WIDTH;
}

/**
Expand All @@ -135,7 +123,7 @@ public function caption(): string

public function defaultSrc()
{
$defaultWidth = $this->defaultWidth();
$defaultWidth = $this->width;

return $this->model->image(
$this->role,
Expand Down Expand Up @@ -264,14 +252,9 @@ protected function imageSources($mediaQueryConfig, $sourceParams = [])
return $sourcesList;
}

protected function defaultWidth()
{
return $this->preset['width'] ?? self::DEFAULT_WIDTH;
}

protected function defaultWidths()
{
$defaultWidth = $this->defaultWidth();
$defaultWidth = $this->width;

return array_filter(self::AUTO_WIDTHS, function ($width) use (
$defaultWidth
Expand Down Expand Up @@ -439,8 +422,8 @@ public function toArray()
'lqip' => $this->lqip(),
'sources' => $this->srcSets(),
'src' => $this->defaultSrc(),
'width' => $this->width(),
'height' => $this->height(),
'width' => $this->imageArray['width'],
'height' => $this->imageArray['height'],
'sizes' => $this->sizes,
'alt' => $this->alt(),
];
Expand Down

0 comments on commit 4fe4a64

Please sign in to comment.