-
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.
Used a helper to get the default site slug.
- Loading branch information
Showing
4 changed files
with
73 additions
and
12 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/DefaultSiteSlugFactory.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\DefaultSiteSlug; | ||
use Zend\ServiceManager\Factory\FactoryInterface; | ||
|
||
/** | ||
* Service factory to get the default site slug, or the first site slug. | ||
* | ||
* @todo Store the default site as slug instead of id? | ||
* @todo Set a setting for the default site of the user? | ||
*/ | ||
class DefaultSiteSlugFactory implements FactoryInterface | ||
{ | ||
/** | ||
* Create and return the DefaultSiteSlug view helper. | ||
* | ||
* @return DefaultSiteSlug | ||
*/ | ||
public function __invoke(ContainerInterface $services, $requestedName, array $options = null) | ||
{ | ||
$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 = (string) reset($slugs); | ||
return new DefaultSiteSlug($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
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,35 @@ | ||
<?php | ||
namespace Omeka\View\Helper; | ||
|
||
use Zend\View\Helper\AbstractHelper; | ||
|
||
/** | ||
* View helper to get the default site slug, or the first one. | ||
*/ | ||
class DefaultSiteSlug extends AbstractHelper | ||
{ | ||
/** | ||
* @var string | ||
*/ | ||
protected $defaultSiteSlug; | ||
|
||
/** | ||
* Construct the helper. | ||
* | ||
* @param string|null $defaultSiteSlug | ||
*/ | ||
public function __construct($defaultSiteSlug) | ||
{ | ||
$this->defaultSiteSlug = $defaultSiteSlug; | ||
} | ||
|
||
/** | ||
* Return the default site slug, or the first one. | ||
* | ||
* @return string|null | ||
*/ | ||
public function __invoke() | ||
{ | ||
return $this->defaultSiteSlug; | ||
} | ||
} |