adds viewhelper factory to pass global settings to helper
This commit is contained in:
parent
143c17a134
commit
9a4d3e2822
|
@ -11,9 +11,10 @@ return [
|
|||
],
|
||||
],
|
||||
'view_helpers' => [
|
||||
'invokables' => [
|
||||
'archiveSiteMeta' => View\Helper\ArchiveSiteMeta::class,
|
||||
'siteCollections' => View\Helper\SiteCollections::class,
|
||||
'factories' => [
|
||||
'archiveSiteMeta' => Service\ViewHelper\ArchiveSiteMetaViewHelperFactory::class,
|
||||
//'archiveSiteMeta' => View\Helper\ArchiveSiteMeta::class,
|
||||
//'siteCollections' => View\Helper\SiteCollections::class,
|
||||
],
|
||||
],
|
||||
'block_layouts' => [
|
||||
|
|
|
@ -0,0 +1,17 @@
|
|||
<?php
|
||||
|
||||
namespace ArchiveSiteMeta\Service\ViewHelper;
|
||||
|
||||
use ArchiveSiteMeta\View\Helper;
|
||||
use Zend\ServiceManager\Factory\FactoryInterface;
|
||||
use Interop\Container\ContainerInterface;
|
||||
use ArchiveSiteMeta\View\Helper\ArchiveSiteMetaViewHelper;
|
||||
|
||||
class ArchiveSiteMetaViewHelperFactory implements FactoryInterface
|
||||
{
|
||||
public function __invoke(ContainerInterface $services, $requestedName, array $options = null)
|
||||
{
|
||||
$config = $services->get('Config');
|
||||
return new ArchiveSiteMetaViewHelper($services->get('Omeka\Settings'));
|
||||
}
|
||||
}
|
|
@ -1,14 +1,25 @@
|
|||
<?php declare(strict_types=1);
|
||||
namespace ArchiveSiteMeta\View\Helper;
|
||||
|
||||
use Laminas\View\Helper\AbstractHelper;
|
||||
|
||||
|
||||
//class ArchiveSiteMeta implements FactoryInterface
|
||||
//{
|
||||
|
||||
|
||||
#use ArchiveSiteMeta\Service\Form\ConfigFormFactory;
|
||||
|
||||
/**
|
||||
* View helper to get metadata for all pages of the specified type.
|
||||
*/
|
||||
class ArchiveSiteMeta extends AbstractHelper
|
||||
class ArchiveSiteMetaViewHelper extends AbstractHelper
|
||||
{
|
||||
|
||||
|
||||
public function __construct($omekaSettings)
|
||||
{
|
||||
$this->omekaSettings = $omekaSettings;
|
||||
}
|
||||
/**
|
||||
* Get data for all pages of the specified type in the current site.
|
||||
*
|
||||
|
@ -45,14 +56,26 @@ class ArchiveSiteMeta extends AbstractHelper
|
|||
}
|
||||
|
||||
public function getCollections($sites){
|
||||
$collections = [];
|
||||
$collections = $this->omekaSettings->get('sitemeta_collections');
|
||||
$collection_options = [];
|
||||
|
||||
foreach ( explode("\n", $collections) as $value ) {
|
||||
$key_value = explode("=", str_replace(array("\r", "\n"), '',$value));
|
||||
$collection_options[trim($key_value[1])] = trim($key_value[0]);
|
||||
}
|
||||
//return $collections;
|
||||
//$site = $sites[0]->setting('sitemeta_collections');
|
||||
//$collections = [];
|
||||
$result = [];
|
||||
foreach ($sites as $site) {
|
||||
$settings = $this->getSiteMetaValues($site);
|
||||
if ($settings && !in_array($settings['collection'], $collections)) {
|
||||
array_push($collections, $settings['collection']);
|
||||
if ($settings && !in_array($settings['collection'], $result)) {
|
||||
$name = $collection_options[$settings['collection']];
|
||||
$result[$settings['collection']] = $name;
|
||||
//array_push($collections, $settings['collection']);
|
||||
}
|
||||
}
|
||||
return $collections;
|
||||
return $result;
|
||||
}
|
||||
|
||||
public function getPages()
|
Loading…
Reference in New Issue