Search code examples
drupaldrupal-6faceted-search

Drupal: Re-using faceted search blocks


The faceted search module in Drupal creates a set of blocks for each new faceted search environment (current search, guided search, related, etc).

If you were to create a faceted search environment for e.g. books, you could set it up with a base path browse/books and a start page as browse/books/results. To display the faceted search blocks, you'd then set the Page Specific Visibility settings for the block as 'Show on only the listed pages' and the actual pages as

browse/books
browse/books/results*

Question: I would like to re-use the 'guided search' block on a different landing page. The landing page should display a list of available search terms (sidebar-left) and show a view over the rest of the page.

So far, simply adding a different path to the list of 'show on only the listed pages' has no effect.


Solution

  • Drupal veterans would likely be able to offer better, cleaner and more correct solutions, but the following works for me:

    I added a new block which runs the following PHP:

    $env = faceted_search_env_load ( $fs_env_id );
    if (!$env->ready()) 
    {
        $env->prepare();
        $env->execute();
    }
    faceted_search_ui_add_css();
    $env->ui_state['stage'] = 'results';
    print faceted_search_ui_guided_block($env);
    

    $fs_env_id depends on your setup. The links generated by the API will link to the actual faceted search environment paths, as expected.