I'm going to Paris this September for DrupalCon; as a professional Drupal developer it is an extremely useful event, and as a full-time web geek it's a great place to socialize with other people who do the same kind of work. I would also like the chance to present on some of the Drupal-as-a-GeoCMS work that has been happening this spring in front of a large audience who will ask sharp questions and then go use our work in their own projects.
I've entered a video contest for a conference ticket refund-- I've been wanting to make a movie with these toys since Easter:
You can vote for me on the DrupalCon Paris site and by rating my video on YouTube. You can also see the other contest entries listed as video responses under the original contest announcement.
Fairly often in Drupal I get handed arrays that have significant keys, but the values are either a label or false-y. I generally don't care about the items with empty values, or I specifically want to remove them. The solution is to use array_filter($arr) to remove any array items with false-y values. In fact, sometimes I don't even care about the labels at all, in which case I might do array_keys(array_filter($arr)). Examples below.
$arr = array(
'key1' => 'Label 1',
'key2' => 'Second Label',
'key3' => 0,
'key4' => 'Label No. 4',
'key5' => 0,
);
$arr_filtered = array_filter($arr);
/*
$arr_filtered = array(
'key1' => 'Label 1',
'key2' => 'Second Label',
'key4' => 'Label No. 4',
);
*/
$arr_filtered_keys = array_keys(array_filter($arr));
/*
$arr_filtered_keys = array(
'key1',
'key2',
'key4',
);
*/
array_filter() can also take a callback as the second argument, which lets you filter out items on your own terms. See the array_filter() documentation.
I develop with Drupal 6 at work. One of the things I've been finding useful recently is writing field formatters. Field formatters are handy because they're used to format CCK field content when it gets displayed in nodes and also to format fields in Views. You can choose between formatters for each field of a node type under the 'Display' tab in the node type's settings. In Views, if you choose a display type that uses fields, you can select a different field formatter when you add each field.
To write your own field formatters, you implement hook_field_formatter_info(), then create theme functions for your formatters and add them to your hook_theme() implementation. At one point this was documented in examples packaged with CCK, but it seems the examples are no longer part of the CCK download.
A simple hook_field_formatter_info() implementation looks like this:
/**
* Implementation of hook_field_formatter_info().
*/
function example_field_formatter_info() {
return array(
'myformatter' => array(
'label' => t('My Formatter'),
'field types' => array('text'),
'multiple values' => CONTENT_HANDLE_CORE,
),
);
}
myformatter". Using "x_formatter" or "x_module_name" here makes the theme key name confusing.CONTENT_HANDLE_CORE means that the formatter is called separately for each value in the field. If a field contains multiple values, then the formatter is called multiple times. Field content is passed to the formatter in $element['#item']. This is the default.CONTENT_HANDLE_MODULE means that the formatter is called only once for a field, and the theme formatter gets all the field values at once. In this case, field content is passed to the formatter in $element[0]['#item'], $element[1]['#item'], $element[2]['#item'], etc. Note that the $elements array contains other information about the field, such as $element['#field_name']You will need to add the field formatter theme function to your hook_theme() implementation:
/**
* Implementation of hook_theme().
*/
function exmaple_theme($existing, $type, $theme, $path) {
return array(
'example_formatter_myformatter' => array(
'function' => 'theme_myformatter',
'arguments' => array('element' => NULL),
),
);
}
example_formatter_myformatter' is constructed from {module name}_formatter_{formatter name}.'function' => 'theme_myformatter' line; the default theme function name in this case would be 'theme_example_formatter_myformatter'.The formatter function itself should return a stuff that is ready to output to the browser:
/**
* Theme function for myformatter from hook_field_formatter_info().
* @param $element
* Array of formatter info and the item to theme. Field contents will either be
* in $element['#item'] or $element[$i]['#item'].
*/
function theme_example_formatter_myformatter($element) {
return strtoupper($element['#item']['safe']);
}
This field formatter simply displays the contents of the text field in all caps. You'll need to clear your cache before your new formatter shows up in the field display choices.I've been trying to think of a snappier way to introduce my birthday list this year, but nothing is surfacing. So: I'm turning 25 next week, this is a list of things I want for my birthday. If you send something via email, put "birthday list" in the subject line and I will not open it until the 18th.
In December I started working as a web developer at the Chicago Technology Cooperative. We do a lot of work with Drupal, and most of our clients are nonprofits. I recently attended Drupalcon Boston and with two of my coworkers presented a session on Drupal as a GIS/Mapping Platform.
This site is an aggregation of things I do on the web. I've also kept a blog while I was learning Drupal, collaborated with my friend Ben on Panlexicon and Pantextual, and, during my year as an Americorps VISTA, I worked on the website of the California Coalition for Rural Housing (CCRH), CCRH's California Inclusionary Housing Policy Search, and the website of the CTC VISTA Project.
I'm using MagpieRSS to aggregate my blogs' RSS feeds on this page.
You can get in touch with me by sending email to bec dot white at gmail dot com.