132 lines
3.1 KiB
PHP
132 lines
3.1 KiB
PHP
<?php
|
|
namespace ArchiveSiteMeta;
|
|
|
|
use ArchiveSiteMeta\Form\ConfigForm;
|
|
use Omeka\Module\AbstractModule;
|
|
use Laminas\EventManager\Event;
|
|
use Laminas\View\Renderer\PhpRenderer;
|
|
use Laminas\EventManager\SharedEventManagerInterface;
|
|
use Laminas\Mvc\MvcEvent;
|
|
use Laminas\Mvc\Controller\AbstractController;
|
|
use Omeka\Mvc\Controller\Plugin\Messenger;
|
|
|
|
|
|
|
|
|
|
class Module extends AbstractModule
|
|
{
|
|
const NAMESPACE = __NAMESPACE__;
|
|
|
|
const PAGE_LAYOUT = [
|
|
'standard' => 'Standard',
|
|
'exhibition' => 'Exhibition',
|
|
];
|
|
|
|
const PAGE_TYPE = [
|
|
'' => '',
|
|
'exhibit' => 'Exhibitions',
|
|
];
|
|
|
|
/*
|
|
public function attachListeners(SharedEventManagerInterface $sharedEventManager): void
|
|
{
|
|
$sharedEventManager->attach(
|
|
\Omeka\Api\Adapter\ItemAdapter::class,
|
|
'api.create.post',
|
|
[$this, 'afterSaveItem'],
|
|
100
|
|
);
|
|
$sharedEventManager->attach(
|
|
\Omeka\Api\Adapter\ItemAdapter::class,
|
|
'api.update.post',
|
|
[$this, 'afterSaveItem'],
|
|
100
|
|
);
|
|
$sharedEventManager->attach(
|
|
\Omeka\Api\Adapter\ItemAdapter::class,
|
|
'api.delete.post',
|
|
[$this, 'afterDeleteItem'],
|
|
100
|
|
);
|
|
}
|
|
*/
|
|
public function getConfig()
|
|
{
|
|
return include __DIR__ . '/config/module.config.php';
|
|
}
|
|
|
|
public function getConfigForm(PhpRenderer $renderer)
|
|
{
|
|
$services = $this->getServiceLocator();
|
|
$config = $services->get('Config');
|
|
$settings = $services->get('Omeka\Settings');
|
|
$form = $services->get('FormElementManager')->get(ConfigForm::class);
|
|
|
|
$data = [];
|
|
$defaultSettings = $config['config']['SiteMeta'];
|
|
foreach ($defaultSettings as $name => $value) {
|
|
$data[$name] = $settings->get($name, $value);
|
|
}
|
|
|
|
$form->init();
|
|
$form->setData($data);
|
|
$html = $renderer->render('module/config', [
|
|
'form' => $form,
|
|
]);
|
|
return $html;
|
|
}
|
|
|
|
|
|
public function handleConfigForm(AbstractController $controller)
|
|
{
|
|
//return true;
|
|
//if (!parent::handleConfigForm($controller)) {
|
|
// return false;
|
|
//}
|
|
|
|
//$services = $this->getServiceLocator();
|
|
//$settings = $services->get('Omeka\Settings');
|
|
|
|
//$a=$b;
|
|
$config = $this->getConfig();
|
|
#print_r($config);
|
|
$encodedString = json_encode($config);
|
|
file_put_contents('/tmp/json_array.txt', $encodedString);
|
|
var_dump($encodedString);
|
|
|
|
|
|
$space = strtolower(static::NAMESPACE);
|
|
if (empty($config['config']['SiteMeta'])) {
|
|
return true;
|
|
}
|
|
|
|
$services = $this->getServiceLocator();
|
|
$formManager = $services->get('FormElementManager');
|
|
$formClass = static::NAMESPACE . '\Form\ConfigForm';
|
|
if (!$formManager->has($formClass)) {
|
|
return true;
|
|
}
|
|
|
|
$params = $controller->getRequest()->getPost();
|
|
|
|
$form = $formManager->get($formClass);
|
|
$form->init();
|
|
$form->setData($params);
|
|
if (!$form->isValid()) {
|
|
$controller->messenger()->addErrors($form->getMessages());
|
|
return false;
|
|
}
|
|
$params = $form->getData();
|
|
|
|
$settings = $services->get('Omeka\Settings');
|
|
$defaultSettings = $config['config']['SiteMeta'];
|
|
//$defaultSettings = $config[$space]['config'];
|
|
$params = array_intersect_key($params, $defaultSettings);
|
|
foreach ($params as $name => $value) {
|
|
$settings->set($name, $value);
|
|
}
|
|
return true;
|
|
}
|
|
|
|
}
|