2012-11-21 98 views
2

過去4個月,我一直在用Drupal 7進行開發,而且似乎無法找到如何在我的頁面上添加更多菜單的直接答案。我瞭解整個system_main_menu和system_secondary_menu,但是如果我製作自定義菜單,我可以在世界中添加更多菜單,比如我有footer_social_menu?我只是喜歡動態的菜單。Drupal 7將自定義菜單添加到頁面

這裏是我與現在

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($瓦爾)功能的工作,而是一種影響所有的菜單,如果我想添加一個的某個ID到自定義菜單?或更改自定義菜單以使用所有div?這是我沒有得到的。我無法使用THEME_links()函數遍歷菜單嗎?

我不想把它們放在一個塊中,如果我不需要,只是爲了避免任何額外的標記,我不需要。我只想要能夠控制菜單,無論是系統還是自定義。

任何幫助,或光棚將是真棒!先謝謝你!

回答

2

嘗試menu block module。它將您的菜單創建爲塊並且高度可配置。

這是documentation link

希望這有助於...穆罕默德。

+1

是的,我已經使用和嘗試,但我希望能夠理解不帶模塊,如果它甚至可以做什麼? –

0

請檢查,這可能會幫助FUL你,

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





    } 
相關問題