coder1.com

  • home
  • drupal articles
  • contact
Home

Drupal 6 to 7, a first glimpse

Mike Milano — May 9, 2010 - 11:05pm

Today I finally started porting a module over to Drupal 7. I didn't read up in depth on the changes and just dove in and started learning based on the PHP errors and features that were not working.

I'm not going to go into anything too in depth here as there is good information out there already, but I took some notes and will point out some changes I had to make with the module I was working on.

Admin settings path

Once updating the .info page so I could enable the module, I found the settings page listed at the top level of the administration area.

The admin settings path has changed form admin/settings/your-custom-module to admin/config/your-custom-module

Queries

The result of db queries now return objects that you can run foreach commands on. Here's an example:

  1. <?php
  2. $rows = db_query("SELECT nid, title FROM {node} WHERE type = 'page'");
  3. foreach ($rows as $row) {
  4. $output .= l($row->title, 'node/'. $row->nid);
  5. }

The way you add your variables in the mix has also changed. No need to wrap your tokens if it's a string anymore.

  1. <?php
  2. db_query("UPDATE {table} SET field1 = :mystring, field2 = :myint", array(':mystring' => 'foo', ':myint' => 5);

drupal_get_form

drupal_get_form now only returns the form array and you need to call drupal_render on the form array if you want to get the HTML output.

print drupal_render(drupal_get_form('some_form'));

hook_nodeapi

I was working on another section of code that used hook_nodeapi, $op = 'view' to add content to the page view. hook_nodeapi is now gone and you will need to use hook_node_view. As they broke out each operation of nodeapi into its own hook, it will add more functions, but do away with the nodeapi monster logic we sometimes come across, or write ourselves.

drupal_to_js()

drupal_js is a function in D6 that outputs the data sent in to it as a JSON string. In D7, you should use json_js_output(). Alternatively if you would just like to get the string without printing it, use drupal_json_encode()

  • Drupal

Post new comment

The content of this field is kept private and will not be shown publicly.
  • Web page addresses and e-mail addresses turn into links automatically.
  • Allowed HTML tags: <a> <em> <strong> <img> <cite> <code> <ul> <ol> <li> <dl> <dt> <dd> <h3> <h4> <h5> <h6> <h7>
  • Lines and paragraphs break automatically.
  • You can enable syntax highlighting of source code with the following tags: <code>, <blockcode>. The supported tag styles are: <foo>, [foo].

More information about formatting options

Poll

Have you checked out Drupal 7 yet? (still alpha):

User login

  • Request new password

Navigation

  • Recent posts
  • home
  • drupal articles
  • contact