Background
Client has Event webforms hosted externally by a marketing automation service, leading to an unusual situation: a node of Event content type should have its summary displayed in certain Views on the client site, but navigating directly to the node address should result in a 301 redirect to the offsite form.
Client can achieve this manually by using the Redirect module:
/admin/config/search/redirect/add?redirect=node/1234
... and then entering the node path in the From field and the offsite destination in the To field. (Yes, this is exactly backwards, but it kind of works.) However, they would like to automate this process.
I tried to do this with Rules:
Events:
- After saving new content of type Event
- After updating existing content of type Event
Conditions:
- NOT Data value is empty (Parameter: Data to check:
[node:field-external-url]
)
Actions:
- Page redirect (Parameter: URL:
[node:field-external-url]
)
Unfortunately, this does not modify the Page Redirect settings on the node by adding an entry to the redirect
table in the database.
Instead, it fires a one-time system event and redirects the site administrator to the desired URL at the moment that the Event content node is created or updated. Subsequent visits to the node URL do not redirect site visitors; instead, they see the node at that URL.
So, I'm trying a different approach, with a small custom_event_redirect
module:
/**
* Implements hook_form_alter().
*/
function custom_event_redirect_form_alter(&$form, &$form_state, $form_id) {
// add submit handler only to Event content forms
if ($form_id === 'event_node_form') {
array_unshift($form['#submit'], 'custom_event_redirect_search_form_submit');
}
}
/**
* Drupal FAPI submit handler implementation
*/
function custom_event_redirect_search_form_submit(array $form, array &$form_state) {
if (!empty($form['field_external_url']['und'][0]['value']['#default_value'])) {
//create redirect programmatically
}
}
Is it possible to use the Redirect API to fire off a redirect_edit_form_submit()
when the event_node_form
is submitted?
This is such an edge case. Google results are skewed heavily toward drupal_goto()
redirects after form submission -- but if that was what I wanted, I could have used Rules.
I don't want to fire off a one-time redirect on form submission; I want to add an entry to the redirect
table on form submission.
¯\_(ツ)_/¯
I don't want the site editor redirected once on form submission
well then add a condition of when user role is not admin nor editor.redirect
table on form submission." The problem is with the action fired, not the user role.