0

I am adding a custom module, and wants when someone install the module, menu will be added to add data in the admin/settings page... But i am getting nothing:

Below is the code i wrote.. pricepackages is the module name i want to created

please help me ..

function pricepackages_menu()
{
    $items = array();
    $items[] = array(
        'path' => 'admin/settings/favorites/quotes',
        'title' => t('Manage Quotes'),
        //'page callback' => 'drupal_get_form',
        //'page arguments' => array('poke_test_form'),
        'callback' => 'drupal_get_form',
        'callback arguments' => 'pricepackages_settings',
        //'access callback' => 'poke_access_callback',
        'access' => user_access('Access administration pages'),
    );
}

Settings hook is like this:

function pricepackages_settings()
{
    //$form['#submit'][] = 'poke_test_submit';
    $form['quote_manage'] = array(
        '#title' => t('Select User'),
        '#type' => 'textfield',
    );
    return $form;
}

2 Answers 2

0
function pricepackages_menu()
{
    $items = array();
    $items['admin/settings/favorites-quotes'] = array(
        'title' => t('Manage Quotes'),
        'page callback' => 'drupal_get_form',
        'page arguments' => array('pricepackages_settings'),
        //'access callback' => TRUE,
        'access arguments' => array('access administration pages'),
    );
}
2
  • Dude, it's showing on left navigation, not under the admin/settings list... can you please help.. This link can also be accessable from other users i guess?? Commented Oct 20, 2014 at 13:05
  • i have updated my answer check once and let me know.
    – DRUPWAY
    Commented Oct 20, 2014 at 13:22
0

I have created a module : 'Custom_menu' with following file structure

modules/custom/custom_menu/

  • custom_menu.info.yml
  • custom_menu.module

            <?php
            /*
             * hook_toolbar()
             */
            function custom_menu_toolbar() {
                /**
                 * Custom menu for Catalog
                 * Array for $module should be array('Name' => 'machine_name')
                 */
                $baseUrl =  \Drupal::request()->getHost().base_path();
    
                $modules = array(
                    'Categories' => 'categories',
                    'Products' => 'products'        
                );
    
                $links = array();
                $a=0;
                foreach ($modules as $module => $route) {
                    $links[$module] = array(
                        'title' => $module,
                        'type'=>'link',
                        'url' => Url::fromUri($baseUrl.'/admin/content-list/content_type/'.$route),
                        'attributes' => array(
                            'title' => $module,
                        ),
                    );
                    $a++;
                }
    
                //content-list/{content_type}
                $shortcut_links = [
                    '#theme'=>'links__toolbar_shortcuts',
                    '#links'=>$links,
                ];
    
                // Create the examples toolbar render array.
                $items['admin_menu_catalog'] = array(
                    '#type' => 'toolbar_item',
                    'tab' => array(
                        '#type' => 'link',
                        '#title' => t('Catalog'),
                        '#url' => Url::fromRoute('<front>'),
                        '#attributes' => array(
                            'title' => t('Catalog'),
                            'class' => array('toolbar-icon', 'toolbar-icon-examples'),
                        ),
                    ),
    
                    'tray' => array(
                        '#heading' => t('Catalog'),
                        'shortcuts' => $shortcut_links,
                    ),
    
                    '#weight' => 200,
                    '#attached' => array(
                        'library' => array(
                            'shortcut/drupal.shortcut',
                        ),
                    ),
                );
            }
    

Now you will see Catalog menu in you admin menu bar with child menus : Categories and Products.

Authentic user can see related content only. Also can add content without following the default procedure of the Drupal.

Your Answer

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

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