Related: http://api.drupal.org/api/file/developer/examples/node_access_example.mo...

I am new to Drupal and this example module confusing very much. I cannot decide which part is changable: node? access? perm?

For example :

node_access_example_perm()

For MyOwnModule how should I name it:

node_MyOwnModule_perm() ?

node_access_MyOwnModule_perm() ??

node_MyOwnModule_access_perm() ???

MyOwnModule_access_perm() ????

access_MyOwnModule_perm() ?????

Comments

carlmcdade’s picture

You'll notice that there are several functions set as hooks. Example hook_menu (or hook_perm). You want to avoid changing those. This means that the last part of the name is most important. Also the first part of the hook name has to be the same as the module name. There are some exceptions but you can be safe with [something_wicked_this_way_comes]_menu. The rest of the functions in the module don't have to follow any set convention. So [something_wicked_this_way_goes]_here is okay since it will only be called locally.

Hiveminds Magazine | FireOrb | Drupal Street | Drupal offline manual

BladeRider’s picture

For the function you are quoting from the example module:

node_access_example_perm() is an implementation of hook_perm().

This means that if you have a custom module, let's say it's called cafewebmasters_stuff.module, you would use:

cafewebmasters_stuff_perm()

...and this leads to the other functions from the node_access_example.module being:

cafewebmasters_stuff_node_grants
cafewebmasters_stuff_node_access_records
cafewebmasters_stuff_form_alter
cafewebmasters_stuff_nodeapi

The general rule is: the first part of the function name is the same as your module's filename, the rest of it is the hook name.