I am creating a drupal module (my first) and I wish to simply store some variables.
I previousely did this by adding some form elements to the theme-settings.php file but now I want to have my own module.
I created my module and form and menu elements and that all seems to be fine. Problem is that nothing seems to be saving to the database. Or maybe is is saving but not retreiving.
This is what I have so far:
my_module.module:
/**
* @file
* My Module Settings.
*/
/**
* Implements hook_help().
*/
function mynewmodule_settings_help($path, $arg) {
/* INFO:
* The help hook is for displaying helpful messages at the top of pages indicated
* by $section to further explain how they work. Adding certain "keywords" to the end of
* a given path (like admin/modules#description) will cause this text to display elsewhere
* in the page as well (in this case, in the description section for the given module).
*/
switch ($path) {
case 'admin/help#mynewmodule_settings':
return t("TODO: Create admin help text for My Module.");
case 'admin/config/system/mynewmodule':
return t('My Module help text will go here.');
}
}
/**
* Implements hook_permission().
*/
function mynewmodule_settings_permission() {
return array(
'administer my module' => array(
'title' => t('Administer My Module Settings'),
)
);
}
/**
* Implements hook_menu().
*/
function mynewmodule_settings_menu() {
$items = array();
$items['admin/config/system/mynewmodule'] = array(
'title' => 'My Module Settings',
'description' => 'Administer My Module Settings',
'page callback' => 'drupal_get_form',
'page arguments' => array('mynewmodule_admin_settings'),
'access arguments' => array('administer my module'),
'type' => MENU_NORMAL_ITEM,
'file' => 'mynewmodule_settings.admin.inc',
);
return $items;
}
And here is my form (mynewmodule_settings.admin.inc):
// $Id$
/**
* @file
* My Module Settings
*
* @author Cybercampbell
*/
/**
* Admin configuration form
*/
function mynewmodule_admin_settings() {
$form = array(
'#type' => 'fieldset',
'#title' => t('My Module Settings'),
'#collapsible' => FALSE,
'#collapsed' => FALSE,
);
$form['breadcrumb'] = array(
'#type' => 'fieldset',
'#title' => t('Breadcrumb'),
'#collapsible' => TRUE,
'#collapsed' => FALSE,
);
$form['breadcrumb']['breadcrumb_display'] = array(
'#type' => 'checkbox',
'#title' => t('Show breadcrumb'),
'#description' => t('Use the checkbox to enable or disable Breadcrumb.'),
'#default_value' => theme_get_setting('breadcrumb_display','mymodule'),
'#collapsible' => TRUE,
'#collapsed' => FALSE,
);
/**
* SOCIAL
*/
$form['social'] = array(
'#type' => 'fieldset',
'#title' => t('Social Settings'),
'#collapsible' => TRUE,
'#collapsed' => FALSE,
);
/**
* FACEBOOK
*/
$form['social']['facebook_display'] = array(
'#type' => 'checkbox',
'#title' => t('Facebook'),
'#description' => t('Use the checkbox to enable or disable the Facebook button.'),
'#default_value' => theme_get_setting('facebook_display','mymodule'),
'#collapsible' => TRUE,
'#collapsed' => FALSE,
);
$form['social']['facebook_id'] = array(
'#type' => 'textfield',
'#title' => t('Facebook ID'),
'#default_value' => theme_get_setting('facebook_id','mymodule'),
'#size' => 32,
);
/**
* TWITTER
*/
$form['social']['twitter_display'] = array(
'#type' => 'checkbox',
'#title' => t('Twitter'),
'#description' => t('Use the checkbox to enable or disable the Twitter button.'),
'#default_value' => theme_get_setting('twitter_display','mymodule'),
'#collapsible' => TRUE,
'#collapsed' => FALSE,
);
$form['social']['twitter_id'] = array(
'#type' => 'textfield',
'#title' => t('Twitter ID'),
'#default_value' => theme_get_setting('twitter_id','mymodule'),
'#size' => 32,
);
/**
* RSS
*/
$form['social']['rss_display'] = array(
'#type' => 'checkbox',
'#title' => t('RSS'),
'#description' => t('Use the checkbox to enable or disable the RSS button.'),
'#default_value' => theme_get_setting('rss_display','mymodule'),
'#collapsible' => TRUE,
'#collapsed' => FALSE,
);
// Attach custom submit handler to the form
$form['#submit'][] = 'mymodule_settings_submit';
$print_footer_text = theme_get_setting('print_footer');
$form['print_footer'] = array(
'#type' => 'text_format',
'#title' => t('Footer Text'),
'#rows' => 5,
'#resizable' => FALSE,
'#default_value' => !empty($print_footer_text['value']) ? $print_footer_text['value'] : '',
'#format' => !empty($print_footer_text['format']) ? $print_footer_text['format'] : 'full_html',
);
return system_settings_form($form);
}
This code worked fine in the theme.settings.php file. Any ideas where i'm going wrong here?