Problem/Motivation

It is not possible to configure a redirect destination (or other necessary config for certain other HTTP responses) when creating a 301/303/etc. response variant.

Proposed resolution

Edit the HttpStatusCodeDisplayVariant code to conditionally pass headers to HttpException for certain response codes and provide a UI for its configuration.

Remaining tasks

Test behavior.

User interface changes

New, likely conditional, field for header, e.g., Location, to be passed to the HttpException constructor.

API changes

None

Data model changes

Config entity will need a schema update for the new parameter.

Comments

bradjones1 created an issue. See original summary.

tim.plunkett’s picture

Category: Bug report » Feature request

Sounds good.

RKopacz’s picture

Any developments on this front?

RKopacz’s picture

bump? I can help with testing & documentation if needs be. Used page manager extensively to do redirects in 7, would love to see this functionality!

Devestaaron’s picture

I would also love to see this!

It seems odd that we can create a redirect but can't specify where it redirect to.

kalistos’s picture

Status: Active » Needs review
StatusFileSize
new2.48 KB

I wanna to save us!

Status: Needs review » Needs work

The last submitted patch, 6: page_manager_redirect_location-2624972-6.patch, failed testing.

kalistos’s picture

StatusFileSize
new4.89 KB
new4.02 KB

Small fix for building redirect using current params.

andypost’s picture

Status: Needs work » Needs review

Status: Needs review » Needs work

The last submitted patch, 8: page_manager-redirect_location-2624972-7.patch, failed testing.

dstorozhuk’s picture

Tested, redirect works, but there few issues:

  1. When creating new variant with http_status_code using wizard, PHP notice appears about undefined redirect_location variable;
  2. When creating new variant with http_status_code using wizard, and non redirect code chosen (404 etc.) - wizard doesn't go forward because of required redirect_location;
  3. When redirecting path alias is not used.
dstorozhuk’s picture

Fix:

  1. When creating new variant with http_status_code using wizard, PHP notice appears about undefined redirect_location variable;
  2. When creating new variant with http_status_code using wizard, and non redirect code chosen (404 etc.) - wizard doesn't go forward because of required redirect_location;
  3. When redirecting path alias is not used.
dstorozhuk’s picture

Status: Needs work » Needs review
dstorozhuk’s picture

StatusFileSize
new6.77 KB
dstorozhuk’s picture

StatusFileSize
new7.23 KB

Update page_manager.schema: display_variant.plugin.http_status_code to accept redirect_location parameter.

The last submitted patch, 12: page_manager-redirect_location-2624972-12.patch, failed testing.

The last submitted patch, 14: page_manager-redirect_location-2624972-14.patch, failed testing.

dstorozhuk’s picture

Issue summary: View changes
andypost’s picture

@dstorozhuk please provide interdiff from #8 to make review easy https://www.drupal.org/documentation/git/interdiff

andypost’s picture

+++ b/src/Plugin/DisplayVariant/HttpStatusCodeDisplayVariant.php
@@ -35,10 +90,10 @@ class HttpStatusCodeDisplayVariant extends VariantBase {
-      '404' => $options['404'],
-      '403' => $options['403'],
-      '500' => $options['500'],
-    ] + $options;
+        '404' => $options['404'],
+        '403' => $options['403'],
+        '500' => $options['500'],
+      ] + $options;

no reason to change, see https://youtrack.jetbrains.com/issue/WI-26512

dstorozhuk’s picture

StatusFileSize
new2.42 KB
new6.69 KB

Fix the schema label for redirect_location property.
Add interdiff.

podarok’s picture

@dstorozhuk I see schema changed, what about supporting upgrade path?

dstorozhuk’s picture

There are new property added. Nothing changed, nothing removed.
@podarok what particular changes in upgrade path do you mean ?

podarok’s picture

I mean how the schema is going to get updated after module updated for existing site?
In our case we use http://dgo.to/confi to update configs within hook_update_N @dstorozhuk

jlockhart’s picture

Worked perfectly. Thanks. Our use case is a deprecated node whos content hasn't been fully migrated but we don't want shown. I applied the patch (clean), updated my page variant and added the path. No errors and works as expected.

As I don't believe I constitute a community I'm going to leave this as Needs Review :)

vprocessor’s picture

Works good on my side too

dstorozhuk’s picture

Version: 8.x-1.x-dev » 8.x-4.x-dev
andypost’s picture

Status: Needs review » Needs work
Issue tags: +Needs tests

NW
- tests
- upgrade path (hook_update_N to add empty property to existing variants)

dstorozhuk’s picture

@andypost thanks for clear roadmap for that patch. I believe i can create the update path, i will be very appropriate for help with tests.

dstorozhuk’s picture

StatusFileSize
new7.58 KB
new787 bytes

Add update path.

Strange, but I cant chose the page_manager 8.x-4.x-dev for testing. The patch can only apply to page_manager 8.x-4.x-dev, since 8.x-1.x-dev doesn't have function page_manager_update_8002().

manuel.adan’s picture

#30 works for me on 8.x-4.0-beta2 version

jlockhart’s picture

#30 applied just fine on fresh pull of 8.x-4x branch. Works as expected as well.

andypost’s picture

Last patch needs fixes for doc-blocks for new functions, also some nits below

Also still require test coverage

  1. +++ b/src/Plugin/DisplayVariant/HttpStatusCodeDisplayVariant.php
    @@ -20,7 +23,59 @@ use Symfony\Component\HttpKernel\Exception\HttpException;
    +    $this->aliasManager = \Drupal::service('path.alias_manager');
    

    It needs proper DI

  2. +++ b/src/Plugin/DisplayVariant/HttpStatusCodeDisplayVariant.php
    @@ -69,19 +144,96 @@ class HttpStatusCodeDisplayVariant extends VariantBase {
    +      $response = new RedirectResponse($redirect_location, $status_code);
    

    this does not allow remote redirects, maybe use TrustedRedirectResponse...

  3. +++ b/src/Plugin/DisplayVariant/HttpStatusCodeDisplayVariant.php
    @@ -69,19 +144,96 @@ class HttpStatusCodeDisplayVariant extends VariantBase {
    +  private function variableToString($var) {
    

    Better to make it protected

xem8vfdh’s picture

I am having the same problem, I think. I opened https://www.drupal.org/project/page_manager/issues/2932215#comment-12392787, but it looks like it may be a duplicate of this.

Whats the status? This seems to be core functionality for the module.

piggito’s picture

Status: Needs work » Needs review
StatusFileSize
new9.19 KB
new7.41 KB

Applying the fixes suggested in #33 + some coding standard fixes

Status: Needs review » Needs work

The last submitted patch, 35: page_manager-redirect_location-2624972-35.patch, failed testing. View results

piggito’s picture

It seems like tests are failing because of https://www.drupal.org/project/page_manager/issues/2918564

xem8vfdh’s picture

thanks @piggito. What's the next step, simply waiting for that issue you linked to be resolved?

piggito’s picture

@xeM8VfDh I think we should focus on solving the linked issue first cause it is breaking Drupal CI tests for all issues in page_manager.

xem8vfdh’s picture

sounds reasonable to me @piggito. Hopefully that is resolved shortly, and this soon thereafter.

japerry’s picture

Status: Needs work » Fixed

Looked good to me and passes tests. Fixed!

  • japerry committed d99c150 on 8.x-4.x authored by dstorozhuk
    Issue #2624972 by dstorozhuk, kalistos, piggito: No configuration...

Status: Fixed » Closed (fixed)

Automatically closed - issue fixed for 2 weeks with no activity.