Drupal dynamic internal redirect

What I want is pretty simple. I have registered a path

function spotlight_menu() {
    $items = array();

    $items['congres'] = array(
        'title' => 'Congres',
        'title arguments' => array(2),
        'page callback' => 'taxonomy_term_page',
        'access callback' => TRUE,
        'type' => MENU_NORMAL_ITEM,
    );

    return $items;
}

When this menu item is triggered, I want to redirect (without changing the url) to a taxonomy page, of which the term is chosen in a function that runs when this function is called.

How can I do this (especcially without changing the url) ?

Answers


You can't call taxonomy_term_page directly as your page callback as you'd need to provide a load function to load the term, which is just going to be too difficult with the setup you've got.

Instead, define your own page callback as an intermediary and just return the output from taxonomy_term_page directly:

function spotlight_menu() {
  $items = array();

  $items['congres'] = array(
    'title' => 'Congres',
    'page callback' => 'spotlight_taxonomy_term_page',
    'access callback' => TRUE,
    'type' => MENU_NORMAL_ITEM,
  );

  return $items;
}

function spotlight_taxonomy_term_page() {
  // Get your term ID in whatever way you need
  $term_id = my_function_to_get_term_id();

  // Load the term
  $term = taxonomy_term_load($term_id);

  // Make sure taxonomy_term_page() is available
  module_load_include('inc', 'taxonomy', 'taxonomy.pages');

  // Return the page output normally provided at taxonomy/term/ID
  return taxonomy_term_page($term);
}

Need Your Help

HTML5 Mirroring webcam canvas

javascript html5 canvas webcam webcam-capture

I'm trying to take a webcam feed - (landscape format), cut out the middle bit (portrait format) and have it render to a canvas so that it fills the screen portrait 1080px by 1920px (for this I scal...

How can I prevent content from disappearing under a Fixed-Header?

javascript jquery html css css3

I'm making an endless page, ie. When a user scrolls to the end of the page, I load more content at the bottom (I'll be loading blog posts to be precise), this is part is finished, However.....

About UNIX Resources Network

Original, collect and organize Developers related documents, information and materials, contains jQuery, Html, CSS, MySQL, .NET, ASP.NET, SQL, objective-c, iPhone, Ruby on Rails, C, SQL Server, Ruby, Arrays, Regex, ASP.NET MVC, WPF, XML, Ajax, DataBase, and so on.