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

aramboyajyan’s picture

StatusFileSize
new578 bytes
jvandyk’s picture

StatusFileSize
new750 bytes

Ran 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()).

a_thakur’s picture

Patch in comment #2 works as stated.

  • Accessing taxonomy/term/ without the patch does not take into account query parameters
  • After applying the patch the query parameter in altered uri callback is taken into account

Changing to RTBC.

a_thakur’s picture

Status: Needs review » Reviewed & tested by the community
marty2081’s picture

+1 for RTBC

trevorkjorlien’s picture

Tested the patch on a custom callback_entity_info_uri() function and it is working correctly. Thanks!

BarisW’s picture

Works great. Please commit.

BarisW’s picture

Ping

Anonymous’s picture

+1 for patch #2

jvandyk’s picture

Status: Reviewed & tested by the community » Needs review
StatusFileSize
new791 bytes

Update to patch #2 covering edge case where $term_path['options']['query'] is not defined.

BarisW’s picture

Assigned: aramboyajyan » Unassigned
Status: Needs review » Reviewed & tested by the community

Looks good to me. Thanks all!

  • BarisW committed a849eb5 on 7.x-1.x authored by aramboyajyan
    Issue #2228557 by jvandyk, aramboyajyan, BarisW, a_thakur, Marty2081,...
BarisW’s picture

Status: Reviewed & tested by the community » Fixed

Committed to dev

Status: Fixed » Closed (fixed)

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