I create a view in drupal 7 display a collection of books, and taxonomy for book types .. then I call book type taxonomy in my view and it displayed good .. But because book types taxonomy menu have about 10 items and maybe increased at any time, I want to display 3 items of book types and when click More link display a list of the others, I can't do it in css only, and I can't add a div to group the other part of the list .. so how can I do that?

thank you

when I try to print my exposed filter array

function MYMODULE_form_alter(&$form, $form_state, $form_id) {
  if ($form_id == 'views_exposed_form') {
     $view = $form_state['view'];

    if ($view->name == 'taxonomybooktype' && $view->current_display == 'taxobooktype') {


        $form['field_book_type_tid']['#options']['All'] = "All";

              echo "<pre>";
      print_r($form['field_book_type_tid']);
      exit;
            }
    }

}

output:

Array
(
  [#type] => select
  [#options] => Array
    (
        [All] => All
        [0] => stdClass Object
            (
                [option] => Array
                    (
                        [7] => Chemical
                    )

            )

        [1] => stdClass Object
            (
                [option] => Array
                    (
                        [1] => computer
                    )

            )

        [2] => stdClass Object
            (
                [option] => Array
                    (
                        [6] => History
                    )

            )
    )
[#size] => 
[#default_value] => All
[#theme] => select_as_links

)

but now how can I group first tow options in a div and remain options in another div or group?

  • It would be helpful to know what kind of exposed filter you use and how it is displayed (e.g. checkboxes, select field, links) – berliner Feb 11 '14 at 0:50
up vote 0 down vote accepted

Agreed with MPD, but basically if you want you can also go with $form['#id']

What you can do is, first try to get your $form['#id'] using form_alter

function MODULENAME_form_alter(&$form, &$form_state, $form_id) {
    echo "<pre>";
    print_r($form['#id']);
    exit;
}

Once you get your $form['#id'] you can add a condition, something like this

function MODULENAME_form_alter(&$form, &$form_state, $form_id) {
    if ($form['#id'] == 'YOUR_FORM_HASH_ID') {
        // Your magic code goes here...
    }
}

Let me know, if I can help you in any other way :-)

  • thank you Rishi for your reply, I think this way is very good, but I cant complete it .. I edit my question and put my trying code and display where I stop, so if you have an idea to help me to complete it? .. thank you – Tasneem Mar 5 '14 at 13:15

Exposed filters use the form API, so you can implement a hook_form_FORM_ID_alter():

function MYMODULE_form_views_exposed_form_alter(&$form, &$form_state) {
  $view = $form_state['view'];

  if ($view->name == 'my_view' && $view->display == 'my_display') {
    // do something awesome
  }
}

Normal Form API procedures then apply.

  • Thank you, it seems good , can I get another step .. which print exposed filter items in for loop?!! .. which I want to put first 3 items in div , and remain 7 items in another div !! .. thank you again – Tasneem Feb 9 '14 at 14:18
  • @t.natshah That is a little bit beyond the scope of this site. Basically, you need to read up on the Form API. You need will need to restructure the render tree to put the form elements in two groups, and then use #prefix and #suffix to make your <div> structure. You may also be able to use fieldsets. – mpdonadio Feb 9 '14 at 16:57

Views exposed form layout module helps with Views exposed form theming.

I usually recommend to use the Better Exposed Filters (BEF) module for anything styling related. It gives you a great deal of flexibility concerning UI controlled styling.

But if I understand your question right, then you're neither finished with the suggested solutions (form_alter) nor with BEF. The reason is that your exposed taxonomy term filter is probably rendering the filter as a single form element that you can't easily be split into several divs.

You could try to do the following, assuming you have, say, 3 "promoted" filters that you always want to show. Then you could add one filter of type taxonomy term, display the filter as checkboxes and limit the valid options to those 3 three "promoted" terms and expose the filter. Then add this same filter again, expose it, but this time limit the valid options to all other terms except the three "promoted" ones. You could then use BEF for example to put this second filter inside the secondary options form (this is a BEF setting) or simply make the filter collapsible (also possible so set in the BEF settings).

Another solution to reduce clutter in search interfaces that I recently needed to build for one of my projects uses a javascript based "reducing" approach (no idea how to call that really). I have published it on github if you want to have a look at it: jQuery-UI-reduceOptions-Plugin. It will initially show all checkboxes, but provides ways of interacting that allow to hide unselected options once the form has been submitted (and is reloaded with the new defaults set, or using ajax submission). It's probably not a real drop-in solution but it works pretty neat, see the screenshots:

enter image description here enter image description here

  • thank you berliner for your reply, but when I try to do that, category apply tow filter on my view content, and what I need to apply one filter from both parts of category on my view content. – Tasneem Mar 5 '14 at 13:09

Your Answer

 
discard

By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

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