0

I'm trying to get my module to work: it replicates an exposed filter of a view into a block to display on other pages. Altering the form generally works, but it unfortunately works globally, ie. my changes are also applied to the original filter form on the views page. That's because I use a simple checking of $delta which does not give me a context - sort of module signature that embedded the form.

I tried both hook_form_alter and hook_form_FORMID_alter - the variables passed to those functions don't seem to carry that info though.

Is there a way to get this kind of context?

1 Answer 1

0

If you are displaying this block on only certain pages, looking at $_GET['q'] or arg(#) will tell you that path or one of its arguments, so maybe you can switch on that? eg, path/to/my/page is in $_GET['q'] and arg(2)=='my'. Note that paths to nodes are system paths, not aliases, so the path might be just node/# but you can do a drupal_get_path_alias() to find it if need be. If you are displaying the block only on certain node types, you can grab $node=menu_get_object() and then switch on $node->type as an example as well. In fact, if you do it that way, $node->path should already point to the aliased path, and it's already cached for your performance pleasure :)

Oh, and failing all the above, you could do all of this in a custom module block, too, eg, in there do something like:

$block['subject']='// subject goes here';
// do the hook form alter
$content=views_embed_view( // the view in question );
$block['content']=$content;

return $block;

All of the php above presumes D6, minor changes apply to D7, but since it is being called in the block itself, the form alter should only change the view there (unless it is also being displayed elsewhere on the same page)

2
  • Well, this of course popped into my mind, but this seem to be not scalable. I thought we had something more versatile. But I noticed that controls have an array labeled #theme which contains some kind of a context: views_exposed_form__[view-name]__block_1. This could probably be tested with a strpos - closer, although still not perfect. Commented Mar 30, 2012 at 19:43
  • indeed. a lot of times print_r()'s of arguments will shed some light on a lot of hidden information inside a $view.
    – Jimajamma
    Commented Mar 30, 2012 at 19:47

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.