diff --git a/application/config/module.config.php b/application/config/module.config.php index 96b56f7b2..2b0b43805 100644 --- a/application/config/module.config.php +++ b/application/config/module.config.php @@ -412,6 +412,7 @@ 'blockLayout' => Service\ViewHelper\BlockLayoutFactory::class, 'blockThumbnailTypeSelect' => Service\ViewHelper\BlockThumbnailTypeSelectFactory::class, 'dataType' => Service\ViewHelper\DataTypeFactory::class, + 'defaultSiteSlug' => Service\ViewHelper\DefaultSiteSlugFactory::class, 'i18n' => Service\ViewHelper\I18nFactory::class, 'logger' => Service\ViewHelper\LoggerFactory::class, 'media' => Service\ViewHelper\MediaFactory::class, diff --git a/application/src/Service/ViewHelper/DefaultSiteSlugFactory.php b/application/src/Service/ViewHelper/DefaultSiteSlugFactory.php new file mode 100644 index 000000000..383c0be98 --- /dev/null +++ b/application/src/Service/ViewHelper/DefaultSiteSlugFactory.php @@ -0,0 +1,33 @@ +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); + } +} diff --git a/application/src/Service/ViewHelper/PublicResourceUrlFactory.php b/application/src/Service/ViewHelper/PublicResourceUrlFactory.php index b425dcad7..1a9e5e837 100644 --- a/application/src/Service/ViewHelper/PublicResourceUrlFactory.php +++ b/application/src/Service/ViewHelper/PublicResourceUrlFactory.php @@ -13,21 +13,13 @@ class PublicResourceUrlFactory implements FactoryInterface { /** - * Create and return the PublicResourceUrlFactory view helper + * Create and return the PublicResourceUrl view helper * - * @return PublicResourceUrlFactory + * @return PublicResourceUrl */ 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); + $defaultSiteSlug = $services->get('ViewHelperManager')->get('defaultSiteSlug'); + return new PublicResourceUrl($defaultSiteSlug()); } } diff --git a/application/src/View/Helper/DefaultSiteSlug.php b/application/src/View/Helper/DefaultSiteSlug.php new file mode 100644 index 000000000..0d729f79e --- /dev/null +++ b/application/src/View/Helper/DefaultSiteSlug.php @@ -0,0 +1,35 @@ +defaultSiteSlug = $defaultSiteSlug; + } + + /** + * Return the default site slug, or the first one. + * + * @return string|null + */ + public function __invoke() + { + return $this->defaultSiteSlug; + } +}