Hi All,

Actually my requirement is create a contact page for user and all the contact details should be showed in content page as a tab after comments tab at admin side using module. For this I have created a module and using this module I have created a contact page for user and also created database table to store contact details.

Now I am facing the issue i.e., when I tried to show the contact user details in a tab in Content page after comments it is not working. I am able to create a tab, when it is clicked content is not showin. Can anyone help me in this. I used below code to create a tab and displaying content.

function new_menu() {
$items['new'] = array(
'title' => 'Contact',
'page callback' => 'drupal_get_form',
'page arguments' => array('new_form'),
'access arguments' => array('new module'),
// 'access callback' => TRUE
);
$items['admin/content/contacts'] = array(
'title' => 'Contacts',
'description' => "Manage your site's book outlines.",
'page callback' => 'drupal_get_form',
'page arguments' => array('node_admin_content123'),
'access arguments' => array('new module'),
'type' => MENU_LOCAL_TASK,
);

return $items;
}
function node_admin_content123($path) {
if ($path == 'admin/content/contacts') {
echo '
' . t('New module contact page') . '

' .
'

' . t('contact description...') . '

';
}
}

what code should i write to display content when I clicked custom tab in content page.

Thanks Inadvnace...

Comments

Jaypan’s picture

First, if you wrap your code in <?php ?> tags, it will be easier for us to read.

Next, you are setting the 'page callback' for your tab as 'drupal_get_form', but the function you are passing as page arguments is not a form definition. Instead, you should do this:

$items['admin/content/contacts'] = array(
  'title' => 'Contacts',
  'description' => "Manage your site's book outlines.",
  'page callback' => 'node_admin_content123',
  'access arguments' => array('new module'),
  'type' => MENU_LOCAL_TASK,
);

Finally, you don't echo values in a page callback, you return them. So you should be doing this:

function node_admin_content123() {
  $output .= t('New module contact page');
  $output .= t('contact description...');

  return $output;
}
kirankumar_k’s picture

Thank you for your reply Jaypan. And I am getting error like "Fatal error: Unsupported operand types in /opt/lampp/htdocs/drupal7/includes/form.inc on line 1079" when I tried to use the above code. Please help me.

Jaypan’s picture

You need to clear the Drupal cache after you change the code.

kirankumar_k’s picture

I have cleared the Drupal Chache still problem exists. This is my code.

function new_menu() {
$items['new'] = array(
    'title' => 'Contact',
    'page callback' => 'drupal_get_form',
    'page arguments' => array('new_form'),
    'access arguments' => array('new module'),
   // 'access callback' => TRUE
    );
$items['admin/content/contacts'] = array(
    'title' => 'Contacts',
    'description' => "Manage your site's book outlines.",
    'page callback' => 'drupal_get_form',
	'page arguments' => array('node_admin_content123'),
    'access arguments' => array('new module'),
    'type' => MENU_LOCAL_TASK,
  );
 
  return $items;
}
function node_admin_content123() {
  $output .= t('New module contact page');
  $output .= t('contact description...');

  return $output;
}
kirankumar_k’s picture

Jaypan, I think now you are able to read.. please check my code once..

Jaypan’s picture

You didn't change your hook_menu() definition as I showed.

kirankumar_k’s picture

Thanks Jaypan it works but I am getting a Notice like "Notice: Undefined variable: output in node_admin_content123() (line 34 of /opt/lampp/htdocs/drupal7/sites/all/modules/new/new.module)."

And also I have a doubt, can I write the code in the below function to get users list from database table?

function node_admin_content123() {
//my code to fetch users contact list with html tags to better look and feel
}
Jaypan’s picture

Show your actual function. Can't help with the reason you are getting the error if you don't show your code.

kirankumar_k’s picture

Thank you for your support Jaypan, actually the above issue resolved. And now I am able to display user contact information in the Cotact Tab in Content page. I have used the below code..

function new_menu() {
$items['new'] = array(
    'title' => 'Contact',
    'page callback' => 'drupal_get_form',
    'page arguments' => array('new_form'),
    'access arguments' => array('new module'),
   // 'access callback' => TRUE
    );
$items['admin/content/contacts'] = array(
  'title' => 'Contacts',
  'description' => "Manage your site's book outlines.",
  'page callback' => 'node_admin_content123',
  'access arguments' => array('new module'),
  'type' => MENU_LOCAL_TASK,
);
 
  return $items;
}
function node_admin_content123() {
 $result = db_select('cotact_form')
        ->fields('cotact_form', array('contact_name','contact_email','contact_phone','contact_comment'))        
        ->execute();

    $entries= $result;
    $output='';
    $rows = array();
    foreach ($entries as $entry) {
      // Sanitize the data before handing it off to the theme layer.
      $rows[] = array_map('check_plain', (array) $entry);
} 


   $header = array(t('Name'), t('Email'), t('Contact'), t('Comment'));
    $output .= theme('table', array('header' => $header, 'rows' => $rows));

    return $output;
}

But now my requirement is, I need to display an Edit or Delete after each user record for Admin. By this Admin can have a privilage to do edit or delete the user information.