I'm trying to start writing drupal 4.7 modules but can't get past this simple problem.
As a registered user with "can set import news" permission i can't access module settings page, while as a first user / admin I can and is works.

Here is this simple code. What am I missing, so that registered user with opted out "can set import news" perm will be able to access drupal/admin/settings/import_news"?

<test code>
//Define new permissions that can later be used by this module.
function import_news_perm(){

 return array('can import news','can set import news');

}//function import_news_perm()

//Module settings
function import_news_settings(){

        if (user_access("can set import news")) {
          $form['import_news_maxdisp'] = array('#type' => 'textfield', '#title' => t('Maximum number of links'), '#default_value' => variable_get('import_news_maxdisp', 3), '#description' => t("The$......
          return $form;
        }

}//function import_news_settings()

</test code>

Comments

heine’s picture

hook_settings is governed by the 'administer site configuration' setting (see hook_menu from system.module).

Solution: create a hook_menu that defines a path and access settings for the renamed function (eg mymode_custom_settings_page).
--
The Manual | Troubleshooting FAQ | Tips for posting | Make Backups! | Consider creating a Test site.

hexa’s picture

Tnx, now i did it this way:

//Add entry to menu for access to settings page
function import_news_menu($may_cache) {
 $items = array();
        if ($may_cache) {
         $items[] = array(
         'path' => 'import_news_settings',
         'title' => 'import news settings',
         'callback' => 'import_news_my_settings',
//       'callback arguments' => '',
         'access' => user_access('can set import news'),
//       'weight' => '0',
         'type' => MENU_NORMAL_ITEM
         );
        }
 return $items;
}//function hook_menu()

function import_news_my_settings(){
 echo MySettingsPageDisplayText;
}//function import_news_my_settings

And it works, now i have two more questions ;-)

1. Where to store my module settings?
I could store them to my table in the database or
could use drupals in-build variable storage, how - where is the turorial on this (can't find it :-( )

2. How to get to display (MySettingsPageDisplayText) text in my new function in a layout consistent page?
By that i mean now i see only the MySettingsPageDisplayText and none of the menu's or blocks or even page header.

Thank you for your help.

hexa’s picture

i think the anwser for 2. might be somth like:
print theme('page', 'bla');
i'm going to test it now. Hope it works ;-)

hexa’s picture

I'm still looking for the solution for the problem num. 1 ;-)

sangamreddi’s picture

All settings will be stored in variables tables, no need to storing to another table or queries.

Sunny                      
www.gleez.com | www.sandeepone.com

heine’s picture

If you use hook_settings, then they will be stored in the variables table. If you use your own page (menu callback) however, then you have to save the variables yourself. You can either create a special table or (when it's more a settings) store the variable with variable_set('var_name', $value)
--
The Manual | Troubleshooting FAQ | Tips for posting | Make Backups! | Consider creating a Test site.

hexa’s picture

Cool, thank you.
Looks like variable_set('var_name', $value) is the right way to go since i'm not using hook_setting but callback function from hook_menu ;-)