Drupal7向页面添加自定义菜单



在过去的4个月里,我一直在使用Drupal 7进行开发,对于如何在页面上添加更多菜单,我似乎找不到一个直接的答案。我了解整个system_main_menu和system_secondary_menu,但是如果我制作了一个自定义菜单,比如说我有一个footer_social_menu的话,我怎么能在页面中添加更多菜单呢?我就是喜欢动态菜单。

以下是我现在正在使用的

function cornmaze_links($variables){
$html = '<ul>';
foreach($variables['links'] as $link){
$html .= '<li>'. l($link['title'], $link['href'], $link).'</li>';
}
$html .= '</ul>';
return $html;

}

我尝试使用THEME_links($vars)函数,但这会影响所有菜单,如果我想向自定义菜单添加某个ID怎么办?或者更改自定义菜单以使用所有div?这是我不明白的。我不一定能使用THEME_links()函数循环浏览菜单?

如果不必要的话,我也不想把它们放在一个块里,只是为了避免任何我不需要的额外标记。我只想能够控制菜单,无论是系统菜单还是自定义菜单。

任何帮助或照明都会很棒!提前谢谢!

尝试菜单块模块。它将您的菜单创建为块并且高度可配置。

这是文档链接。

请检查,这可能对您有帮助,

function formuserentry_menu() {
$items = array();
$items['formuserentry'] = array( //this creates a URL that will call this form at "examples/form-example"
'title' => 'Entry Page',
'page callback' => array('formuserentry_view'),
'access callback' => TRUE,
'type' => MENU_NORMAL_ITEM
);
$items['formuserentry/application'] = array( //this creates a URL that will call this form at "examples/form-example"
'title' => 'Entry Application Forms', //page title
'description' => 'A form to mess around with.',
'page callback' => 'drupal_get_form', //this is the function that will be called when the page is accessed.  for a form, use drupal_get_form
'page arguments' => array('formuserentry_application' , 2), //put the name of the form here
'access arguments' => array('administer your module'),
);

return $items;
}

/********** front page view ***********/

function formuserentry_view() {
$result = 'My  Sub Menu URL was hit';
$header = array('Entry Id','Name', 'DOB', 'Year', 'Image' );
$rows = array();
$no_yes = array('No', 'Yes');
$results = db_query("SELECT * FROM userentryform ORDER BY userentryId DESC");
foreach ($results as $node) {
$rows[] = array(
l($node->firstname, 'formuserentry/application/'. $node->userentryId ),

array('data' => $node->firstname, 'class' => 'title'),
array('data' => $node->lastname, 'class' => 'type'),
array('data' => $node->birthyear, 'class' => 'type'),
array('data' => '<img src="sample.jpg">dff', 'class' => 'image'),
);
}
return theme('table', array('header' => $header, 'rows' => $rows));

}
/********************** add form ***************************/

function formuserentry_application($form, &$form_state, $candidateId) {
$firstname = ''; 
$lastname = ''; 
$birthyear = ''; 
/****** query fetch ******/
if(isset($candidateId)){
$fetchquery = db_select('userentryform', 'n')
->fields('n', array('firstname','lastname', 'birthyear'))
->fields('n')
->condition('userentryId',$candidateId)
->execute()
->fetchAll();
$firstname = $fetchquery[0]->firstname; 
$lastname = $fetchquery[0]->lastname; 
$birthyear = $fetchquery[0]->birthyear; 
}
/**************************/
//print($fetchquery);
//drupal_set_message('<pre>'. print_r($fetchquery[0]->firstname, TRUE) .'</pre>');
$form['name'] = array(
'#type' => 'fieldset',
'#title' => t('Name'),
'#collapsible' => TRUE,
'#collapsed' => FALSE,
);
$form['name']['first'] = array(
'#type' => 'textfield',
'#title' => t('First Name'),
'#required' => TRUE,
'#default_value' => $firstname,
'#description' => "Please enter your first name.",
'#size' => 20,
'#maxlength' => 20,
);
$form['name']['canid'] = array(
'#type' => 'hidden',
'#required' => FALSE,
'#default_value' => $candidateId,
'#description' => "Please enter your first name.",
'#size' => 20,
'#maxlength' => 20,
);
$form['name']['last'] = array(
'#type' => 'textfield',
'#title' => t('Last name'),
'#value' => $lastname,
'#required' => TRUE,
);
$form['name']['year_of_birth'] = array(
'#type' => 'textfield',
'#title' => "Year of birth",
'#description' => 'Format is "YYYY"',
'#value' => $birthyear,
'#required' => TRUE,
); 
// Image upload field.
$form['name']['image'] = array(
'#type' => 'managed_file',
'#title' => 'File',
'#upload_location' => 'public://my-files/',
'#process' => array('formuserentry_my_file_element_process'),
"#upload_validators"  => array('file_validate_is_image' => array())
);

$form['submit'] = array(
'#type' => 'submit',
'#value' => 'Submit',
);
return $form;
}
/*********  for validation ************/
> function formuserentry_my_file_element_process($element, &$form_state,
> $form) {   $element = file_managed_file_process($element, $form_state,
> $form);   $element['upload_button']['#access'] = FALSE;   return
> $element; }
> 
> function formuserentry_application_validate($form, &$form_state) {  
> $year_of_birth = $form_state['values']['year_of_birth'];
>     if ($year_of_birth && ($year_of_birth < 1900 || $year_of_birth > 2000)) {
>         form_set_error('year_of_birth', 'Enter a year between 1900 and 2000.');
>     } }
/********** form submission ***************/
function formuserentry_application_submit($form, &$form_state) {
$first_name    = $form_state['values']['first']; 
$last_name     = $form_state['values']['last'];
$year_of_birth = $form_state['values']['year_of_birth'];
$profileimage      = $form_state['values']['image'];
$canid      = $form_state['values']['canid'];
if($canid == '') {
$nid = db_insert('userentryform')
->fields(array(
'firstname' => $form_state['values']['first'],
'lastname' => $form_state['values']['last'],
'birthyear' => $form_state['values']['year_of_birth'],
'profileimage' =>  $form_state['values']['profileimage'],
))
->execute(); 
drupal_set_message(t('The form has been Added your last insert ID is => '.$nid));     
} else {

$nid = db_update('userentryform')
->fields(array(
'firstname' => $form_state['values']['first'],
'lastname' => $form_state['values']['last'],
'birthyear' => $form_state['values']['year_of_birth']
))
->condition('userentryId',$canid)
->execute(); 
drupal_set_message(t('The form has been Updated your last insert ID is => '.$nid));
}
drupal_goto("/formuserentry/");


}

最新更新