You are hereModules
Modules
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
Most of the code has been taken from user.module and adjusted to fit the need we have. So here is the code, ready to use.
* Implements hook_menu().
*/
function password_email_form_menu() {
$items = array();
$items['change-credentials/%user'] = array(
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.
$form['actions']['cancel'] = array(
'#markup' => l(t('Cancel'), 'user'),
'#weight' => '666',
);
}
This will appear on user edit form and bring you back to user page when clicked.
Set the default address on shipping information with smart IP, refresh whole form to have proper counties(administrative area)
The title says it all :) add this to your module, into hook_form_alter and rock
//in otherwise, let this section only happen once, and let ajax make changes as expected
if (!(!empty($_SERVER['HTTP_X_REQUESTED_WITH']) && strtolower($_SERVER['HTTP_X_REQUESTED_WITH']) == 'xmlhttprequest')) {
if ($form_id == 'commerce_checkout_form_checkout') {
Debug entitys etc
When debuging enteties normal dpm with devel module just wont do you any good. So use this
http://drupal.stackexchange.com/questions/33473/is-there-a-good-way-to-i...
and this for debugging or introspecting wrappers
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
global $user;
$account = clone($user);
og_is_member('node', $current_group->nid, 'user', $account)
will check if there is a user(user object) in a organic group, probably currently logged in user.
Inviting Friends/Sending messages over Facebook, Drupal module/snippet
There is a cool Facebook feature that you can easily implement, inviting or sending messages to Facebook friends with Facebook SDK
Just build a module, a block or whatever you want and put this code in
What is important is to have a FB app and FB APP ID that you have set in some variable, I am using it here with
variable_get('fb_app_id', NULL)
We are using here SEND https://developers.facebook.com/docs/sharing/reference/send-dialog but you can also use other types like invite, request etc https://developers.facebook.com/docs/games/requests/v2.1
Advanced modal forms - modal windows with CTools (singe and multistep)
So I client of mine wanted to use popups :) but not just ordinary popups, he wanted to put there, login, registration, node adding, notificiations, user invites for OG, simple menus and even FB login and registration. We also needed to save some user choices before the login/registration and act upon them after the user logs in. So spoiler alert now "if you want to save budget and time" dont't use modal windows or any popups for complex workflows.
Fixing some fatal errors
Recently I got to fix some older Drupal 6 site. It had WSOD so I needed to add this to index http://drupaldump.com/wsod-or-white-screen-death-and-error-reporting and then I saw sort of this error "Fatal error: Unsupported operand types in common.inc" so I used this post https://www.drupal.org/node/362799 and added this code to the "l" function, and solved this bugger.
echo " "; $backtrace = debug_backtrace(); var_export($backtrace[0]); die(); }
Load another node after CTools modal window is submited
Continuing from http://drupaldump.com/ctools-modal-window-return-message-same-modal-window we can also do some more stuff after one modal is submited, we can load another content in it. For example a whole node, we just need to load it and then render it properly. Problem you can encounter is that you will need to change the modal size
$output = array();
$node = node_load(7);
// Content for modal window:
$contents = render(node_view($node, 'full', NULL));
CTools modal window, return message in the same modal window
I wanted to have a confirmation message in modal window, instead of closing the modal and having it on normal page. All that is needed is to check form_state after submit and add this part of code in form function
{
$form = array();
....
if ( $form_state['submitted']){
$output[] = ctools_modal_command_display('Success', '
');
print ajax_render($output);
exit;
}
return $form;
}
and you will have this message in modal window.
p.s.