diff --git a/Classes/Controller/AbstractController.php b/Classes/Controller/AbstractController.php index d2a7f25eb..6f9159d48 100644 --- a/Classes/Controller/AbstractController.php +++ b/Classes/Controller/AbstractController.php @@ -276,6 +276,55 @@ protected function sanitizeRequestData(): void $this->requestData['double'] = MathUtility::forceIntegerInRange($this->requestData['double'] ?? 0, 0, 1); } + /** + * Sanitize settings from FlexForm. + * + * @access protected + * + * @return void + */ + protected function sanitizeSettings(): void + { + $this->setDefaultIntSetting('storagePid', 0); + + if ($this instanceof MetadataController) { + $this->setDefaultIntSetting('rootline', 0); + $this->setDefaultIntSetting('originalIiifMetadata', 0); + $this->setDefaultIntSetting('displayIiifDescription', 1); + $this->setDefaultIntSetting('displayIiifRights', 1); + $this->setDefaultIntSetting('displayIiifLinks', 1); + } + + if ($this instanceof OaiPmhController) { + $this->setDefaultIntSetting('limit', 5); + $this->setDefaultIntSetting('solr_limit', 50000); + } + + if ($this instanceof PageViewController) { + $this->setDefaultIntSetting('useInternalProxy', 0); + } + } + + /** + * Sets default value for setting if not yet set. + * + * @access protected + * + * @param string $setting name of setting + * @param int $value for being set if empty + * + * @return void + */ + protected function setDefaultIntSetting(string $setting, int $value): void + { + if (empty($this->settings[$setting])) { + $this->settings[$setting] = $value; + $this->logger->warning('Setting "' . $setting . '" not set, using default value "' . $value . '". Probably FlexForm for controller "' . get_class($this) . '" is not read.'); + } else { + $this->settings[$setting] = (int) $this->settings[$setting]; + } + } + /** * Sets page value. * @@ -533,7 +582,7 @@ protected function getDocumentByUrl(string $documentId) // Make sure configuration PID is set when applicable if ($doc->cPid == 0) { - $doc->cPid = max((int) $this->settings['storagePid'], 0); + $doc->cPid = max($this->settings['storagePid'], 0); } $this->document->setLocation($documentId); diff --git a/Classes/Controller/MetadataController.php b/Classes/Controller/MetadataController.php index 1fa0138f9..a8b45f152 100644 --- a/Classes/Controller/MetadataController.php +++ b/Classes/Controller/MetadataController.php @@ -107,16 +107,10 @@ public function mainAction(): void if ($this->isDocMissing()) { // Quit without doing anything if required variables are not set. return; - } else { - // Set default values if not set. - $this->setDefault('rootline', 0); - $this->setDefault('originalIiifMetadata', 0); - $this->setDefault('displayIiifDescription', 1); - $this->setDefault('displayIiifRights', 1); - $this->setDefault('displayIiifLinks', 1); - $this->setPage(); } + $this->setPage(); + $this->currentDocument = $this->document->getCurrentDocument(); $this->useOriginalIiifManifestMetadata = $this->settings['originalIiifMetadata'] == 1 && $this->currentDocument instanceof IiifManifest; @@ -529,21 +523,4 @@ private function getMetadataForIds(array $id, array $metadata): array } return $metadata; } - - /** - * Sets default value for setting if not yet set. - * - * @access private - * - * @param string $setting name of setting - * @param int $value 0 or 1 - * - * @return void - */ - private function setDefault(string $setting, int $value): void - { - if (!isset($this->settings[$setting])) { - $this->settings[$setting] = $value; - } - } } diff --git a/Classes/Controller/OaiPmhController.php b/Classes/Controller/OaiPmhController.php index 81c7430ef..e55b8ede5 100644 --- a/Classes/Controller/OaiPmhController.php +++ b/Classes/Controller/OaiPmhController.php @@ -645,8 +645,8 @@ protected function fetchDocumentSet(): array $this->logger->error('Apache Solr not available'); return $documentSet; } - if ((int) $this->settings['solr_limit'] > 0) { - $solr->limit = (int) $this->settings['solr_limit']; + if ($this->settings['solr_limit'] > 0) { + $solr->limit = $this->settings['solr_limit']; } // We only care about the UID in the results and want them sorted $parameters = [ @@ -785,7 +785,7 @@ private function checkGranularity(): void */ protected function generateOutputForDocumentList(array $documentListSet) { - $documentsToProcess = array_splice($documentListSet['elements'], 0, (int) $this->settings['limit']); + $documentsToProcess = array_splice($documentListSet['elements'], 0, $this->settings['limit']); if (empty($documentsToProcess)) { $this->error = 'noRecordsMatch'; return []; diff --git a/Classes/Controller/PageViewController.php b/Classes/Controller/PageViewController.php index 8fe4a01e8..78b830535 100644 --- a/Classes/Controller/PageViewController.php +++ b/Classes/Controller/PageViewController.php @@ -503,7 +503,7 @@ protected function addViewerJS(): void 'score' => $docScore, 'annotationContainers' => $docAnnotationContainers, 'measureCoords' => $docMeasures['measureCoordsCurrentSite'], - 'useInternalProxy' => $this->settings['useInternalProxy'] ? 1 : 0, + 'useInternalProxy' => $this->settings['useInternalProxy'], 'currentMeasureId' => $currentMeasureId, 'measureIdLinks' => $docMeasures['measureLinks'] ]; @@ -539,7 +539,7 @@ protected function addViewerJS(): void 'score' => $this->scores, 'annotationContainers' => $this->annotationContainers, 'measureCoords' => $docMeasures['measureCoordsCurrentSite'], - 'useInternalProxy' => $this->settings['useInternalProxy'] ? 1 : 0, + 'useInternalProxy' => $this->settings['useInternalProxy'], 'verovioAnnotations' => $this->verovioAnnotations, 'currentMeasureId' => $currentMeasureId, 'measureIdLinks' => $docMeasures['measureLinks']