-
-
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 (#3796)
* New Trait for decoding attribute in images * Update comments info * decoding default in system/config/system.yaml and system/blueprints/config/system.yaml for the images.defaults.decoding value * Fixed predefined option in the decoding attribute
- Loading branch information
pmoreno.rodriguez
authored
Feb 3, 2024
1 parent
cd2a7d8
commit ad8b1b7
Showing
4 changed files
with
54 additions
and
0 deletions.
There are no files selected for viewing
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
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
40 changes: 40 additions & 0 deletions
40
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,40 @@ | ||
<?php | ||
|
||
/** | ||
* @package Grav\Common\Media | ||
* @author Pedro Moreno https://github.com/pmoreno-rodriguez | ||
* @license MIT License; see LICENSE file for details. | ||
*/ | ||
|
||
namespace Grav\Common\Media\Traits; | ||
|
||
use Grav\Common\Grav; | ||
|
||
/** | ||
* Trait ImageDecodingTrait | ||
* @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) | ||
{ | ||
if (null === $value) { | ||
$value = Grav::instance()['config']->get('system.images.defaults.decoding', 'auto'); | ||
} | ||
|
||
// Validate the provided value (similar to loading) | ||
if ($value !== null && $value !== 'auto') { | ||
$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