how to write the function return?

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
everydayrun
Forum Commoner
Posts: 51
Joined: Wed Jan 20, 2010 1:30 am

how to write the function return?

Post 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.
User avatar
Apollo
Forum Regular
Posts: 794
Joined: Wed Apr 30, 2008 2:34 am

Re: how to write the function return?

Post by Apollo »

Ehh.. what?

Perhaps you need this?
User avatar
Jonah Bron
DevNet Master
Posts: 2764
Joined: Thu Mar 15, 2007 6:28 pm
Location: Redding, California

Re: how to write the function return?

Post 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);
}
everydayrun
Forum Commoner
Posts: 51
Joined: Wed Jan 20, 2010 1:30 am

Re: how to write the function return?

Post 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.
cpetercarter
Forum Contributor
Posts: 474
Joined: Sat Jul 25, 2009 2:00 am

Re: how to write the function return?

Post 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?
Post Reply