-
-
Notifications
You must be signed in to change notification settings - Fork 1.4k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
New Trait for decoding attribute in images
- Loading branch information
pmoreno.rodriguez
committed
Jan 29, 2024
1 parent
cd2a7d8
commit 959acda
Showing
2 changed files
with
44 additions
and
0 deletions.
There are no files selected for viewing
42 changes: 42 additions & 0 deletions
42
system/src/Grav/Common/Media/Traits/ImageDecodingTrait.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
<?php | ||
|
||
/** | ||
* @package Grav\Common\Media | ||
* | ||
* @copyright Copyright (c) 2015 - 2024 Trilby Media, LLC. All rights reserved. | ||
* @license MIT License; see LICENSE file for details. | ||
*/ | ||
|
||
namespace Grav\Common\Media\Traits; | ||
|
||
use Grav\Common\Grav; | ||
|
||
/** | ||
* Trait ImageLoadingTrait | ||
* @package Grav\Common\Media\Traits | ||
*/ | ||
|
||
trait ImageDecodingTrait | ||
{ | ||
/** | ||
* Allows to set the decoding attribute from Markdown or Twig | ||
* | ||
* @param string|null $value | ||
* @return $this | ||
*/ | ||
public function decoding($value = null) | ||
{ | ||
$validValues = ['sync', 'async', 'auto']; | ||
|
||
if (null === $value) { | ||
$value = Grav::instance()['config']->get('system.images.defaults.decoding', 'auto'); | ||
} | ||
|
||
// Validate the provided value | ||
if ($value && in_array($value, $validValues, true)) { | ||
$this->attributes['decoding'] = $value; | ||
} | ||
|
||
return $this; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters