How to show name field in signup form drupal 7 - drupal

I am using Profile 2 to add fields in registration form in drupal 7.
now i want to show name fields before username and password fields, how can i do it ?

Edit: I'm sorry, I had misunderstood your question (left my previous answer for history).
Try Profile2 Registration Path. It promises to merge both your account and profile information on a custom path. Use the .htaccessfile to redirect from user/register to the new URL or install one of the various redirect modules.
Afterwards you might want to follow the approach from my previous answer to correct the order:
Use hook_form_alter to set the weights of the fields according to your needs. You can do so by inserting somthing similar to
function yourthemename_form_alter(&$form, &$form_state, $form_id) {
if ($form_id == 'user_register_form') {
$form['field_firstname']['#weight'] = -20;
$form['field_lastname']['#weight'] = -19;
}
}
in the template.php of your theme.
Be aware that I'am using the build in profile fields instead of Profile2 but it should work the same way. If you're not sure how your profile fields are to be accessed download and enable develmodule, set permissions to allow guests to access developer information and insert a dpm($form)in the above function.

Related

Drupal user permissions & odd content types

I have a permissions problem in Drupal. I want users to be able to create a certain node type, but there are two different paths I need to give them permissions for to let them do this. The type is content created by a module called isbn2node, and there are two ways to make content through it, each with different paths:
?=node/add/isbn2node-book
?=node/add/isbn2node_book/isbn2node
One has an underscore and the other one has a hyphen. The first path leads to a form that lets users enter information on a book manually; the second path lets them enter an ISBN, searches for it, and populates the form for them based on the results.
I've changed permissions in the People menu so they can add isbn2node-book content manually using the first path, but there isn't an option to let them use the second method. Aliasing the url so it didn't have node/add in the path didn't work either.
Creating a duplicate content type seems like an ugly solution to this; is there a more elegant way to let users access that second path?
A little code in a custom module using hook_node_access should do it.
$node is either a node object or the machine name of the content type on which to perform the access check (if the node is being created then the $node object is not available so it will be a string instead).
So this should do it:
function MY_MODULE_node_access($node, $op, $account) {
if ($op == 'create') {
$type = $node;
if($type == 'book' && $account->uid) return NODE_ACCESS_ALLOW;
}
}
I figured this out, and the issues I was having were specific to this content type. The ISBN2Node module requires users to have the Administer Nodes permission to use its lookup and bulk import features.
There is some extra code for the module's hook_permission and hook_menu sections submitted as a fix in the module's issues thread.

Modify the title given in hook_menu() from another module

How can I change the title given to the /user/[uid] page from Your account to Welcome [user name] for logged-in user, where [user name] is the username for the currently logged-in user?
Use hook_menu_alter.
Alter the data being saved to the {menu_router} table after hook_menu is invoked.
Code sample:
function MYMODULE_menu_alter()
{
global $user;
if($user->uid != 0)
$items['user']['title'] = 'Welcome ' . $user->name;
}
You should be able to accomplish this with the Menu token module:
Menu Token module provides tokens, that could be used in title or in path of menu items (links).
(It requires the popular Token module.)
Note that with Drupal 7.23, the user.module includes a 'title callback' to determine if the user is logged in or not, and respond with a corresponding title.
Code that worked for me (through theme template, instead of a custom module):
function YOURTHEME_menu_alter(&$items) {
$items['user']['title callback'] = 'YOURTHEME_user_menu_title';
}
function YOURTHEME_user_menu_title() {
global $user;
return user_is_logged_in() ? t($user->name) : t('User account');
}
The String Overrides module should make this easy.
In Drupal 7, hook_menu() and hook_menu_alter() are just invoked when the data about routes implemented from modules needs to be refreshed, for example when a module is enabled, disabled, installed, or uninstalled. An implementation of hook_menu_alter() that uses the name of the currently logged-in user in the title would show the same username for different users.
Differently, the title callback associated with a route is called every time the page associated with that route is rendered.
The correct code would be similar to the following one.
function mymodule_menu_alter(&$items) {
$items['user']['title callback'] = 'mymodule_user_profile_title';
}
function mymodule_user_profile_title() {
global $user;
return user_is_logged_in() ? t('Welcome, #name', array('#name' => format_username($user))) : t('User account');
}
Notice that the first argument of t() needs to be a literal string, not a dynamic value as in t($user->name) because the database table containing the string translations would not contain the translation for every username used in a site.
It is also wrong because the shown username is invariant respect the language used on a site: For example, in an Italian site, a username like Albert isn't translated to Alberto, nor Vincent is translated to Vincenzo.
When showing a username in the UI, it is always preferable to use format_username(), which allows to third-party module to change what shown as username. (For example, a module could show the content of a user field, instead of showing the login username.)
If you aren't willing to write custom code, you could use the String Overrides module. If you don't want to use any module just for changing the title of the user profile page, you could add the following code in the settings.php file used for the site.
$conf['locale_custom_strings_en'][''] = array(
'My account' => 'Welcome to my site'
);
Notice that, either using the String Overrides module or adding the $conf['locale_custom_strings_en'][''] array in the settings.php file, you cannot:
Provide a string that changes basing on the logged-in user (which is what the question is asking for)
Provide a string that is used only on specific pages
The latter case could be a pro or a con. If the string that needs to be changed is generic enough, it would be replaced even when it should not.

How do I CC someone when an order is placed?

I am using Ubercart with Drupal.
How do I CC someone when an order is placed? I will probably have to modify the code somewhere because it should only happen under a certain theme, but I'm not sure where to even edit this.
I went to admin/store/ca and created an action. I used the products as a condition and it works.
An easy solution is to use the hook_mail_alter() in a small stub module.
This hook will let you add add to the email generated by another module.
You will need to dig into the ubercart code to find the specific $mailkey for the email you want to change.
http://api.drupal.org/api/drupal/developer--hooks--core.php/function/hook_mail_alter/6
function myhack_mail_alter(&$message)
{
if ($message['id'] == 'the ubercart mail key')
{
//$message['headers']['Bcc'] = 'myemail#example.com';
$message['headers']['cc'] = 'myemail#example.com';
}
}
One way to find the message key is to add the following to your function, then have the site send the email. This function will dump the keys to the dblog.
watchdog('MailKey', $message['id'], {}, WATCHDOG_INFO);

Is there a way to output users name as a link to profile in Drupal?

Im using pathauto so user profiles have a clean URL in the format /user/name-name
How can I output the users name as a link to the profile? Ive seen the theme() function used to do stuff similar to this?
Use the l() function to create the link and make the link to user/uid. When using l, it will be converted to whatever you set it up to in pathauto.
If you want the user's name as the text of the link, use theme('username', $account); where $account is the fully-loaded user object from user_load().

Drupal using views with CCK custom fields

I've got a Drupal site which uses a custom field for a certain type of node (person_id) which corresponds to a particular user. I want to create a view so that when logged in, a user can see a list of nodes 'tagged' with their person_id. I've got the view working fine, with a url of my-library/username but replacing username with a different username shows a list of all nodes tagged with that user. What I want to do is stop users changing the URL and seeing other users' tagged nodes. How can I do this? Is there somewhere where I can dictate that the only valid argument for this page is the one that corresponds with the current logged in user's username?
person_id = uid?
In this case, add argument with user:uid, then in Validation options select PHP Code, read comment of this field carefully:
Enter PHP code that returns TRUE or
FALSE. No return is the same as FALSE,
so be SURE to return something if you
do not want to declare the argument
invalid. Do not use . The
argument to validate will be
"$argument" and the view will be
"$view". You may change the argument
by setting "$handler->argument".
Add this code:
global $user;
$account = user_load('name'=>arg(1));
$handler->argument = $user->uid;
return $account->uid == $user->uid;
I'm not sure how you have setup your view, which gives some different options to solve this. A way that should work would be to set the default argument be the logged users id/username and remove the argument from the url.
Alternatively you could create your own filter which requires some work with the views API, but gives more control.

Resources