mirror of
https://github.com/getgrav/grav.git
synced 2025-02-20 19:56:53 +01:00
Merge branch 'develop' of github.com:getgrav/grav into develop
This commit is contained in:
commit
419692b9e4
|
|
@ -7,6 +7,7 @@
|
|||
* Added support for `assets.addJsModule()` with full pipeline support
|
||||
* Added `Utils::getExtensionsByMime()` method to get all the registered extensions for the specific mime type
|
||||
* Added `Media::getRoute()` and `Media::getRawRoute()` methods to get page route if available
|
||||
* Added `Medium::getAlternatives()` to be able to list all the retina sizes
|
||||
2. [](#improved)
|
||||
* Improved `Utils::download()` method to allow overrides on download name, mime and expires header
|
||||
* Improved `onPageFallBackUrl` event
|
||||
|
|
|
|||
|
|
@ -63,6 +63,14 @@ interface MediaObjectInterface extends \Grav\Framework\Media\Interfaces\MediaObj
|
|||
*/
|
||||
public function addAlternative($ratio, MediaObjectInterface $alternative);
|
||||
|
||||
/**
|
||||
* Get list of image alternatives. Includes the current media image as well.
|
||||
*
|
||||
* @param bool $withDerived If true, include generated images as well. If false, only return existing files.
|
||||
* @return array
|
||||
*/
|
||||
public function getAlternatives(bool $withDerived = true): array;
|
||||
|
||||
/**
|
||||
* Return string representation of the object (html).
|
||||
*
|
||||
|
|
|
|||
|
|
@ -128,11 +128,29 @@ trait MediaObjectTrait
|
|||
}
|
||||
|
||||
$alternative->set('ratio', $ratio);
|
||||
$width = $alternative->get('width');
|
||||
$width = $alternative->get('width', 0);
|
||||
|
||||
$this->alternatives[$width] = $alternative;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param bool $withDerived
|
||||
* @return array
|
||||
*/
|
||||
public function getAlternatives(bool $withDerived = true): array
|
||||
{
|
||||
$alternatives = [];
|
||||
foreach ($this->alternatives + [$this->get('width', 0) => $this] as $size => $alternative) {
|
||||
if ($withDerived || $alternative->filename === basename($alternative->filepath)) {
|
||||
$alternatives[$size] = $alternative;
|
||||
}
|
||||
}
|
||||
|
||||
ksort($alternatives, SORT_NUMERIC);
|
||||
|
||||
return $alternatives;
|
||||
}
|
||||
|
||||
/**
|
||||
* Return string representation of the object (html).
|
||||
*
|
||||
|
|
|
|||
Loading…
Reference in New Issue
Block a user