Skip to content

Links to basketball training videos

Exposing custom module fields to exposed filters on a view in Drupal.

Much thanks to http://www.gregeisenman.info/ with link at http://www.gregeisenman.info/blogs/greg/views-2-and-drupal-adding-custom-field-views-query.

In case that link goes down, it involved using hook_views_api() and hook_views_data().

Here is what I did:

In my custom module’s .module file (mymodule.module) I added an implementation of hook_views_api():

/**
* Implementation of hook_views_api().
*/
function mymodule_views_api() {
return array(
'api' => 2,
'path' =>
drupal_get_path('module', 'mymodule'),
);
}
?>

Then, I added a views.inc file to my modules folder named mymodule.views.inc.

I then added the following code to expose two fields from my custom module to the view and to the view filters. In the code below, the is the name of a table used to store data for my custom module. It joins to node directly. I used an INNER join, but that can be removed to default to a LEFT JOIN.

/**
* Implementation of hook_views_data().
*/
function mymodule_views_data() {
$data['‘] = array(
‘table’ => array(
‘group’ => ‘My Custom Data’,
‘title’ => ‘‘,
‘join’ => array(
‘node’ => array(
‘type’ => ‘INNER’,
‘left_field’ => ‘nid’,
‘field’ => ‘nid’,
),
),
),
‘name’ => array(
‘title’ => t(’name’),
‘help’ => t(’A name generated
by the mymodule module.’),
‘field’ => array(
‘handler’ => ‘views_handler_field’,
‘click sortable’ => TRUE,
),
// Information for accepting a value as a filter
‘filter’ => array(
‘handler’ => ‘views_handler_filter_string’,
),
// Information for sorting on a value.
’sort’ => array(
‘handler’ => ‘views_handler_sort’,
),
),
‘description’ => array(
‘title’ => t(’description’),
‘help’ => t(’An abstract generated
by the mymodule module.’),
‘field’ => array(
‘handler’ => ‘views_handler_field’,
‘click sortable’ => TRUE,
),
// Information for accepting a value as a filter
‘filter’ => array(
‘handler’ => ‘views_handler_filter_string’,
),
// Information for sorting on a value.
’sort’ => array(
‘handler’ => ‘views_handler_sort’,
),
),
);

return $data;
}
?>

That is the quick and dirty on how I go it going in my project. Thanks again to http://www.gregeisenman.info/ for http://www.gregeisenman.info/blogs/greg/views-2-and-drupal-adding-custom-field-views-query.

Parallels, FreeBSD, OS X, Ruby on Rails, Mongrel, whew…

I decided I needed to learn RoR. I tried to convert an old Dell Dimension 4100 to a FreeBSD server for local development and ran into some network adapter trouble… I’ll have to see if the office has some nics I can try… Anyway, I decided to run a vm and found two incredibly helpful posts by Jason Noble (http://jasonnoble.org/2008/09/setting-up-freebsd-vm-with-parallels.html and http://jasonnoble.org/2008/09/installing-ruby-on-rails-in-freebsd.html).

When starting the sample site using script/server, I did receive an error (”undefined method `camelize’ for “app”:String”), so i installed ruby-iconv (thanks http://john.vipvip.com/blog/?p=71) and the sample app was active.

Also, in order to access the site running in Parallels in the FreeBSD vm from the host OS X os, I had to make sure my parallels vm was setup using Bridged Ethernet under Network Adapter Options. Once that was set, I could hit it via its local network address, for example, http://192.168.x.x:3000/users.

Next, I switched from Webrick to Mongrel just by installing the gem: gem install mongrel.

Everything now looks ready to start a real application.

Thanks to all for the helpful posts.

Working Around Pocket IE Crash Bug

I discovered my site would crash the pocket IE browser on my IPAQ. After some googlin’, I found that there is a bug in the way pocket ie parses some css tags… Anyway, I simply added a non-breaking space to the nav bar on the right side of my site, which added a little space at the top, but looks fine and actually gave it a little breathing room… This breaks up the order in which pocket ie reads the html and prevents the crash. If anyone has found a better way to deal with this, please let me know… I need to update this posting with more detail when time allows…