Skip to content

Commit

Permalink
feat: add possibility to define http code 410 for gone contents
Browse files Browse the repository at this point in the history
(cherry picked from commit d4ec65d)
  • Loading branch information
tinect committed Apr 27, 2024
1 parent 14a1e10 commit 101ad38
Show file tree
Hide file tree
Showing 4 changed files with 28 additions and 21 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -29,10 +29,15 @@
</template>
<template v-else>
<sw-card position-identifier="tinect-redirects-details">
<sw-container class="no-flex-grow-field">
<sw-container class="no-flex-grow-field" columns="1fr 1fr">
<sw-checkbox-field :label="$t('tinect-redirects.detail.activeLabel')"
v-model="redirect.active">
</sw-checkbox-field>

<sw-checkbox-field :helpText="$t('tinect-redirects.detail.hiddenHelpText')"
:label="$t('tinect-redirects.detail.hiddenLabel')"
v-model="redirect.hidden">
</sw-checkbox-field>
</sw-container>

<sw-card :title="$t('tinect-redirects.detail.source')"
Expand All @@ -46,12 +51,20 @@
:helpText="$tc('tinect-redirects.detail.salesChannelDomainHelpText')">
</sw-entity-single-select>

<sw-field :label="$t('tinect-redirects.detail.sourceUrlLabel')"
<sw-text-field :label="$t('tinect-redirects.detail.sourceUrlLabel')"
v-model="redirect.source"
validation="required"></sw-field>
validation="required"></sw-text-field>
</sw-card>

<sw-card :title="$t('tinect-redirects.detail.target')"
<sw-select-number-field :label="$t('tinect-redirects.detail.httpCodeLabel')"
v-model="redirect.httpCode"
validation="required">
<option value=301>{{ $t('tinect-redirects.detail.httpCodeLabelValues.301') }}</option>
<option value=302>{{ $t('tinect-redirects.detail.httpCodeLabelValues.302') }}</option>
<option value=410>{{ $t('tinect-redirects.detail.httpCodeLabelValues.410') }}</option>
</sw-select-number-field>

<sw-card v-if="redirect.httpCode !== 410" :title="$t('tinect-redirects.detail.target')"
position-identifier="tinect-redirects-details-target">
<template v-if="hasSwUrlExt">
<sw-url-ext-field :label="$t('tinect-redirects.detail.targetUrlLabel')"
Expand All @@ -67,20 +80,6 @@
</template>
</sw-card>

<sw-select-number-field :label="$t('tinect-redirects.detail.httpCodeLabel')"
v-model="redirect.httpCode"
validation="required">
<option value=301>{{ $t('tinect-redirects.detail.httpCodeLabelValues.301') }}</option>
<option value=302>{{ $t('tinect-redirects.detail.httpCodeLabelValues.302') }}</option>
</sw-select-number-field>

<sw-container class="no-flex-grow-field">
<sw-checkbox-field :helpText="$t('tinect-redirects.detail.hiddenHelpText')"
:label="$t('tinect-redirects.detail.hiddenLabel')"
v-model="redirect.hidden">
</sw-checkbox-field>
</sw-container>

<sw-text-editor :label="$t('tinect-redirects.detail.commentLabel')"
v-model="redirect.comment"></sw-text-editor>
</sw-card>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,8 @@
"targetUrlHelpText": "Die Ziel-URL kann entweder eine interne URL (z.B. /shopware) oder eine externe URL (z.B. https://shopware.com/example) sein",
"httpCodeLabelValues": {
"301": "301 (Permanent verschoben)",
"302": "302 (Gefunden / Temporär verschoben)"
"302": "302 (Gefunden / Temporär verschoben)",
"410": "410 (Permanent gelöscht)"
},
"columnIpAddress": "IP-Adresse",
"columnUserAgent": "User-Agent",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,8 @@
"targetUrlHelpText": "The target URL can be an internal URL (e.g. /shopware) or an external URL (e.g. https://shopware.com/example)",
"httpCodeLabelValues": {
"301": "301 (Moved Permanently)",
"302": "302 (Found / Moved Temporarily)"
"302": "302 (Found / Moved Temporarily)",
"410": "410 (Gone)"
},
"columnIpAddress": "IP-Address",
"columnUserAgent": "User-Agent",
Expand Down
8 changes: 7 additions & 1 deletion src/Subscriber/BeforeSendResponseSubscriber.php
Original file line number Diff line number Diff line change
Expand Up @@ -119,6 +119,12 @@ private function handleRequest(Request $request): ?Response
return null;
}

$httpCode = $redirect->getHttpCode();

if ($httpCode === Response::HTTP_GONE) {
return new Response('', $httpCode);
}

$targetURL = $redirect->getTarget();

$host = $request->attributes->get(RequestTransformer::SALES_CHANNEL_ABSOLUTE_BASE_URL)
Expand All @@ -132,7 +138,7 @@ private function handleRequest(Request $request): ?Response
$targetURL = $host . $targetURL;
}

return new RedirectResponse($targetURL, $redirect->getHttpCode());
return new RedirectResponse($targetURL, $httpCode);
}

private function getSalesChannelContext(Request $request): SalesChannelContext
Expand Down

0 comments on commit 101ad38

Please sign in to comment.