3

I have been developing with Drupal 7 for the past 4 months now, and I can't seem to find a straight answer as to how to add more menus on my pages. I understand the whole system_main_menu and system_secondary_menu, but how in the world can I add more menus to my page if I make a custom menu, let's say I have a footer_social_menu? I just love dynamic menus.

Here's what I am working with right now

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

}

I tried using the THEME_links($vars) function, but that affects ALL of the menus, what if I wanted to add a certain ID to a custom menu? or change the custom menu to use all divs? That's what I don't get. I can't necessarily loop through the menus using the THEME_links() function?

I don't want to put them in a block either, if I don't have to, just to avoid any extra markup that I don't need. I just want to be able to control menus, whether they be system or custom.

Any help, or light shed would be awesome! Thank you in advance!

2 Answers 2

2

Try menu block module. It creates your menus as blocks and highly configurable.

Here's the documentation link.

Sign up to request clarification or add additional context in comments.

1 Comment

Yeah, I have used and tried that, but I want to be able to understand without a module, if it can even be done?
0

Please Check , this may be help ful for you,

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





    }

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.