Drupal 7 learning curve
I've been playing around with Drupal 7 a fair bit, and it's awesome—it really is. I think that I definatley owe the people responsible a beer or two next time I see them... oh, wait—that's a community of thousands who contributed, tested and devoted a whole bunch of time to make this thing happen. I've got 20 bucks and once that's gone, it's gone :)
Anyhoo, lots of things in Drupal 7 have moved or changed from Drupal 6. In this blog post I'm just keeping a list of the things that I scratched my head looking at for 30 minutes or so, only to realize the answer was right in front of me. Hopefully this will save some other folk a whole bunch of time.
SIDENOTE: Also - really pumped to be doing another 'Teaching folk how to use Drupal' course in Vancouver in March (provisionally). This time the topic might be building a 'Brochureware' site out of the box with Drupal 7. That's like a simple website for a small company or something like that. Brochureware isn't the best term really—sounds a bit corporate. Keep your eyes peeled for that one. Stoked to be working with some awesome Vancouver Drupal Peeps on this program. Drupal Training for all!
Here's my list of time saving tips:
Taxonomy
So you go and create a new Vocabulary in Drupal 6 and you get to specify what node types the taxonomy applies to right there, right on the same form you use to add the vocabulary. In Drupal 7, this has dissappeared. What you need to do in Drupal 7 is go ahead, add the vocabulary, add in some terms, and then go to the content type fields page and add a new 'Taxonomy Term' field.
This makes sense because Taxonomy uses the new Field API, but took me a few minutes of stumbling around to put 2 & 2 together and realize that to add the taxonomy to a node type in Drupal 7, you do it at the content type level (while in Drupal 6 it's at the Taxonomy level).
drupal_schema_install
hook_install and hook_uninstall AUTOMATICALLY call drupal_install_schema and drupal_uninstall_schema respectfully. You had to include this in your install/uninstall hooks in drupal 6. Took me a while to figure out why I was getting 'This table already exists' error messages.
Adding a body/description textfield to a custom node type
I like to create my custom node types in code, it's just better that way and everything is in code and can be kept in revision control. For some reason, in Drupal 7 you have to add this wierd code to your hook_install if you want your custom node type to have a Drupal body field:
function mynodetype_install() {
// Ensure the node type is available.
node_types_rebuild();
$types = node_type_get_types();
node_add_body_field($types['mynodetype'], 'Body input label');
}
See http://api.drupal.org/api/drupal/modules--node--node.api.php/function/hook_form/7 , specifically the comment at the bottom for more details.
db_affected_rows is no more
A db_select query will always return 0 or more results. Use count($result) to determine whether there were any results returned. I always used to use db_affected_rows, but I think that was just bad practice from me. To count affect edit rows, append your query with ->rowCount(). So:
db_select('yourtable') -> fields('myfield')->execute()->rowCount()
theme_table parameters have changed
This one caught me out for a while! Now you just send a bit whopping array of the old parameters—see: http://api.drupal.org/api/drupal/includes--theme.inc/function/theme_table/7 . This pretty much goes for every theme function, e.g. http://api.drupal.org/api/drupal/includes--theme.inc/function/theme_item_list/7
hook_block has been exploded
Drupal 6's hook_block has been exploded into a whole bunch of other functions: http://api.drupal.org/api/search/7/hook_block . See http://drupal.org/node/995868 for an okay post on how to make it all come together in D7, although to get started you just need to check out hook_block_info and hook_block_view.
Nifty new preprocess_html
So you want your module to add a helpful class to the <body> tag. You need to use the MODULE_OR_THEME_preprocess_html() function:
function MODULE_OR_THEME_preprocess_html(&$vars) {
if(SOME CONDITION) {
$vars['classes_array'][] = 'myclass';
}
}
Do you have a helpful D6 -> D7 tip to add?
Use the comments below. As I find other things I'll post them as a comment too!











