From ed793b1cd67196b9f5658b50f9b207296ef85956 Mon Sep 17 00:00:00 2001 From: Daniel Berthereau Date: Mon, 17 Dec 2018 00:00:00 +0100 Subject: [PATCH] Added a link to display the resource in public view from the admin pages (omeka/omeka-s#1259). --- README.md | 3 + config/module.config.php | 1 + .../ViewHelper/PublicResourceUrlFactory.php | 25 ++++++ src/View/Helper/PublicResourceUrl.php | 43 +++++++++ view/omeka/admin/item-set/show.phtml | 86 ++++++++++++++++++ view/omeka/admin/item/show.phtml | 88 +++++++++++++++++++ view/omeka/admin/media/show.phtml | 85 ++++++++++++++++++ 7 files changed, 331 insertions(+) create mode 100644 src/Service/ViewHelper/PublicResourceUrlFactory.php create mode 100644 src/View/Helper/PublicResourceUrl.php create mode 100644 view/omeka/admin/item-set/show.phtml create mode 100644 view/omeka/admin/item/show.phtml create mode 100644 view/omeka/admin/media/show.phtml diff --git a/README.md b/README.md index aa04f04..39c6df0 100644 --- a/README.md +++ b/README.md @@ -21,6 +21,8 @@ This is an equivalent for the [shortcode as a page] in Omeka classic too. Display direct links to the current resource in the public user bar in order to simplify edition and management of resources (fix [#1283]). +The revert links are available too. They display the resource in the default +site, or in the first one (fix [#1259]). #### Random order of resources @@ -148,6 +150,7 @@ Copyright [shortcode as a page]: https://github.com/omeka/plugin-SimplePages/pull/24 [#1156]: https://github.com/omeka/omeka-s/issues/1156 [#1258]: https://github.com/omeka/omeka-s/issues/1258 +[#1259]: https://github.com/omeka/omeka-s/issues/1259 [#1274]: https://github.com/omeka/omeka-s/issues/1274 [#1276]: https://github.com/omeka/omeka-s/issues/1276 [#1281]: https://github.com/omeka/omeka-s/issues/1281 diff --git a/config/module.config.php b/config/module.config.php index d8e71f9..dfe5948 100644 --- a/config/module.config.php +++ b/config/module.config.php @@ -18,6 +18,7 @@ 'factories' => [ 'defaultSiteSlug' => Service\ViewHelper\DefaultSiteSlugFactory::class, 'logger' => Service\ViewHelper\LoggerFactory::class, + 'publicResourceUrl' => Service\ViewHelper\PublicResourceUrlFactory::class, ], ], 'block_layouts' => [ diff --git a/src/Service/ViewHelper/PublicResourceUrlFactory.php b/src/Service/ViewHelper/PublicResourceUrlFactory.php new file mode 100644 index 0000000..171fbbf --- /dev/null +++ b/src/Service/ViewHelper/PublicResourceUrlFactory.php @@ -0,0 +1,25 @@ +get('ViewHelperManager')->get('defaultSiteSlug'); + return new PublicResourceUrl($defaultSiteSlug()); + } +} diff --git a/src/View/Helper/PublicResourceUrl.php b/src/View/Helper/PublicResourceUrl.php new file mode 100644 index 0000000..d52f6d3 --- /dev/null +++ b/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/view/omeka/admin/item-set/show.phtml b/view/omeka/admin/item-set/show.phtml new file mode 100644 index 0000000..e7f6f6b --- /dev/null +++ b/view/omeka/admin/item-set/show.phtml @@ -0,0 +1,86 @@ +plugin('translate'); +$escape = $this->plugin('escapeHtml'); +$this->htmlElement('body')->appendAttribute('class', 'item-sets show'); +$viewItemsLink = $this->url( + 'admin/default', + ['controller' => 'item', 'action' => 'browse'], + [ + 'query' => [ + 'item_set_id' => $itemSet->id() + ] + ] +); +if ($owner = $itemSet->owner()) { + $ownerText = $escape($itemSet->owner()->name()); +} else { + $ownerText = $translate('[no owner]'); +} + +$sectionNavs = [ + 'item-set-metadata' => $translate('Metadata'), + 'item-set-linked' => $translate('Linked resources'), +]; +?> + +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']); ?> + + +
+ +sectionNav($sectionNavs, 'view.show.section_nav', $itemSet); ?> + +
+ resourceClass()): ?> +
+

+
resourceClass()->label()); ?>
+
+ + displayValues(); ?> +
+ +
+ params()->fromQuery('page', 1); + $property = $this->params()->fromQuery('property'); + $subjectValues = $itemSet->displaySubjectValues($page, 25); + ?> + +

+ + +
+

+
+ +
+ + + + +trigger('view.show.after'); ?> diff --git a/view/omeka/admin/item/show.phtml b/view/omeka/admin/item/show.phtml new file mode 100644 index 0000000..de42e12 --- /dev/null +++ b/view/omeka/admin/item/show.phtml @@ -0,0 +1,88 @@ +plugin('translate'); +$escape = $this->plugin('escapeHtml'); +$this->htmlElement('body')->appendAttribute('class', 'items show'); +if ($owner = $item->owner()) { + $ownerText = $escape($item->owner()->name()); +} else { + $ownerText = $translate('[no owner]'); +} + +$sectionNavs = [ + 'item-metadata' => $translate('Metadata'), + 'item-linked' => $translate('Linked resources'), +]; +?> +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']); ?> + +
+ +sectionNav($sectionNavs, 'view.show.section_nav', $item); ?> + +
+ resourceClass()): ?> +
+

+
resourceClass()->label())); ?>
+
+ + displayValues(); ?> +
+ +
+ params()->fromQuery('page', 1); + $property = $this->params()->fromQuery('property'); + $subjectValues = $item->displaySubjectValues($page, 25, $property); + ?> + +

+ + +
+

+
+ +
+ + + +trigger('view.show.after'); ?> diff --git a/view/omeka/admin/media/show.phtml b/view/omeka/admin/media/show.phtml new file mode 100644 index 0000000..66fa0d6 --- /dev/null +++ b/view/omeka/admin/media/show.phtml @@ -0,0 +1,85 @@ +plugin('translate'); +$escape = $this->plugin('escapeHtml'); +$this->htmlElement('body')->appendAttribute('class', 'media show'); + +$sectionNavs = [ + 'media-metadata' => $translate('Metadata'), +]; +?> + +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); ?> + +
+ render(); ?> + resourceClass()): ?> +
+

+
resourceClass()->label(); ?>
+
+ + displayValues(); ?> +
+ + + +trigger('view.show.after'); ?>