From 79fcfc8673efac5618c558fb42f184d8b0044ad7 Mon Sep 17 00:00:00 2001 From: Daniel Berthereau Date: Mon, 21 May 2018 00:00:00 +0200 Subject: [PATCH] Added a button to link to the public page of a resource. --- application/config/module.config.php | 1 + .../ViewHelper/PublicResourceUrlFactory.php | 33 ++++++++++++++ .../src/View/Helper/PublicResourceUrl.php | 43 +++++++++++++++++++ .../view/omeka/admin/item-set/show.phtml | 1 + application/view/omeka/admin/item/show.phtml | 1 + application/view/omeka/admin/media/show.phtml | 3 ++ 6 files changed, 82 insertions(+) create mode 100644 application/src/Service/ViewHelper/PublicResourceUrlFactory.php create mode 100644 application/src/View/Helper/PublicResourceUrl.php diff --git a/application/config/module.config.php b/application/config/module.config.php index 030fc08fbc..96b56f7b29 100644 --- a/application/config/module.config.php +++ b/application/config/module.config.php @@ -418,6 +418,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')); ?>
+ hyperlink($translate('Public view'), $this->publicResourceUrl($itemSet), ['class' => 'button', 'target' => '_blank']); ?> userIsAllowed('update')): ?> link($translate('Edit item set'), 'edit', ['class' => 'button']); ?> diff --git a/application/view/omeka/admin/item/show.phtml b/application/view/omeka/admin/item/show.phtml index 563e54798f..8292e33667 100644 --- a/application/view/omeka/admin/item/show.phtml +++ b/application/view/omeka/admin/item/show.phtml @@ -17,6 +17,7 @@ $itemMedia = $item->media(); ?> pageTitle($item->displayTitle(), 1, $translate('Items')); ?>
+ hyperlink($translate('Public view'), $this->publicResourceUrl($item), ['class' => 'button', 'target' => '_blank']); ?> userIsAllowed('update')): ?> link($translate('Edit item'), 'edit', ['class' => 'button']); ?> diff --git a/application/view/omeka/admin/media/show.phtml b/application/view/omeka/admin/media/show.phtml index 7947bd764c..66fa0d6a2f 100644 --- a/application/view/omeka/admin/media/show.phtml +++ b/application/view/omeka/admin/media/show.phtml @@ -11,7 +11,10 @@ $sectionNavs = [ pageTitle($media->displayTitle(), 1, $translate('Media')); ?>
+ hyperlink($translate('Public view'), $this->publicResourceUrl($media), ['class' => 'button', 'target' => '_blank']); ?> + userIsAllowed('update')): ?> link($translate('Edit media'), 'edit', ['class' => 'button']); ?> +
sectionNav($sectionNavs, 'view.show.section_nav', $media); ?>