Added Media::getRoute() and Media::getRawRoute() methods to get page route if available

This commit is contained in:
Matias Griese
2022-01-11 14:34:35 +02:00
parent 55b45fcf2f
commit f8f5502c40
2 changed files with 41 additions and 0 deletions

View File

@@ -5,6 +5,7 @@
* Added support for generic `assets.link()` for external references. No pipeline support
* 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
2. [](#improved)
* Improved `Utils::download()` method to allow overrides on download name, mime and expires header
* Improved `onPageFallBackUrl` event

View File

@@ -60,6 +60,46 @@ class Media extends AbstractMedia
}
}
/**
* Return raw route to the page.
*
* @return string|null Route to the page or null if media isn't for a page.
*/
public function getRawRoute(): ?string
{
$path = $this->getPath();
if ($path) {
/** @var Pages $pages */
$pages = $this->getGrav()['pages'];
$page = $pages->get($path);
if ($page) {
return $page->rawRoute();
}
}
return null;
}
/**
* Return page route.
*
* @return string|null Route to the page or null if media isn't for a page.
*/
public function getRoute(): ?string
{
$path = $this->getPath();
if ($path) {
/** @var Pages $pages */
$pages = $this->getGrav()['pages'];
$page = $pages->get($path);
if ($page) {
return $page->route();
}
}
return null;
}
/**
* @param string $offset
* @return bool