2

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 that 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?

googletorp
  • 33,075
  • 15
  • 67
  • 82
bert
  • 287
  • 6
  • 14
  • 1
    actually realized that $content was not what I should be looking at. The $node array is passed in as well and can be used in a similar way as $form was used in a form. Now I have to figure out how to determine if user is administrator or not. – bert Apr 18 '10 at 15:12
  • What are you even trying to do? – Kevin Apr 18 '10 at 16:02
  • Have you defined an "administrator" role and assigned users to it, or are you just trying to determine if the user is your default admin user that you created during the install process? – flamingLogos Apr 18 '10 at 16:47
  • Kevin: I am trying to modify default view node page to exclude specific elements such as longitude and latitude values for everyone but administrator. Flaming: indeed I mean default admin. – bert Apr 18 '10 at 17:09
  • Lat/long values from a location node type can be controlled directly in the content type if I am not mistaken. – Kevin Apr 18 '10 at 19:14

2 Answers2

1

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.

Kevin
  • 13,153
  • 11
  • 60
  • 87
0

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...
}
flamingLogos
  • 5,971
  • 4
  • 37
  • 44