Skip to content

Commit

Permalink
Moved site settings to site settings.
Browse files Browse the repository at this point in the history
  • Loading branch information
Daniel-KM committed Dec 17, 2017
1 parent 1c88e01 commit 94bc663
Show file tree
Hide file tree
Showing 4 changed files with 117 additions and 40 deletions.
119 changes: 114 additions & 5 deletions Module.php
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,8 @@
use Omeka\Permissions\Assertion\OwnsEntityAssertion;
use Zend\EventManager\Event;
use Zend\EventManager\SharedEventManagerInterface;
use Zend\Form\Element\Checkbox;
use Zend\Form\Fieldset;
use Zend\Mvc\Controller\AbstractController;
use Zend\Mvc\MvcEvent;
use Zend\ServiceManager\ServiceLocatorInterface;
Expand Down Expand Up @@ -111,6 +113,7 @@ public function install(ServiceLocatorInterface $serviceLocator)
);
$html .= '</p>';
$settings->set('folksonomy_legal_text', $html);
$this->manageSiteSettings($serviceLocator, 'install');
}

public function uninstall(ServiceLocatorInterface $serviceLocator)
Expand All @@ -125,6 +128,7 @@ public function uninstall(ServiceLocatorInterface $serviceLocator)
$conn->exec($sql);

$this->manageSettings($serviceLocator->get('Omeka\Settings'), 'uninstall');
$this->manageSiteSettings($serviceLocator, 'uninstall');
}

public function upgrade($oldVersion, $newVersion, ServiceLocatorInterface $serviceLocator)
Expand All @@ -140,6 +144,33 @@ public function upgrade($oldVersion, $newVersion, ServiceLocatorInterface $servi
$settings->set('folksonomy_append_media_show',
$defaultSettings['folksonomy_append_media_show']);
}

if (version_compare($oldVersion, '3.3.7', '<')) {
$config = require __DIR__ . '/config/module.config.php';
$defaultSettings = $config[strtolower(__NAMESPACE__)]['site_settings'];
$siteSettings = $serviceLocator->get('Omeka\Settings\Site');
$settings = $serviceLocator->get('Omeka\Settings');
$api = $serviceLocator->get('Omeka\ApiManager');
$sites = $api->search('sites')->getContent();
foreach ($sites as $site) {
$siteSettings->setTargetId($site->id());
$siteSettings->set('folksonomy_append_item_set_show',
$settings->get('folksonomy_append_item_set_show',
$defaultSettings['folksonomy_append_item_set_show'])
);
$siteSettings->set('folksonomy_append_item_show',
$settings->get('folksonomy_append_item_show',
$defaultSettings['folksonomy_append_item_show'])
);
$siteSettings->set('folksonomy_append_media_show',
$settings->get('folksonomy_append_media_show',
$defaultSettings['folksonomy_append_media_show'])
);
}
$settings->delete('folksonomy_append_item_set_show');
$settings->delete('folksonomy_append_item_show');
$settings->delete('folksonomy_append_media_show');
}
}

protected function manageSettings($settings, $process, $key = 'settings')
Expand All @@ -158,6 +189,17 @@ protected function manageSettings($settings, $process, $key = 'settings')
}
}

protected function manageSiteSettings(ServiceLocatorInterface $serviceLocator, $process)
{
$siteSettings = $serviceLocator->get('Omeka\Settings\Site');
$api = $serviceLocator->get('Omeka\ApiManager');
$sites = $api->search('sites')->getContent();
foreach ($sites as $site) {
$siteSettings->setTargetId($site->id());
$this->manageSettings($siteSettings, $process, 'site_settings');
}
}

/**
* Add tag and tagging visibility filters to the entity manager.
*/
Expand Down Expand Up @@ -690,6 +732,12 @@ function (Event $event) {
[$this, 'viewShowAfterPublic']
);
}

$sharedEventManager->attach(
\Omeka\Form\SiteSettingsForm::class,
'form.add_elements',
[$this, 'addSiteSettingsFormElements']
);
}

public function getConfigForm(PhpRenderer $renderer)
Expand Down Expand Up @@ -745,6 +793,66 @@ public function handleConfigForm(AbstractController $controller)
}
}

public function addSiteSettingsFormElements(Event $event)
{
$services = $this->getServiceLocator();
$siteSettings = $services->get('Omeka\Settings\Site');
$config = $services->get('Config');
$form = $event->getTarget();

$defaultSiteSettings = $config[strtolower(__NAMESPACE__)]['site_settings'];

$fieldset = new Fieldset('folksonomy');
$fieldset->setLabel('Folksonomy'); // @translate

$fieldset->add([
'name' => 'folksonomy_append_item_set_show',
'type' => Checkbox::class,
'options' => [
'label' => 'Append automatically to item set page"', // @translate
'info' => 'If unchecked, the viewer can be added via the helper in the theme or the block in any page.', // @translate
],
'attributes' => [
'value' => $siteSettings->get(
'folksonomy_append_item_set_show',
$defaultSiteSettings['folksonomy_append_item_set_show']
),
],
]);

$fieldset->add([
'name' => 'folksonomy_append_item_show',
'type' => Checkbox::class,
'options' => [
'label' => 'Append automatically to item page', // @translate
'info' => 'If unchecked, the viewer can be added via the helper in the theme or the block in any page.', // @translate
],
'attributes' => [
'value' => $siteSettings->get(
'folksonomy_append_item_show',
$defaultSiteSettings['folksonomy_append_item_show']
),
],
]);

$fieldset->add([
'name' => 'folksonomy_append_media_show',
'type' => Checkbox::class,
'options' => [
'label' => 'Append automatically to media page"', // @translate
'info' => 'If unchecked, the viewer can be added via the helper in the theme or the block in any page.', // @translate
],
'attributes' => [
'value' => $siteSettings->get(
'folksonomy_append_media_show',
$defaultSiteSettings['folksonomy_append_media_show']
),
],
]);

$form->add($fieldset);
}

/**
* Cache taggings and tags for resource API search/read.
*
Expand Down Expand Up @@ -1076,20 +1184,21 @@ public function viewShowAfter(Event $event)
public function viewShowAfterPublic(Event $event)
{
$serviceLocator = $this->getServiceLocator();
$settings = $serviceLocator->get('Omeka\Settings');
$siteSettings = $serviceLocator->get('Omeka\Settings\Site');
$view = $event->getTarget();
$resource = $view->resource;
$resourceName = $resource->resourceName();

$appendMap = [
'item_sets' => 'folksonomy_append_item_set_show',
'items' => 'folksonomy_append_item_show',
'media' => 'folksonomy_append_media_show',
];
if ($settings->get($appendMap[$resource->resourceName()])) {
echo $view->showTags($resource);
$this->displayTaggingQuickForm($event);
if (!$siteSettings->get($appendMap[$resourceName])) {
return;
}

echo $view->showTags($resource);
$this->displayTaggingQuickForm($event);
}

/**
Expand Down
3 changes: 2 additions & 1 deletion config/module.config.php
Original file line number Diff line number Diff line change
Expand Up @@ -283,7 +283,8 @@
'folksonomy_max_length_total' => 1000,
'folksonomy_message' => '+',
'folksonomy_legal_text' => '<p>I agree with <a rel="licence" href="#" target="_blank">terms of use</a> and I accept to free my contribution under the licence <a rel="licence" href="https://creativecommons.org/licenses/by-sa/3.0/" target="_blank">CC BY-SA</a>.</p>',
// TODO Move to site settings.
],
'site_settings' => [
'folksonomy_append_item_set_show' => true,
'folksonomy_append_item_show' => true,
'folksonomy_append_media_show' => true,
Expand Down
2 changes: 1 addition & 1 deletion config/module.ini
Original file line number Diff line number Diff line change
Expand Up @@ -8,5 +8,5 @@ author_link = "https://github.com/Daniel-KM"
module_link = "https://github.com/Daniel-KM/Omeka-S-module-Folksonomy"
support_link = "https://github.com/Daniel-KM/Omeka-S-module-Folksonomy/issues"
configurable = true
version = "3.3.6"
version = "3.3.7"
omeka_version_constraint = "^1.0.0"
33 changes: 0 additions & 33 deletions src/Form/ConfigForm.php
Original file line number Diff line number Diff line change
Expand Up @@ -84,27 +84,6 @@ public function init()
'id' => 'folksonomy-legal-text',
],
]);
$taggingFormFieldset->add([
'name' => 'folksonomy_append_item_set_show',
'type' => Checkbox::class,
'options' => [
'label' => 'Append to public item set page automatically', // @translate
],
]);
$taggingFormFieldset->add([
'name' => 'folksonomy_append_item_show',
'type' => Checkbox::class,
'options' => [
'label' => 'Append to public item page automatically', // @translate
],
]);
$taggingFormFieldset->add([
'name' => 'folksonomy_append_media_show',
'type' => Checkbox::class,
'options' => [
'label' => 'Append to public media page automatically', // @translate
],
]);

$inputFilter = $this->getInputFilter();

Expand Down Expand Up @@ -139,17 +118,5 @@ public function init()
'name' => 'folksonomy_legal_text',
'required' => false,
]);
$taggingFormFilter->add([
'name' => 'folksonomy_append_item_set_show',
'required' => false,
]);
$taggingFormFilter->add([
'name' => 'folksonomy_append_item_show',
'required' => false,
]);
$taggingFormFilter->add([
'name' => 'folksonomy_append_media_show',
'required' => false,
]);
}
}

0 comments on commit 94bc663

Please sign in to comment.