Page 1 of 1
how to write the function return?
Posted: Fri Jul 09, 2010 3:10 am
by everydayrun
Code: Select all
function annotate_menu() {$items['admin/settings/annotate'] = array('title' => 'Annotation settings','description' => 'Change how annotations behave.','page callback' => 'drupal_get_form','page arguments' => array('annotate_admin_settings'),'access arguments' => array('administer site configuration'),'type' => MENU_NORMAL_ITEM,'file' => 'annotate.admin.inc',);return $items;}
Code: Select all
function annotate_admin_settings() {$options = node_get_types('names');$form['annotate_node_types'] = array('#type' => 'checkboxes','#title' => t('Users may annotate these content types'),'#options' => $options,'#default_value' => variable_get('annotate_node_types', array('page')),'#description' => t('A text field will be available on these content types tomake user-specific notes.'),);return system_settings_form($form);}
the above are two functions and each have a return value. but the return value are all irregularly, now if i want to design a function how to write the function's return.
Re: how to write the function return?
Posted: Fri Jul 09, 2010 3:14 am
by Apollo
Ehh.. what?
Perhaps you need
this?
Re: how to write the function return?
Posted: Fri Jul 09, 2010 10:58 am
by Jonah Bron
Lets clean that up a bit.
Code: Select all
function annotate_menu() {
$items['admin/settings/annotate'] = array(
'title' => 'Annotation settings',
'description' => 'Change how annotations behave.',
'page callback' => 'drupal_get_form',
'page arguments' => array('annotate_admin_settings'),
'access arguments' => array('administer site configuration'),
'type' => MENU_NORMAL_ITEM,
'file' => 'annotate.admin.inc'
);
return $items;
}
Code: Select all
function annotate_admin_settings() {
$options = node_get_types('names');
$form['annotate_node_types'] = array(
'#type' => 'checkboxes',
'#title' => t('Users may annotate these content types'),
'#options' => $options,
'#default_value' => variable_get('annotate_node_types', array('page')),
'#description' => t('A text field will be available on these content types tomake user-specific notes.')
);
return system_settings_form($form);
}
Re: how to write the function return?
Posted: Sun Jul 11, 2010 1:54 am
by everydayrun
i want to know why on the above the function's return line are "return $items" and "return system_settings_form($form)", could i instead of it using others?
eg:return system_settings_form($form)", i use this "return $form" to place of it.
Re: how to write the function return?
Posted: Sun Jul 11, 2010 11:17 am
by cpetercarter
Of course you can change the functions so that they return different values. But if you do so, you are likely to find that your programme does not work at all, or produces strange and unpredictable outcomes.
Take your second function, annotate_admin_settings(), for example. It returns system_settings_form($form). This means that it takes the value of $form, and uses it as an input in the function system_settings_form(), and returns the output. I don't know what system_settings_form() does exactly, but I guess that it turns the array $forms into the html needed to display a form on the webpage. So changing the return value of annotate_admin_settings() to $forms would have a radical effect on this part of the programme, and would probably give you a broken Drupal installation.
Does that help?