Showing posts with label Drupal 7. Show all posts
Showing posts with label Drupal 7. Show all posts

Tuesday, March 1, 2016

Remove the password hint details in drupal register page

You can use the below code remove the password hint details in drupal register page.

/**
 * Implements hook_element_info_alter().
 */
function HOOK_element_info_alter(&$types) {
  if (isset($types['password_confirm']['#process']) && (($position = array_search('user_form_process_password_confirm', $types['password_confirm']['#process'])) !== FALSE)) {
    unset($types['password_confirm']['#process'][$position]);
  }
}

Note: Please clear form cache after adding

Remove the user tab link in user login page and user register page

We can use the below code to remove the user tab link in user login page and user register page.

/**
 * Implementation of hook_menu_alter().
*/
function HOOK_menu_alter(&$items) {
  $items['user/login']['type'] = MENU_CALLBACK;
  $items['user/register']['type'] = MENU_CALLBACK;
  $items['user/password']['type'] = MENU_CALLBACK; 
}

Note: Please clear the menu cache after adding this function

Thursday, September 18, 2014

Malformed image URL in Node Edport module in Drupal 7

If you are getting Malformed image URL in Node export. Then you have to change the code in Node Export module

Try to use image_create_url() instead of url() in node_export.module file: Line 1052

- $export_data = url($file->uri, array('absolute' => TRUE));
+ $export_data = file_create_url($file->uri, array('absolute' => TRUE));

Monday, February 24, 2014

Delete operation in Drupal 7

The following function is used to delete file and file usage in Drupal 7.
file_data($file);

The following db function is used to delete a record from a table in Drupal 7.
db_delete('table')->condition('field', $value->execute();

The following drupal function is used to delete a node in Drupal 7.
node_delete($nid);
Multiple node delete: node_multiple_delete(array($nid1, $nid2));

The following drupal function is used to delete a user in Drupal 7.
user_delete($uid);
Multiple user delete: user_multiple_delete(array($uid1, $uid2));

The following drupal function is used to delete a content type in Drupal 7.
node_type_delete($type);

Friday, February 21, 2014

Use file_prepare_directory() instead of file_check_directory()

In Drupal 7, use file_prepare_directory() instead of file_check_directory() from Drupal 6.

Drupal 6 file_directory_path not exists in Drupal 7

Drupal 6 file_directory_path not exists in Drupal 7. Use variable_get('file_public_path', conf_path() . '/files'); instead of file_directory_path();

The following function is return file directory relative path:  drupal_realpath('public://')

Thursday, February 13, 2014

Image not imported in Drupal 7 migration from Druapl 6

In node_export drupal module having issue to import images/files in Drupal 7

Fixed:
In Drupal 7, we have to use file_create_url() instead of url() in node_export.module line no 1052 - Refer - https://drupal.org/node/1264256

Tuesday, December 31, 2013

Apply row style template in Drupal 7

We can design or apply our own design to drupal views (row style) in Drupal 7.

*) Goto Views -> Block or Page view -> Advanced -> Other -> Theme: Information.
*) Create the template file in your custom theme folder. Possible template file name can be created from "Row style output" in Theme: Information.
*) If required, please apply "Rescan template files" button.
*) Once rescan done, your template will be shown as bold.
*) Then press "Row style output" link, copy the code and paste into your template file.
*) Then you can design or apply your own design.

For Example: 
Create views-view-fields--<view name>--<view machine name>.tpl.php in theme folder
And apply the following code

<div class="ownclass">
    <a href="<?php echo $fields['field_link']->content; ?>">
        <?php echo $fields['field_image']->content; ?>
    </a>
</div>

Thursday, December 26, 2013

Get rows count in Drupal 7

<?php

$query = db_select('table1')->fields('users')->execute();
$count = $query->rowCount();

?>