-1

I'm having an issue configuring a URL alias that redirects content to a view with a contextual filter.

Here's my working setup:

  1. I have a bunch of content of type SEEL Lesson Plan.
  2. To display these lessons in a Library, I created a view with the path http://example.com/seel/
  3. I set up a contextual filter (Content: Title) on the view. So, if you access http://example.com/seel/eat-an-apple, it will display the lesson with title "Eat an Apple" in the Library.

Here's my objective:

I want to override the "Save" button, so when clients edit any content of type SEEL Lesson Plan, it takes them to the library (http://example.com/seel/eat-an-apple) rather than the content page (http://example.com/content/eat-an-apple).

How do I do that?


Here's what doesn't work:

I added the following URL alias at http://example.com/admin/config/search/path/patterns:

enter image description here

I created a new content of type SEEL Lesson Plan that uses this URL alias. I can see it in my list of URL aliases (http://example.com/admin/config/search/path/list/seel):

enter image description here

But, when I go to http://example.com/seel/fdsa to test it out, it totally messes up. I'd include a screenshot if I could, but the HTML elements are literally all over the place -- displaying below the block on the left sidebar instead of in the main content pane, floating all over the footer, etc.

Here's how I know it's a problem with URL aliases:

When I go back and delete the URL alias seel/fdsa, and then go to http://example.com/seel/fdsa, it displays exactly how I set it up originally in the view.

As well: other lesson plans, for which there is no URL alias, display just fine. (For example: http://example.com/seel/eat-an-apple still works.)

Why is this happening?

  • You have two conflicting routes - seel/* for the node, and seel/* for the View (the View will normally "win" in my experience)...couldn't say why that manifests itself as a broken layout without more info I think, but having two routes with the same pattern is likely to end with weirdness. You mentioned that the content page should be at example.com/content/eat-an-apple, so why add the pathauto alias as well? The node won't be available from the /content path once you've done that – Clive Apr 18 '17 at 21:20
  • And to answer your first question, "How do I do that?", you can take the (a) Site-Building approach: Use the Rules module, or (b) Programmatic approach: Use a custom Form API submit handler function, where you set the $form_state['redirect'] = SOME_DESTINATION;. – Stefanos Petrakis Apr 18 '17 at 22:11
  • @Clive I don't want it to be available from the content/* URL, only through the view. – Lincoln Bergeson Apr 19 '17 at 1:05
  • @StefanosPetrakis Is (b) essentially the same as using .htaccess to set up a 301? – Lincoln Bergeson Apr 19 '17 at 1:06
  • You should set up a redirect then, yes. Currently Drupal is getting confused because you're trying to jam 2 things into a single path. A and B are the same thing by the way, just accomplished with different approaches – Clive Apr 19 '17 at 7:26
0

At @Clive's suggestion, I ditched the idea of trying to do this with URL aliases, and instead set up a redirect with the Rules module.

This was done by going to /admin/config/workflow/rules, clicking "Add New Rule", and reacting on event "Content is viewed".

The final rule looks like this:

enter image description here

And it works :-)

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.