theme_get_setting() 和 THEME_settings() 已被删除

theme_get_setting() 和 THEME_settings() 已被删除

In Drupal 6, themes could add custom form elements to their “configure theme settings” page at admin/build/themes/settings/THEMENAME. Themes would need to create a theme-settings.php page in their theme directory and use a function with the following syntax:

<?php
/**
* Implementation of THEMEHOOK_settings() function.
*
* @param $saved_settings
*   array An array of saved settings for this theme.
* @return
*   array A form array.
*/
function phptemplate_settings($saved_settings) { }
?>

In Drupal 7, much more flexibility is given to themes to modify the entire theme settings form. In a theme’s theme-settings.php, themes should now use a THEMENAME_form_system_theme_settings_alter(&$form, $form_state) function. This gives the same power to themes that modules have if they use hook_form_system_theme_settings_alter(). See the “Forms API Quickstart Guide” and “Forms API Reference” on http://api.drupal.org/api/7, as well as the hook_form_FORM_ID_alter() docs to learn the full flexibility of Forms API. Note that themes can no longer use the phptemplate_ prefix to the function; you’ll need to use the actual name of your theme as the prefix.

Here’s an example if you had a “foo” theme and wanted to add a textfield whose default value was “blue bikeshed”:

<?php
function foo_form_system_theme_settings_alter(&$form, $form_state) {
 
$form['caberet_example'] = array(
   
'#type'          => 'textfield',
   
'#title'         => t('Widget'),
   
'#default_value' => theme_get_setting('foo_example'),
   
'#description'   => t("Place this text in the widget spot on your site."),
  );
}
?>

In order to set the default value for any form element you add, you’ll need to add a simple line to your .info file: settings[SETTING_NAME] = DEFAULT_VALUE. For our foo theme, you’d need to edit the foo.info file and this line:

settings[foo_example] = blue bikeshed

In any of your theme’s php files, you can retrieve the value the user set by calling:

<?php
$foo_example
= theme_get_setting('foo_example');
?>

同步内容