Posts

Resetting Drupal Passwords in Drupal 7 with Drush

Sometimes, whether in testing or other situations, you need to reset a password (often the admin password) for a Drupal site. The shortest answer is that two wonderful options are built into drush! # Get an admin login link drush uli # Set the password for any user drush upwd admin --password="newpassword"

How to Reset Root Password in Drupal 7 with phpMyAdmin

Image
Copy the hash.. $S$C6x2r.aW5Nkg7st6/u.IKWjTerHXscjPtu4spwhCVZlP89UKcbb/ (that’s the hash for newPassword ).   Navigate to your phpMyAdmin (likely in your control panel online somewhere). Then browse the User table for the Root user, look like his. Take the copied hashed text and paste it into the pass field of the Root user and hit “Go”. See this If you want to reset Drupal pasword using Drush .

Drupal - List User's Author

Drupal by default donot provide user's author detail in views or any where in data base. Once I went through this kind of requirnment to list users with detail, who created those users. A simple way in D7 is to add text field in "user_register_form". That field will be hidden and will get current user's detail in it. We will do this using a module with hook_form_alter. Say you added a text field in user registration form with name "field_authortxt" Add the following code in .module file function custom_user_author_form_alter(&$form, &$form_state, $form_id) { if(( $form_id == "user_register_form") || ( $form_id == "user_profile_form")){ $lang = $form['field_authortxt']['#language']; global $user; $form['field_authortxt'][$lang][0]['value']['#default_value'] = $user->name; $form['#after_build'][] = '_tansnippet_after_build'; } } Now we need to hid...

The form has become outdated. Copy any unsaved work in the form below and then reload this page.

This may have several reasons to appear.. In my case I found it as I was missing "$form['form_token']" in my template file of user register form. As a from need to have $form['form_build_id'] $form['form_id'] $form['form_token'] to proceed for proper submissions. Note: Above values are hidden values. Drupal - Custom Login Redirect to current page

Code snippet: How to set the disabled or readonly attribute of a CCK field

Here's a code snippet that you can use to set the disabled attribute of a CCK field. First, you need to create a small module containing the following code: ssf /** * @file * Custom module to set the disabled attribute of CCK fields. */ /** * Implementation of hook_form_alter(). */ function mysnippet_form_alter(&$form, $form_state, $form_id) { if (isset($form['type']) && isset($form['#node'])) { // Use this check to match node edit form for a particular content type. if ('mytype_node_form' == $form_id) { $form['#after_build'][] = '_mysnippet_after_build'; } // Use this check to match node edit form for any content type. // if ($form['type']['#value'] .'_node_form' == $form_id) { // $form['#after_build'][] = '_mysnippet_after_build'; // } } } /** * Custom after_build callback handler. */ function _mysnippet_after_build($form, &$form_state) { // Use...

Attaching files to nodes programmatically in Drupal 7

$filename = 'image.txt'; $image = file_get_contents('http://www.ibiblio.org/wm/paint/auth/gogh/gogh.white-house.jpg'); $file = file_save_data($image, 'public://' . $filename, FILE_EXISTS_RENAME); $node->field_image = array(LANGUAGE_NONE => array('0' => (array)$file)); Source from.... http://stackoverflow.com/questions/5129559/attaching-files-to-nodes-programmatically-in-drupal-7

Drupal - Custom Login Redirect to current page

To redirect an html login link to back to the current page, (You were on), we need to use $_SERVER['HTTP_REFERER'] with hook_form alter.. For example if you are using a link like... Login any where in the site... function custom_login_redirect_form_alter(&$form, &$form_state, $form_id) { if ($form_id == 'user_login') { $form['#submit'][] = 'goback';// go back will be called on submit } $uri = request_uri(); if (($uri == "/user/login") && (!isset($_SESSION['last_page']))) { $_SESSION['last_page'] = $_SERVER['HTTP_REFERER']; } } go back is the function that will be added to submit array to be called after login form is submitted.. Here we are keeping the URL of the last page in "$_SERVER['HTTP_REFERER']" and storing it to some session with name "last_page" When submit is hit, it calls the function in '$form['#submit'][]' i-e ...