Drupal Dump

Drupal Snippets, Hacks and more....

495 posts since 2011

Page to change only password and email

We needed to have a custom page or a block to only change email and password on that page, and the other user info we separated in different page. Sounds like a nice solution for users. So what we did is the following.

-custom menu item
-custom form
-validation and submit

Cancel button on drupal forms

This one is short but sweet. Usually drupal forms don't have cancel buttons that bring you back to previous page, so lets add one.

Drush

If you are running into this error while using drush

Directory ..../drush/cache/default exists, but is not writable. [error] Please check directory permissions.

Run this to solve it


sudo drush version
sudo chown -R $USER ~/.drush

Some clever functions to check current users, subscribe to organic group etc

I have been building a custom module that has Inviting users to a group feature in it. So there are this helper functions that are very useful.

user_load_by_mail($invitee_email)

will check if there is a user with specific mail, returning false if it is not, returning user object if there is one user with that email

Drupal 301 redirect to another domain

This is not so much drupal but sometimes you will move your drupal site to other domain, so then to have your home and all other pages properly redirected add this code to your .htaccess file

Options +FollowSymLinks
RewriteEngine on
RewriteRule (.*) http://www.some-domain.co/$1 [R=301,L]