Posts

Installing Drupal 7 using Drush

Drush is raealy handy to do the Drupal stuff ver quick and easy. If you haven't already installed Drush check http://drupal.org/project/drush. Installing Drupal 7 with DRUSH is awsome, with just two simple commands, setting up MYSQL user and DB, note down the passwoprd, then run the following comman. Make sure to replace the user and passwords names for your local setup: drush dl drupal-7.x drush site-install standard --account-name=admin --account-pass=admin --db-url=mysql://MySQLUser:Password@localhost/MySQLDatabase ...and you're done. *Note: The Drupal username and password seemed to always end up as admin/admin. So, just using those and then changing them after you login to your new site.

Override Default Blog View

Image
Drupal by default creates a blog view for evry use at sitename.com/blogs/user-name. To override this view with your custom one, create a page view of content type Blog Entry, with path as "blogs/%". Add "Content: Author" in Relationship. As you can see in below screen shot. Now you need to filter it by the author of content. In contextual filter use "(Author) user: Uid" with selection of "Specify Validation Criteria", Choose user as "Validator". See attached screen shot for this. And there you go. Now what ever url you set in path auto, it will get that automatically.

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...