-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added a view helper to get the default site slug (to be used in admin).
- Loading branch information
Showing
3 changed files
with
69 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
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 Next\Service\ViewHelper; | ||
|
||
use Interop\Container\ContainerInterface; | ||
use Next\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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
<?php | ||
namespace Next\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; | ||
} | ||
} |