3

在过去的 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() 函数遍历菜单?

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

任何帮助或灯棚都会很棒!先感谢您!

4

2 回答 2

2

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

这是文档链接

于 2012-11-21T06:45:14.527 回答
0

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

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/");





    }
于 2015-10-21T18:54:21.703 回答