I have been using hook_alter to modify forms in a custom PHP module. I started to take the same approach modifying the result page of "node add" form. However this page is not a form so I don't have a form ID to hook on to. Actually it contains a login form, but that does not contain the elements tha开发者_运维百科t I am looking for.
Next I cloned the node.tpl.php file called and called it node-my-content-type.tpl.php. If I add "hello world" to this page, the phrase is displayed at the top, so I know it is working.
However, here all my content seems to be flattened to a single string called $content, so manipulating this becomes very difficult.
What approach should I use in this situation?
You can determine properties of the current user by doing:
global $user;
var_dump($user);
That will show you your account. So if you want to limit something by role, you would do:
if (in_array('administrator', $user->roles)) {
// code
}
But I think you would be much better suited to using CCK and Content Permissions to control field level visibility like this.
The default admin account always has the uid of 1 in the users table, so to do something for everyone except the admin, you could do this:
// Bring the $user object into scope
global $user;
if ($user->uid != 1) {
do something here...
}
精彩评论