+ + | ++ + | +
---|---|
+ + | ++ diacritics; ?> + | +
+ + | +
+
+
+
+ mappings; ?> + |
+
diff --git a/apps/qubit/modules/settings/actions/diacriticsAction.class.php b/apps/qubit/modules/settings/actions/diacriticsAction.class.php new file mode 100644 index 0000000000..1109d053ba --- /dev/null +++ b/apps/qubit/modules/settings/actions/diacriticsAction.class.php @@ -0,0 +1,101 @@ +. + */ + +class SettingsDiacriticsAction extends SettingsEditAction +{ + // Arrays not allowed in class constants + public static $NAMES = [ + 'diacritics', + ]; + + public function earlyExecute() + { + parent::earlyExecute(); + + $this->updateMessage = $this->i18n->__('Diacritics settings saved.'); + + $this->settingDefaults = [ + 'diacritics' => 0, + ]; + } + + public function processForm() + { + foreach ($this->form as $field) { + $this->processField($field); + } + + $this->uploadDiacritics(); + } + + public function uploadDiacritics() + { + if (!$this->form->isValid()) { + return; + } + + $file = $this->form->getValue('mappings'); + + $diacriticsMappingPath = + sfConfig::get('sf_config_dir').DIRECTORY_SEPARATOR. + 'diacritics_mapping.yml'; + + if (null !== $file) { + try { + sfYaml::load($file->getTempName()); + + if (!move_uploaded_file($file->getTempName(), $diacriticsMappingPath)) { + $this->getUser()->setFlash('error', $this->context->i18n->__( + 'Unable to upload diacritics mapping yaml file.' + )); + unset($this->updateMessage); + + return; + } + } catch (Exception $e) { + // Reset diacritics settings when uploading yaml fails + QubitSetting::findAndSave('diacritics', 0, ['sourceCulture' => true]); + unlink($diacriticsMappingPath); + $this->getUser()->setFlash('error', $this->context->i18n->__( + 'Unable to upload diacritics mapping yaml file.' + )); + unset($this->updateMessage); + + return; + } + } else { + // Reset diacritics settings when uploading yaml fails + QubitSetting::findAndSave('diacritics', 0, ['sourceCulture' => true]); + unlink($diacriticsMappingPath); + } + } + + protected function addField($name) + { + switch ($name) { + case 'diacritics': + $this->form->setDefault($name, $this->settingDefaults[$name]); + $this->form->setWidget($name, new sfWidgetFormSelectRadio(['choices' => [0 => $this->i18n->__('Disabled'), 1 => $this->i18n->__('Enabled')]], ['class' => 'radio'])); + $this->form->setValidator($name, new sfValidatorChoice(['choices' => [1, 0]])); + $this->form->setWidget('mappings', new sfWidgetFormInputFile([], ['accept' => '.yml,.yaml'])); + $this->form->setValidator('mappings', new sfValidatorFile()); + + break; + } + } +} diff --git a/apps/qubit/modules/settings/actions/editAction.class.php b/apps/qubit/modules/settings/actions/editAction.class.php index e868af28d7..b07169c870 100644 --- a/apps/qubit/modules/settings/actions/editAction.class.php +++ b/apps/qubit/modules/settings/actions/editAction.class.php @@ -1,5 +1,4 @@ isMethod('post')) { - $this->form->bind($request->getPostParameters()); + $this->form->bind($request->getPostParameters(), $request->getFiles()); if ($this->form->isValid()) { $this->processForm(); diff --git a/apps/qubit/modules/settings/actions/menuComponent.class.php b/apps/qubit/modules/settings/actions/menuComponent.class.php index 2948c80290..621f2ae063 100644 --- a/apps/qubit/modules/settings/actions/menuComponent.class.php +++ b/apps/qubit/modules/settings/actions/menuComponent.class.php @@ -39,6 +39,10 @@ public function execute($request) 'label' => $i18n->__('Default template'), 'action' => 'template', ], + [ + 'label' => $i18n->__('Diacritics'), + 'action' => 'diacritics', + ], [ 'label' => $i18n->__('Digital object derivatives'), 'action' => 'digitalObjectDerivatives', diff --git a/apps/qubit/modules/settings/templates/diacriticsSuccess.php b/apps/qubit/modules/settings/templates/diacriticsSuccess.php new file mode 100644 index 0000000000..0901a8bf42 --- /dev/null +++ b/apps/qubit/modules/settings/templates/diacriticsSuccess.php @@ -0,0 +1,80 @@ + + + + + + + + + +
+ +
+$ php symfony search:populate+
+ +
+type: mapping+
mappings:
- À => A
- Á => A
+ + | ++ + | +
---|---|
+ + | ++ diacritics; ?> + | +
+ + | +
+
+
+
+ mappings; ?> + |
+
$ php symfony search:populate+
+ | + |
---|---|
+ | diacritics; ?> | +
+ |
+
+ mappings; ?> + |
+