💾 Archived View for chirale.org › 2008-11-21_226.gmi captured on 2024-09-28 at 23:50:32. Gemini links have been rewritten to link to archived content

View Raw

More Information

⬅️ Previous capture (2024-05-12)

-=-=-=-=-=-=-

Customize exposed filter on Drupal View

Tested on:

When you have to filter a view by a content type, you have to use Exposed filters. Since default list is somewhat ugly (a select with some elements and CTRL to be pressed) we transform it in simple checkboxes.

Copy and paste this code into your template.php:

# I use imagecache because on my site is active # and doesn't use hook_form_alter /bin /boot /dev /etc /home /init /lib /lib32 /lib64 /libx32 /lost+found /media /mnt /opt /proc /root /run /sbin /srv /sys /tmp /usr /var Display checkboxes instead select for exposed views filters */ function imagecache_form_alter($form_id, &$form) { if($form_id == 'views_filters' && arg(0) == 'change_to_your_view_path_before_slash') { if(!empty($form)) { foreach ($form as $id => $field) { if ($form[$id]['#type'] == 'select' && $form[$id]['#multiple'] == 'multiple') { # from select to checkboxes $form[$id]['#type'] = 'checkboxes'; foreach($form[$id]['#options'] as $key=>&$content) { # hide from list all content types that aren't mycontenttype or mycontenttype2  if($key!='mycontenttype' && $key!='mycontenttype2'){ unset($form[$id]['#options'][$key]); } } } } } } }

To hide operators dropdown, you have to check “lock operators” on views page.

See also:

https://web.archive.org/web/20081121000000*/http://drupal.org/node/158607

</ul>