diff --git a/application/config/module.config.php b/application/config/module.config.php index 9068e6661e..f0842f1dbe 100644 --- a/application/config/module.config.php +++ b/application/config/module.config.php @@ -407,6 +407,7 @@ 'navigationLink' => Service\ViewHelper\NavigationLinkFactory::class, 'pagination' => Service\ViewHelper\PaginationFactory::class, 'params' => Service\ViewHelper\ParamsFactory::class, + 'publicResourceUrl' => Service\ViewHelper\PublicResourceUrlFactory::class, 'setting' => Service\ViewHelper\SettingFactory::class, 'userSetting' => Service\ViewHelper\UserSettingFactory::class, 'siteSetting' => Service\ViewHelper\SiteSettingFactory::class, diff --git a/application/src/Service/ViewHelper/PublicResourceUrlFactory.php b/application/src/Service/ViewHelper/PublicResourceUrlFactory.php new file mode 100644 index 0000000000..b425dcad7e --- /dev/null +++ b/application/src/Service/ViewHelper/PublicResourceUrlFactory.php @@ -0,0 +1,33 @@ +get('Omeka\Settings')->get('default_site'); + $api = $services->get('Omeka\ApiManager'); + if ($defaultSiteId) { + $slugs = $api->search('sites', ['id' => $defaultSiteId], ['returnScalar' => 'slug'])->getContent(); + } else { + $slugs = $api->search('sites', ['limit' => 1], ['returnScalar' => 'slug'])->getContent(); + } + $defaultSiteSlug = reset($slugs); + return new PublicResourceUrl($defaultSiteSlug); + } +} diff --git a/application/src/View/Helper/PublicResourceUrl.php b/application/src/View/Helper/PublicResourceUrl.php new file mode 100644 index 0000000000..1ef6aaf400 --- /dev/null +++ b/application/src/View/Helper/PublicResourceUrl.php @@ -0,0 +1,43 @@ +defaultSiteSlug = $defaultSiteSlug; + } + + /** + * Return the url to the public default site page or a resource. + * + * @uses AbstractResourceRepresentation::siteUrl() + * + * @param AbstractResourceRepresentation $resource + * @param bool $canonical Whether to return an absolute URL + * @return string + */ + public function __invoke(AbstractResourceRepresentation $resource, $canonical = false) + { + // Manage the case where there is no site. + return $this->defaultSiteSlug + ? $resource->siteUrl($this->defaultSiteSlug, $canonical) + : ''; + } +} diff --git a/application/view/omeka/admin/item-set/show.phtml b/application/view/omeka/admin/item-set/show.phtml index 40e0c855fd..e7f6f6bd92 100644 --- a/application/view/omeka/admin/item-set/show.phtml +++ b/application/view/omeka/admin/item-set/show.phtml @@ -26,6 +26,7 @@ $sectionNavs = [ pageTitle($itemSet->displayTitle(), 1, $translate('Item sets')); ?>