Skip to content

Commit f6faaef

Browse files
[IMPROVEMENT] Replace multiview source remove link (kitodo#1749)
1 parent 65d0d51 commit f6faaef

File tree

3 files changed

+53
-15
lines changed

3 files changed

+53
-15
lines changed

Classes/Controller/PageViewController.php

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -98,12 +98,15 @@ public function mainAction(): ResponseInterface
9898
$this->loadDocument();
9999

100100
if ($this->isDocMissingOrEmpty()) {
101-
// if document is empty and current document type is a multi document type redirect to multi view
101+
// if document is empty and current document type is a multi document type then redirect to multi view
102102
if (!$this->isDocMissing() &&
103103
$this->isMultiDocumentType($this->document->getCurrentDocument()->tableOfContents[0]['type'])) {
104104
return $this->multiviewRedirect();
105105
}
106106
return $this->htmlResponse();
107+
} elseif (array_key_exists('multiViewSource', $this->requestData)) {
108+
// if request data contains multiViewSource parameter then redirect to multi view
109+
return $this->multiviewRedirect();
107110
}
108111

109112
$this->setPage();
@@ -522,6 +525,10 @@ private function multiviewRedirect(): ResponseInterface
522525
'tx_dlf[multiview]' => 1
523526
];
524527

528+
if (array_key_exists('multiViewSource', $this->requestData)) {
529+
$arguments['tx_dlf[multiViewSource]'] = $this->requestData['multiViewSource'];
530+
}
531+
525532
$uri = $this->uriBuilder
526533
->reset()
527534
->setArguments($arguments)

Classes/ViewHelpers/LinkViewHelper.php

Lines changed: 42 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -48,22 +48,35 @@ public function render(): string
4848

4949
$viewData = $this->arguments['viewData'];
5050

51-
// UriBuilder does not properly encode specified entities in URL parameter
52-
// For more details, please see the following TYPO3 issue https://forge.typo3.org/issues/107026
53-
if (isset($viewData['requestData']['id']) && GeneralUtility::isValidUrl($viewData['requestData']['id'])) {
54-
$viewData['requestData']['id'] = str_replace("%2F", "%252F", $viewData['requestData']['id']);
55-
}
56-
57-
$arguments = [];
58-
foreach ($viewData['requestData'] as $key => $value) {
59-
if (!in_array($key, $this->arguments['excludedParams'])) {
60-
$arguments['tx_dlf'][$key] = $value;
51+
$dlfArguments = [];
52+
foreach ($viewData['requestData'] as $key => $data) {
53+
if (is_array($data)) {
54+
$tempData = [];
55+
foreach ($data as $dataKey => $dataValue) {
56+
if (!in_array($key . '[' . $dataKey . ']', $this->arguments['excludedParams'])) {
57+
$tempData[] = $dataValue;
58+
}
59+
}
60+
if (count($tempData) > 0) {
61+
$dlfArguments[$key] = $tempData;
62+
}
63+
} elseif (!in_array($key, $this->arguments['excludedParams'])) {
64+
$dlfArguments[$key] = $data;
6165
}
6266
}
6367

6468
$additionalParams = $this->arguments['additionalParams'];
6569
foreach ($additionalParams as $key => $value) {
66-
$arguments['tx_dlf'][$key] = $value;
70+
$dlfArguments[$key] = $value;
71+
}
72+
73+
// double replace encoding in URL value parameters
74+
if (isset($dlfArguments['id'])) {
75+
$dlfArguments['id'] = $this->doubleEncode($dlfArguments['id']);
76+
}
77+
78+
if (isset($dlfArguments['multiViewSource']) && is_array($dlfArguments['multiViewSource'])) {
79+
$dlfArguments['multiViewSource'] = array_map([$this, 'doubleEncode'], $dlfArguments['multiViewSource']);
6780
}
6881

6982
$childContent = (string) $this->renderChildren();
@@ -77,7 +90,7 @@ public function render(): string
7790
}
7891

7992
$uri = $uriBuilder
80-
->setArguments($arguments)
93+
->setArguments(['tx_dlf' => $dlfArguments])
8194
->setArgumentPrefix('tx_dlf')
8295
->uriFor('main');
8396

@@ -92,4 +105,21 @@ public function render(): string
92105

93106
return $tag->tag->render();
94107
}
108+
109+
/**
110+
* Double encode specific characters in URL.
111+
*
112+
* UriBuilder does not properly encode specified entities in URL parameter
113+
* For more details, please see the following TYPO3 issue https://forge.typo3.org/issues/107026
114+
*
115+
* @param string $url The URL in which specific characters should be encoded
116+
* @return string The replaced URL
117+
*/
118+
private function doubleEncode(string $url): string
119+
{
120+
if (GeneralUtility::isValidUrl($url)) {
121+
$url = str_replace("%2F", "%252F", $url);
122+
}
123+
return $url;
124+
}
95125
}

Resources/Private/Templates/MultiView/Main.html

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
-->
1111
</f:comment>
1212
<html xmlns:f="http://typo3.org/ns/TYPO3/CMS/Fluid/ViewHelpers"
13+
xmlns:kitodo="http://typo3.org/ns/Kitodo/Dlf/ViewHelpers"
1314
data-namespace-typo3-fluid="true">
1415

1516
<div class="page-control">
@@ -45,9 +46,9 @@
4546
<div class="gridstack-dragging-handle" title="{f:translate(key: 'multiview.dragging_label', extensionName: 'dfgviewer')}"></div>
4647
<f:if condition="{document.sourceKey} >= 0">
4748
<div class="removeDocument">
48-
<f:link.action addQueryString="untrusted" argumentsToBeExcludedFromQueryString="{0: 'tx_dlf[multiViewSource][{document.sourceKey}]', 1: 'tx_dlf[multiview]'}">
49+
<kitodo:link viewData="{viewData}" excludedParams="{0: 'multiViewSource[{document.sourceKey}]', 1: 'multiview'}">
4950
<f:translate key="multiview.remove_document" extensionName="dfgviewer" />
50-
</f:link.action>
51+
</kitodo:link>
5152
</div>
5253
</f:if>
5354
</div>

0 commit comments

Comments
 (0)