开发者

drupal_get_form page callback usage

function example_menu() {
  $items['admin/config/example'] = array(
    'title' => 'Example',
    'description' => 'example configuration',
    'page callback' => 'drupal_get_form',
    'page arguments' => array('example_admin_settings'),
    'access arguments开发者_运维百科' => array('administer example'),
    'file' => 'example.admin.inc',
    'file path' => drupal_get_path('module', 'example'),
  );
  return $items;
}

In the above code I am confused how it works. The page callback is drupal_get_form and the page arguments is example_admin_settings. My question is how exactly does this work?

I know that drupal_get_form probably ends up calling example_admin_settings which return system_settings_form. Could someone point me to the right docs?


You're on the right path.

When you access admin/config/example, drupal_get_form('example_admin_settings') is executed. example_admin_settings() itself will return an array which has its contents based on the form api, something like:

$form['name'] = array(
    '#type' => 'input',
    '#title' => 'Insert your name here: ',
);
$form['submit'] = array(
    '#type' => 'submit',
    '#value' => 'Submit',
);

return $form;

Drupal will render and output the form automatically for you.
Also, consider posting your next questions about Drupal at https://drupal.stackexchange.com/.


this is example is like making something like this

function example_menu() {
  $items['admin/config/example'] = array(
    'title' => 'Example',
    'description' => 'example configuration',
    'page callback' => '_my_page_content_function',
    'access arguments' => array('administer example'),
    'file' => 'example.admin.inc',
    'file path' => drupal_get_path('module', 'example'),
  );
  return $items;
}

function _my_page_content_function(){
 return drupal_get_form('example_admin_settings') ; 
} 

function example_admin_settings($form, $form_state) {
  ... return my form 
}

in your example you asking drupal to create page and the content of this page is the content that returned by the function drupal_get_form when we pass the argument example_admin_settings to it.

SUMMARY:

page callback is the name of the function that return the content of our page when we pass the argument page aruguments to

sorry for my english mmmm need more details ?

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜