-
Notifications
You must be signed in to change notification settings - Fork 140
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added a button to link to the public page of a resource.
- Loading branch information
Showing
6 changed files
with
82 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
33 changes: 33 additions & 0 deletions
33
application/src/Service/ViewHelper/PublicResourceUrlFactory.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) | ||
: ''; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters