forked from getgrav/grav
-
Notifications
You must be signed in to change notification settings - Fork 0
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 fetchPriority attribute in images (getgrav#3850)
- Loading branch information
1 parent
c55f2be
commit 346d194
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/ImageFetchPriorityTrait.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 ImageFetchPriorityTrait | ||
* @package Grav\Common\Media\Traits | ||
*/ | ||
|
||
trait ImageFetchPriorityTrait | ||
{ | ||
/** | ||
* Allows to set the fetchpriority attribute from Markdown or Twig | ||
* | ||
* @param string|null $value | ||
* @return $this | ||
*/ | ||
public function fetchpriority($value = null) | ||
{ | ||
if (null === $value) { | ||
$value = Grav::instance()['config']->get('system.images.defaults.fetchpriority', 'auto'); | ||
} | ||
|
||
// Validate the provided value (similar to loading and decoding attributes) | ||
if ($value !== null && $value !== 'auto') { | ||
$this->attributes['fetchpriority'] = $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