Problem/Motivation
Taxonomy term path options are ignored and not taken into account when constructing the redirection URL.
The issue can be reproduced if you try to override the uri callback using hook_entity_info_alter() and in the callback function pass any URL arguments, such as query string. Create a sample custom module with the following code:
function sample_menu() {
$items['sample'] = array(
'title' => 'Testing page',
'page callback' => 'sample_sample_page',
'page arguments' => array(),
'access arguments' => array('access content'),
'type' => MENU_CALLBACK,
);
return $items;
}
function sample_sample_page() {
$tid = filter_input(INPUT_GET, 'tid', FILTER_SANITIZE_NUMBER_INT);
$output = '<p>' . t('Sample page') . '</p>';
if ($tid) {
$output .= '<p>' . t('Viewing term ID: @tid', array('@tid' => $tid)) . '</p>';
}
else {
$output .= '<p>' . t('The path did not work and term ID is not included in the query string. Try applying the patch.') . '</p>';
}
return $output;
}
function sample_entity_info_alter(&$entity_info) {
$entity_info['taxonomy_term']['uri callback'] = '_sample_taxonomy_term_uri';
}
function _sample_taxonomy_term_uri($term) {
return array(
'path' => 'sample',
'options' => array(
'query' => array('tid' => $term->tid),
),
);
}
Proposed resolution
Merge the $options array with term path options when constructing the redirect for taxonomy terms.
This way if the term path options array is empty, everything will work the same way as before.
Attached is the patch.
API changes
This should not have an impact to anything else.
Thanks!
Comments
Comment #1
aramboyajyan commentedComment #2
jvandyk commentedRan across this while redirecting taxonomy terms to Solr paths which have a query string.
Attached patch is a bit more specific than #1 in that it only merges the query string from the uri_callback result instead of just anything which happens to be in $options (which can include the entity and entity type; see last lines of entity_uri()).
Comment #3
a_thakur commentedPatch in comment #2 works as stated.
Changing to RTBC.
Comment #4
a_thakur commentedComment #5
marty2081 commented+1 for RTBC
Comment #6
trevorkjorlien commentedTested the patch on a custom callback_entity_info_uri() function and it is working correctly. Thanks!
Comment #7
BarisW commentedWorks great. Please commit.
Comment #8
BarisW commentedPing
Comment #9
Anonymous (not verified) commented+1 for patch #2
Comment #10
jvandyk commentedUpdate to patch #2 covering edge case where $term_path['options']['query'] is not defined.
Comment #11
BarisW commentedLooks good to me. Thanks all!
Comment #13
BarisW commentedCommitted to dev