2012-11-21 2 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/"); 





    }