Skip to content

Commit

Permalink
Added a button to link to the public page of a resource.
Browse files Browse the repository at this point in the history
  • Loading branch information
Daniel-KM committed Oct 27, 2019
1 parent 41f8f4b commit 79fcfc8
Show file tree
Hide file tree
Showing 6 changed files with 82 additions and 0 deletions.
1 change: 1 addition & 0 deletions application/config/module.config.php
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
33 changes: 33 additions & 0 deletions application/src/Service/ViewHelper/PublicResourceUrlFactory.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
<?php
namespace Omeka\Service\ViewHelper;

use Interop\Container\ContainerInterface;
use Omeka\View\Helper\PublicResourceUrl;
use Zend\ServiceManager\Factory\FactoryInterface;

/**
* Service factory for the PublicResourceUrlFactory view helper.
*
* @todo Set a setting for the default site of the user.
*/
class PublicResourceUrlFactory implements FactoryInterface
{
/**
* Create and return the PublicResourceUrlFactory view helper
*
* @return PublicResourceUrlFactory
*/
public function __invoke(ContainerInterface $services, $requestedName, array $options = null)
{
// Get the slug for the default site, else the first one.
$defaultSiteId = $services->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);
}
}
43 changes: 43 additions & 0 deletions application/src/View/Helper/PublicResourceUrl.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
<?php
namespace Omeka\View\Helper;

use Omeka\Api\Representation\AbstractResourceRepresentation;
use Zend\View\Helper\AbstractHelper;

/**
* View helper to return the url to the public default site page of a resource.
*/
class PublicResourceUrl extends AbstractHelper
{
/**
* @var string
*/
protected $defaultSiteSlug;

/**
* Construct the helper.
*
* @param string|null $defaultSiteSlug
*/
public function __construct($defaultSiteSlug)
{
$this->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)
: '';
}
}
1 change: 1 addition & 0 deletions application/view/omeka/admin/item-set/show.phtml
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ $sectionNavs = [
<?php echo $this->pageTitle($itemSet->displayTitle(), 1, $translate('Item sets')); ?>

<div id="page-actions">
<?php echo $this->hyperlink($translate('Public view'), $this->publicResourceUrl($itemSet), ['class' => 'button', 'target' => '_blank']); ?>
<?php if ($itemSet->userIsAllowed('update')): ?>
<?php echo $itemSet->link($translate('Edit item set'), 'edit', ['class' => 'button']); ?>
<?php endif; ?>
Expand Down
1 change: 1 addition & 0 deletions application/view/omeka/admin/item/show.phtml
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ $itemMedia = $item->media();
?>
<?php echo $this->pageTitle($item->displayTitle(), 1, $translate('Items')); ?>
<div id="page-actions">
<?php echo $this->hyperlink($translate('Public view'), $this->publicResourceUrl($item), ['class' => 'button', 'target' => '_blank']); ?>
<?php if ($item->userIsAllowed('update')): ?>
<?php echo $item->link($translate('Edit item'), 'edit', ['class' => 'button']); ?>
<?php endif; ?>
Expand Down
3 changes: 3 additions & 0 deletions application/view/omeka/admin/media/show.phtml
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,10 @@ $sectionNavs = [
<?php echo $this->pageTitle($media->displayTitle(), 1, $translate('Media')); ?>

<div id="page-actions">
<?php echo $this->hyperlink($translate('Public view'), $this->publicResourceUrl($media), ['class' => 'button', 'target' => '_blank']); ?>
<?php if ($media->userIsAllowed('update')): ?>
<?php echo $media->link($translate('Edit media'), 'edit', ['class' => 'button']); ?>
<?php endif; ?>
</div>

<?php echo $this->sectionNav($sectionNavs, 'view.show.section_nav', $media); ?>
Expand Down

0 comments on commit 79fcfc8

Please sign in to comment.