Skip to content

Commit

Permalink
Merge pull request #14 from visuellverstehen/13-custom-alt-text-logic
Browse files Browse the repository at this point in the history
Make param handling overwritable
  • Loading branch information
simonerd authored Feb 26, 2024
2 parents b15a570 + da0036b commit 948dfc5
Showing 1 changed file with 39 additions and 25 deletions.
64 changes: 39 additions & 25 deletions src/Tags/Picture.php
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,41 @@ public function __call($method, $args): string

return $this->output($asset);
}

protected function handleAltText(Picturesque &$picture)
{
// if no param is set, the asset will be checked for an alt text
if ($alt = $this->params->get('alt')) {
$picture->alt($alt);
}
}

protected function handleCssClasses(Picturesque &$picture)
{
if ($class = $this->params->get('class')) {
$picture->css($class);
}
}

protected function handleLazyLoading(Picturesque &$picture)
{
// if no param is set, config default is used
if ($this->params->has('lazy')) {
if ($this->params->get('lazy') == false) {
$picture->lazy(false);
}
else {
$picture->lazy(true);
}
}
}

protected function handleWrapperCssClasses(Picturesque &$picture)
{
if ($wrapperClass = $this->params->get('wrapperClass')) {
$picture->wrapperClass($wrapperClass);
}
}

protected function output($asset)
{
Expand Down Expand Up @@ -109,31 +144,10 @@ protected function output($asset)
}
}

// alt tag
// if no param is set, the asset will be checked for an alt text
if ($alt = $this->params->get('alt')) {
$picture->alt($alt);
}

// css classes
if ($class = $this->params->get('class')) {
$picture->css($class);
}

if ($wrapperClass = $this->params->get('wrapperClass')) {
$picture->wrapperClass($wrapperClass);
}

// lazy loading
// if no param is set, config default is used
if ($this->params->has('lazy')) {
if ($this->params->get('lazy') == false) {
$picture->lazy(false);
}
else {
$picture->lazy(true);
}
}
$this->handleAltText($picture);
$this->handleCssClasses($picture);
$this->handleWrapperCssClasses($picture);
$this->handleLazyLoading($picture);

$picture->generate();

Expand Down

0 comments on commit 948dfc5

Please sign in to comment.