Tag Archives: Drupal 7

Drupal 7 – Allow Facebook login using Facebook Connect

The website i am working now needs to have Facebook Login. I found 3 modules which could implement that feature.

 

Facebook Connect requires the Facebook PHP SDK and the configuration is quite user friendly and this is also the module which i used.

Facebook OAuth provides an API for authentication and does not need the Facebook PHP SDK. It fits for Drupal developesr who wants higher level of customization.

Drupal for Facebook seems to target Facebook application development. I didn’t tried it.
Continue reading Drupal 7 – Allow Facebook login using Facebook Connect

Drupal 7 – Render the Nice Menus programmatically

The following piece of code will print the Nice Menus block.

$menu = theme('nice_menus', array('id' => 1, 'direction' => 'down', 'depth' => 1, 'menu_name' => '<menu-machine-code>', 'menu' => NULL));
print $menu['content'];

 

you can input any value in the <id> parameter and the rendered menu will have the HTML tag id = nice-menu-<id>. Just make sure there is no duplicated nice menu id in the same page.

Done =)

Reference: How to display nice_menus programmatically in Drupal 7

Drupal 7 – Update node programmatically

If you want to update the node programmatically, the following example update the node title and the value of the custom field called field_example.

// Load the node with nid = 1
$nid = 1;
$a_node = node_load($nid);
$a_node->title = 'new title';
$a_node->field_example['und'][0]['value'] = 'new value';

// Save the node
node_save($a_node);

// If you want to populate the node author and creation date, call node_submit() before saving
/*
if($a_node = node_submit($a_node)) {
  // Save the node
  node_save($a_node);
}
*/

 

Done =)

Reference: fooninja.net – Updating nodes programmatically in Drupal 7

Drupal 7 – Set a date fieldCondition in EntityFieldQuery

We can select nodes by conditions using EntityFieldQuery.
Drupal 7 – Get specific nodes using EntityFieldQuery

After I have installed the Date module, I could create a content type with a date field called field_expiry_date. When i setup this field, there are 3 date options in the field type.

  • Date
  • Date (ISO format)
  • Date (Unix timestamp)

Continue reading Drupal 7 – Set a date fieldCondition in EntityFieldQuery

Drupal 7 – Create a Datetime field in hook_schema() @ 2

Yesterday we talked about defining a datetime field for the table created by custom module.
Drupal 7 – Create a Datetime field in hook_schema() @ 1

As i have mentioned in the above post, the datetime field is no longer support by the Drupal Schema API. If you don’t want to use the datetime field, you can try to save the datetime in timestamp format and stored it in an int column.
Continue reading Drupal 7 – Create a Datetime field in hook_schema() @ 2