Blogs | Srijan

Drupal 7 Learnings

Written by Team Srijan | Sep 21, 2011 7:00:00 AM

A few months ago Drupal 7 was released and ever since then we've been working hard to adapt to the changes. Here are some of the things that I've learnt over the last few months. Thought it would be a good idea to share it with the community. Do let me know your thoughts about these in comments section below !

Development Learnings

1) There is a change in the filter format table in d6 and d7
     - In d6 it is named as filter_formats and  in d7 it is filter_format and  even the fields are different.

2) We no longer need drush for migration. Now we can migrate data from the administrator interface itself. But the drawback of this is we can't use the “itemlimit” and “idlist” to restrict node creation.

3) We no longer have the nodeapi function. Now to use any $op of the nodeapi we need to call the function node_<op>.
        e.g. if we wish to call the ‘insert’ $op , we will use hook_node_insert()

4) We no longer have the db_result() function. This is how we can use it in D7 : db_query({...})->fetchField();

5) Learned how to carry out the functionality of sorting the list of contents alphabetically using views and glossary view [default view=> need to enable it].
Even how to show up all the letters whether it contains the content or not by overriding the views tpl i.e. views-view-summary-unformatted.tpl file located in the view module.

6) Learned how panels can be used with menus.

7) We no longer have the db_fetch_array() function. Now the db_result() function will return the prepared statement object, already executed.

8) Argument 2 passed to db_query() must be an array
       eg: db_query('SELECT n.nid, n.title, n.created FROM {node} n WHERE n.uid = :uid', array(':uid' => $uid));

9) Customized the default “addThis module” links. Overridden the theme function of the addthis button function.

10) How to add active classes on the thumbnails being generated using views_slideshow.

11) Mailchimp integration and its working.
      Just create an account in the mailchimp and create a form with all the fields being added.Just copy and paste the code being highlighted under the “Share it” tab.

12) Pulling up the tweets from multiple accounts using the list widget.  
      In the respective account, just create a new lists and visit the profile of the accounts that need to be added. Add the respective accounts in the lists so created and using the list widget embed code, paste the code.

13) In the webform, how to send mails to different mail accounts on submitting the form.
      Under the form components of type “Select list”, instead of inserting the key values just insert the respective mail address and under the email settings, just select the component name.

14) While writing the custom code, for the fields that are not mandatory do ensure that “if” condition is being posed so that the error of “Undefined und in function()” does not occur. E.g,

if($node->field_blog_image != NULL) {
    $img = $node->field_blog_image['und'][0]['uri'];
}

15) How to provide description to the feeds page
     While using views of type feeds, override the template file of “style output” and enter the text to be displayed between the <description> </description>

New Module Implementation:

1) Inline Form Messages:
    Used for showing up the error messages under each fields.

1) Menu_block:
   Used for showing up the menus where active menu parent will be shown as expanded and
   rest parent item as unexpanded.

3) Menu position:
   Used to insert the menu item in the specified position.

4) Unique field:
   Used to mention the fields to be unique in nature like for a textfield to be unique i.e once the
   number has been entered then no other content can contain that same number.

5) Menu attribute:
   Used to add unique id’s, classes and styles to a particular menu item.It becomes easier when javascript or jquery is being applied to the menu item.

6) AddThis module:
   Used to provide the contents to be added on various medium of networks.

7) Views_slideshow:
    Used for providing the slideshow.Customization of this was the new learning

8) Mailchimp
   Used for having integrating the form with the mailchimp.

New API Changes in D7

1) For applying imageache, use
   image_style_url($style_name, $path)
  where,
  $style_name = the imagecache preset
  $path = the path being mentioned in the field[‘uri’]
 
2) For making the image linkable,
   l($text, $path, array $options = array())
   where,
   $text = the one which is to be made linkable
   $path = the path where it is to be linked to
   $options = array(‘html’=>true) [for images]

3) Sql query change. Use
$node_nid=63;
db_query(‘SELECT title FROM {node} WHERE nid=:nid’,array(':nid'=>$node_nid))
foreach() {}

Theming Learnings

1) If you want to add any class in body use yourthemename_preprocess_html function in d7 .

2) If you want create any content type node.tpl.php then use ‘Double hypen’’ ‘--’  ex : node--article.tpl.php in d7 . In d6 we use only ‘Single hypen’ ‘-’

Well, that's what I've learnt till date and will keep on sharing more in future too. Do share what you have learned and help us all learn more :)