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' => [
|
'view_helpers' => [
|
||||||
'invokables' => [
|
'factories' => [
|
||||||
'archiveSiteMeta' => View\Helper\ArchiveSiteMeta::class,
|
'archiveSiteMeta' => Service\ViewHelper\ArchiveSiteMetaViewHelperFactory::class,
|
||||||
'siteCollections' => View\Helper\SiteCollections::class,
|
//'archiveSiteMeta' => View\Helper\ArchiveSiteMeta::class,
|
||||||
|
//'siteCollections' => View\Helper\SiteCollections::class,
|
||||||
],
|
],
|
||||||
],
|
],
|
||||||
'block_layouts' => [
|
'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);
|
<?php declare(strict_types=1);
|
||||||
namespace ArchiveSiteMeta\View\Helper;
|
namespace ArchiveSiteMeta\View\Helper;
|
||||||
|
|
||||||
use Laminas\View\Helper\AbstractHelper;
|
use Laminas\View\Helper\AbstractHelper;
|
||||||
|
|
||||||
|
|
||||||
|
//class ArchiveSiteMeta implements FactoryInterface
|
||||||
|
//{
|
||||||
|
|
||||||
|
|
||||||
#use ArchiveSiteMeta\Service\Form\ConfigFormFactory;
|
#use ArchiveSiteMeta\Service\Form\ConfigFormFactory;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* View helper to get metadata for all pages of the specified type.
|
* 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.
|
* 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){
|
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) {
|
foreach ($sites as $site) {
|
||||||
$settings = $this->getSiteMetaValues($site);
|
$settings = $this->getSiteMetaValues($site);
|
||||||
if ($settings && !in_array($settings['collection'], $collections)) {
|
if ($settings && !in_array($settings['collection'], $result)) {
|
||||||
array_push($collections, $settings['collection']);
|
$name = $collection_options[$settings['collection']];
|
||||||
|
$result[$settings['collection']] = $name;
|
||||||
|
//array_push($collections, $settings['collection']);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return $collections;
|
return $result;
|
||||||
}
|
}
|
||||||
|
|
||||||
public function getPages()
|
public function getPages()
|
Loading…
Reference in New Issue