0

How do I add #markup or #suffix to MENU_LOCAL_TASK in Drupal?

$items['user/%/checkins_history'] = array( //add to to user's profile
            'type' => MENU_LOCAL_TASK,
            'title' => t('Checkins History'),           
            'suffix' => '<div>Num'.$num_of_results .'</div>', // NOT WORKING            
            'access arguments' => array('Administer Checkins'),
            'page arguments' => array(1),
            'file' => 'manager.inc',
            'page callback' => 'manager_checkins_history_page'
        );
2

What you're asking doesn't really make sense.

MENU_LOCAL_TASK is used as metadata for a route defined in hook_menu().

#prefix and #suffix are properties for render arrays.

The two concepts are not compatible.

|improve this answer|||||
1

Your calling this from hook_menu, correct? I don't believe that suffix can be used from here. At least it's not in the list of valid return values in listed on the hook_menu page.

You'll need to add the suffix to whatever the output of your url is, if it's a form, it can nicely be added to the form via the form api.

Example:

Let's say your function manager_checkins_history_page is a form that uses the form aip, and looks something like this:

function manager_checkins_history_page($form, &$form_state){

  $form['switch'] = array(
    '#type' => 'checkbox',
    '#title' => t('i'm a chekcbox'),
    '#default_value' => false,
  );

  $form['submit'] = array(
    '#type' => 'submit',
    '#value' => t('Submit'),
  );

  return $form;
}

if you wanted to apply a suffix to the whole form, you could do something like:

function manager_checkins_history_page($form, &$form_state){
  $form['group1'] = array(
    '#type' => 'fieldset',
    '#title' => t('Your Name'),
    '#suffix' => "I'm a suffix for your form",  
   );

  $form['group1']['switch'] = array(
    '#type' => 'checkbox',
    '#title' => t('i'm a chekcbox'),
    '#default_value' => false,
  );

  $form['group1']['submit'] = array(
    '#type' => 'submit',
    '#value' => t('Submit'),
  );

  return $form;
}

That would give you a form, wrapped in a box, with a suffix at the end.

|improve this answer|||||
  • can you show me an example? – Grasper Nov 20 '14 at 15:55
  • @Grasper, check out my edit. Again, I'm working under the assumption that this looks like an edit page for checkins, and if that's the case might be a form call back. If that is incorrect, please post your call back function to get a better answer. The long and short of it is, hook_menu sets up the page callbacks, and the content should be provided in the callback, so your suffix should be coming from there. – Jance Nov 20 '14 at 16:08
  • drupal is just a mess...compared to WP. The tab only displays data, no form inside. I hate drupal with all my heart, lol – Grasper Nov 20 '14 at 16:11
  • Ok, in that case you should just be able to append the content of your suffix to the return value of manager_checkins_history_page. so you don't really need '#suffix' in this case. And drupal has a bit of a learning curve, so don't get too flustered. That's why we're here ;) – Jance Nov 20 '14 at 16:21
  • @Grasper are you trying to add a suffix as a means to work around Drupal's plaintext title restriction? There's other ways to skin that cat. – murraybiscuit Nov 20 '14 at 16:55

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.