Posts

Drupal 7 - First Time Login Redirection

I was trying tocome up with a solution for first time login redirection and after that redirection to user profile edit page every time a user logged in. For that I created a role, "First Time Login". Then created a rule using rules module. It will assign role "First Time Login" to a newly created user. Then in the following code, in module "custom_login_redirections" using hook_user_login redirected user to the "Welcome Page" of it has role "First Time Login". // Comment function custom_login_redirections_user_login(&$edit, $account) { if (!isset($_POST['form_id']) || $_POST['form_id'] != 'user_pass_reset') { if(isset($account->roles[30])){ if(in_array($account->roles[30], $account->roles)) { $options = array( 'absolute' => TRUE, 'query' => array('destination' => '#overlay=node/17973') ); $redirec...

Drupal - Hiding field group and its Children

It came to me when I was trying to hide field_group on account page. Searching on I found the following solution using hook_form_alter // Comment /** * Implements hook_form_FORM_ID_alter(). */ function MODULE_form_node_form_alter(&$form, &$form_state) { global $user; // The 'internal' field groups should only be accessible for regional administrators. if (!in_array('regional administrator', $user->roles)) { foreach (array('group_action_internal', 'group_company_internal', 'group_topic_internal') as $fieldgroup) { if (isset($form['#fieldgroups'][$fieldgroup]) && isset($form['#group_children'])) { // Hide the field group itself. $form['#fieldgroups'][$fieldgroup]->format_type = 'hidden'; // Hide the elements inside the field group. foreach ($form['#group_children'] as $field => $group) { if ($group == $fieldgroup) { ...

Some Useful Drush Commands

Downloading modules:  $ drush dl module_name It will automaticly download extracted module to modules folder in your project. Enabling modules: $ drush en module_name Disabling modules: $ drush pm-disable module_name Unistalling modules: $ drush pm-uninstall module_name Clear Cache:  You can use the following command to clear all cache of your site. $ drush cc all List modules: $ drush pm-list --type=module And if you want to list only non core modules, you can use $ drush pm-list --type=module --no-core --pipe SQL dump: $ drush sql-dump > filename.sql It will automatically take the dump of the database of the project in which you are. status (st) Check the Status: Provides a birds-eye view of the current Drupal installation, if any. $ drush status Check the Recent Watchdog:  To list the recent watch dog status, us the following. $ drush ws ws referes to Watchdog show. Database connection detail: Provides a bi...

Installing Drupal - On Lamp

Here we will see how to install Drupal on a LAMP environment. We can do it using two ways, one is downloading it manulay and other is install it using DRUSH.(We will see how to install drush in next sections.) Downloading and Extracting Drupal  You can download latest Drupal by going to https://drupal.org/project/drupal are by using any utility. Here we will be using wget in shell. wget http://ftp.drupal.org/files/projects/drupal-x.x.tar.gz You can replace x.x with the version you want to download. For example.. wget http://ftp.drupal.org/files/projects/drupal-7.22.tar.gz Now time to exteact the file you just downloaded. tar -zxvf drupal-7.22.tar.gz After extracting you can move files in drupal-7.22.tar.gz directory one level "up" into the web server's document root or your public HTML directory. mv drupal-7.22/* /var/www/local.mysite.com/docroot NOTE: In your web server's configuration file the base URL for your Drupal installation wil...

Set menu item active using custom code.

If you want to set a menu item of the main menu as active (class="active"). Here is how you can do this.. function mymodule_init() { $link=menu_link_load(2570); $link["options"]["attributes"]["class"]="active"; menu_link_save($link); } 2570 is mlid of that perticuler menu item. You can check it by editing that perticuler menu item "admin/build/menu/item/2570/edit" Now, I just want to set it active on some specific pages... like "mypage01", "mypage02" etc function mymodule_init() { if((arg(0) == 'mypage01') || (arg(0) == 'mypage02')) { $link=menu_link_load(2570); $link["options"]["attributes"]["class"]="active"; menu_link_save($link); $menu_active = 1; } else { if($menu_active == 1) { $link=menu_link_load(2570); $link["options"]["attributes"]["class"]=""; m...

Downgrading PHP 5.4 to 5.3 on Ubuntu

Download the shell script from here Once you have php5_4_downgrade_5.3.sh file you need to change the permissions using the following command su root chmod u+x ./php5_4_downgrade_5.3.sh Now you can run the script using the following command sudo sh php5_4_downgrade_5.3.sh Follow the on instructions

Illegal offset type in isset or empty pathauto.inc:180

In my scenario, I was using "simplexml_load_file" and getting values in variable. if ($child2->getName() == 'job_title') { print $node_title = $child2; } passing $node_title to node->title using node object and was saving it. It was working well in browser, when i was running script. But created a drush command for it 'drush impvac', which was resulting in docroot$ drush impvac Illegal offset type in isset or empty pathauto.inc:180 [warning] Illegal offset type pathauto.inc:223 [warning] It was because node->title was not getting a plain string from xml, so just added 'check_plain' to dp my stuff. if ($node_title != '') { $node->title = check_plain($node_title); } And all was set.