0
votes

I want to create page in admin side using module. I need to mention the custom link page using hook_menu(). After accessing the link from browser, I want to display some links for calling another static links from another website.

For Example :

I want to create admin/list-of-links : custom url

After clicking on this, on this page, the result would be like table listing with button for navigation of that static links from another website.

I have created followings.

By using following code, I have created custom page with assignment of the custom template file, by passed static links and printed that in the custom template page. Please note, I have just printed array in the template page. The formatting is remaining.

<?php 
    // Created Custom URL for accesing the static links
    function test_menu() {
        $items['admin/list-of-links'] = array(
            'title' => 'List Section',
            'page callback' => 'list_section',
            'access arguments' => array('administrator'),
        );
    }

    // Created Page Callback for assigning the variable for the theme
    function list_section() {
        $static_links = array("www.google.com", "www.facebook.com");
        return theme('test_link', array('static_links' => $static_links));
    }

    // Assigned the template for the page that we have created 
    function test_theme($existing, $type, $theme, $path) {

        return array(
            'test_link' => array(
                'template' => 'static-link-listing',
                'path' => drupal_get_path('theme', 'seven') . "/templates"
            ),
        );
    }

    //Created Template File :  themes/seven/templates/static-link-listing.tpl.php
    // And after that, I am getting the result.
    // Now after that, we will format what output we need.

    echo "<pre>";
    print_r($static_links);

    ?>
1

1 Answers

0
votes

You will be needing to use the hook_menu() to do this.

Let's say your module nis named example, then you'll need to add the following code in the .module file:

/**
 * Implements hook_menu().
 */
function example_menu() {
  $items['admin/list-of-links'] = array(
    'description' => 'Load a list lof links',
    'title' => t('List of links'),
    'page callback' => '_example_load_links',
    'access arguments' => array('access content'),
    'type' => MENU_NORMAL_ITEM,
  );

  return $items;
}

To then return a list of links on the selected page, you'll need to add a function for the page callback, so for example:

/**
 * We load a list of links
 */
function _example_load_links(){
  $content['item'] = array(
    '#type' => 'item',
    '#markup' => t('Hello world, place your links here'),
  );
  return $content;
}

This should work if you enable your module and clear your cache (very important with hook_menu)