Welcome, Guest
Username: Password: Remember me

TOPIC: [SOLVED] Changing menu on Control Panel

Changing menu on CPanel?? 03 Aug 2016 06:38 #14353

  • jonathanbell
  • jonathanbell's Avatar
  • Offline
  • Premium Member
  • Posts: 147
  • Thank you received: 5
  • Karma: 1
If I wanted to add more items and change the links on the CPanel in my components, where would I do this? Sorry had a good look but have drawn a blank..
The administrator has disabled public write access.

Changing menu on CPanel?? 03 Aug 2016 09:32 #14354

  • Romkabouter
  • Romkabouter's Avatar
  • Offline
  • Elite Member
  • Posts: 310
  • Thank you received: 131
  • Karma: 48
You should fork the admin/component/helper/helper.php.

There you will find "addSubmenu", where you can change the links array.
After that, you will have to change getMenuItems, where you can further specify the link
The administrator has disabled public write access.
The following user(s) said Thank You: admin

Changing menu on CPanel?? 03 Aug 2016 09:56 #14355

  • admin
  • admin's Avatar
  • Offline
  • Administrator
  • Chef
  • Posts: 3711
  • Thank you received: 987
  • Karma: 140
First step, you create all the available pages items.
Second step, you define which link is called for the menu. You can create different menus.

Well, this part is ugly. I was waiting something coming from Joomla, but I don't see any move at the moment.
When you talk about this, I feel in a shame when I see how is the code. Not so bad, but really redondant.
I would like to rewrite it all, using xml files for that.

Good luck.
Coding is now a piece of cake
The administrator has disabled public write access.

Changing menu on CPanel?? 03 Aug 2016 22:23 #14356

  • jonathanbell
  • jonathanbell's Avatar
  • Offline
  • Premium Member
  • Posts: 147
  • Thank you received: 5
  • Karma: 1
Thanks, I will go and have a look at the helper file and fork it. Will see how I go. Thanks both...
The administrator has disabled public write access.

Changing menu on CPanel?? 04 Aug 2016 12:56 #14360

  • admin
  • admin's Avatar
  • Offline
  • Administrator
  • Chef
  • Posts: 3711
  • Thank you received: 987
  • Karma: 140
I think the new way for building menus based on XML file will be available soon because it is easy to do and because I feel so bad every time I see the current code. I get a headache every time... lol.
Coding is now a piece of cake
The administrator has disabled public write access.

Changing menu on CPanel?? 09 Aug 2016 08:31 #14393

  • liubov
  • liubov's Avatar
  • Offline
  • Elite Member
  • (=) 10 mn and it's ready!
  • Posts: 279
  • Thank you received: 36
  • Karma: 22
Romkabouter wrote:
You should fork the admin/component/helper/helper.php.

There you will find "addSubmenu", where you can change the links array.
After that, you will have to change getMenuItems, where you can further specify the link

I tried to fork the helper to do that without success for the moment. I write here what i've done step by step:
- I want to delete 'Positions' Menus -
  1. Create admin/fork directory
  2. Copy the admin/_fork/helper.php in admin/fork/
  3. Adding administration <folder>fork</folder> in mycomponent.xml
  4. Delete the memu in mycomponent.xml i do not want to see in Components/mycomponent/submenus
  5. Copy original function 'addSubmenu' in admin/fork/helper.php
  6. Delete the menu i do not want to see in the Admin Cpanel
    $links = array(
    'admin.pedigrees.default',
    'admin.etalons.default',
    'admin.lices.default',
    'admin.portees.default',
    'admin.actualites.default',
    /* 'admin.positions.default', */
    'admin.races.default',
    'admin.robes.default',
    'admin.yeuxs.default',
    'admin.annees.default',
    'admin.rubriques.default'
    );
  7. Copy original function 'getMenuItems' in admin/fork/helper.php
  8. Delete the Menu Item i do not want to see in the Admin Cpanel
    /* $items = array(
    'label' => 'JBREEDING_LAYOUT_GESTION_DES_POSITIONS',
    'view' => 'positions',
    'layout' => 'default',
    'icon' => 'jbreeding_positions'
    ); */

Forked helper do not overwrite the original function because i still see the Item Menu that i've deleted.


( or may be we can overwrite but not cancel/delete objects as xml forms ) ?
Last Edit: 09 Aug 2016 08:58 by liubov.
The administrator has disabled public write access.

Changing menu on CPanel?? 09 Aug 2016 09:52 #14395

  • admin
  • admin's Avatar
  • Offline
  • Administrator
  • Chef
  • Posts: 3711
  • Thank you received: 987
  • Karma: 140
Here is the solution.
public static function addSubmenu($view, $layout, $alias = 'menu')
{
	$items = static::getMenuItems();

	$client = 'admin';
	if (JFactory::getApplication()->isSite())
		$client = 'site';

	$links = array();
	switch($client)
	{
		case 'admin':
			switch($alias)
			{
				case 'cpanel':
				case 'menu':
				default:
					$links = array(
					
					
// ->   Change order, add/remove items HERE

						'admin.continents.default',
						'admin.countries.default',
						'admin.travellers.default',
						'admin.visits.visitstravellers',
						'admin.visits.visitscities',
						'admin.visits.default',
						'admin.cities.default'
					);

					if ($alias != 'cpanel')
						array_unshift($links, 'admin.cpanel');

					break;
			}
			break;
...

The items are prepared in getMenuItems()
Coding is now a piece of cake
Last Edit: 09 Aug 2016 09:53 by admin.
The administrator has disabled public write access.

Changing menu on CPanel?? 09 Aug 2016 10:27 #14400

  • liubov
  • liubov's Avatar
  • Offline
  • Elite Member
  • (=) 10 mn and it's ready!
  • Posts: 279
  • Thank you received: 36
  • Karma: 22
It is exactely what i ve done :
public static function addSubmenu($view, $layout, $alias = 'menu')
	{
		$items = static::getMenuItems();

		// Will be handled in XML in future (or/and with the Joomla native menus)
		// -> give your opinion on j-cook.pro/forum


		$client = 'admin';
		if (JFactory::getApplication()->isSite())
			$client = 'site';

		$links = array();
		switch($client)
		{
			case 'admin':
				switch($alias)
				{
					case 'cpanel':
					case 'menu':
					default:
						$links = array(
							'admin.pedigrees.default',
							'admin.etalons.default',
							'admin.lices.default',
							'admin.portees.default',
							'admin.actualites.default',
            /*===>	'admin.statuts.default',   <===*/
							'admin.races.default',
							'admin.robes.default',
							'admin.yeuxs.default',
							'admin.annees.default',
							'admin.rubriques.default'
						);

and for the forked GetMenuItems :
public static function getMenuItems()
	{
		// Will be handled in XML in future (or/and with the Joomla native menus)
		// -> give your opinion on j-cook.pro/forum

		$items = array();

		$items['admin.pedigrees.default'] = array(
			'label' => 'JBREEDING_LAYOUT_GESTION_DES_CHIENS',
			'view' => 'pedigrees',
			'layout' => 'default',
			'icon' => 'jbreeding_pedigrees'
		);

		$items['admin.etalons.default'] = array(
			'label' => 'JBREEDING_LAYOUT_GESTION_DES_ETALONS',
			'view' => 'etalons',
			'layout' => 'default',
			'icon' => 'jbreeding_etalons'
		);

		$items['admin.lices.default'] = array(
			'label' => 'JBREEDING_LAYOUT_GESTION_DES_LICES',
			'view' => 'lices',
			'layout' => 'default',
			'icon' => 'jbreeding_lices'
		);

		$items['admin.portees.default'] = array(
			'label' => 'JBREEDING_LAYOUT_GESTION_DES_PORTEES',
			'view' => 'portees',
			'layout' => 'default',
			'icon' => 'jbreeding_portees'
		);

		$items['admin.actualites.default'] = array(
			'label' => 'JBREEDING_LAYOUT_GESTION_DES_ACTUALITES',
			'view' => 'actualites',
			'layout' => 'default',
			'icon' => 'jbreeding_actualites'
		);

    /*===> $items['admin.statuts.default'] = array(
			'label' => 'JBREEDING_LAYOUT_GESTION_DES_POSITIONS',
			'view' => 'statuts',
			'layout' => 'default',
			'icon' => 'jbreeding_statuts'
		); <===*/

		$items['admin.races.default'] = array(
			'label' => 'JBREEDING_LAYOUT_GESTION_DES_RACES',
			'view' => 'races',
			'layout' => 'default',
			'icon' => 'jbreeding_races'
		);

..... .... .... ....
The administrator has disabled public write access.

Changing menu on CPanel?? 09 Aug 2016 10:36 #14402

  • admin
  • admin's Avatar
  • Offline
  • Administrator
  • Chef
  • Posts: 3711
  • Thank you received: 987
  • Karma: 140
If you only need to remove the item, you don't need to fork getMenuItems().

I downloaded your component and made the operation. It works like a charm.
You might have missed something.

What happen if you comment the line in the original helper ?
It is working, check very well if you are not doing another mistake.
Coding is now a piece of cake
The administrator has disabled public write access.

Changing menu on CPanel?? 09 Aug 2016 11:26 #14404

  • liubov
  • liubov's Avatar
  • Offline
  • Elite Member
  • (=) 10 mn and it's ready!
  • Posts: 279
  • Thank you received: 36
  • Karma: 22
Arg ! ok, I will check with better eyes :)

I guess my forked helper is not loaded ...

j-cook source with modified fork helper here : com_jbreeding_beta_3.0.1.zip

just to validate the structure if you have some time ;p
Last Edit: 09 Aug 2016 13:59 by liubov.
The administrator has disabled public write access.

Changing menu on CPanel?? 09 Aug 2016 13:22 #14406

  • admin
  • admin's Avatar
  • Offline
  • Administrator
  • Chef
  • Posts: 3711
  • Thank you received: 987
  • Karma: 140
put your file in 'fork/helpers/helper.php'
Coding is now a piece of cake
The administrator has disabled public write access.
The following user(s) said Thank You: liubov

Changing menu on CPanel?? 09 Aug 2016 13:58 #14408

  • liubov
  • liubov's Avatar
  • Offline
  • Elite Member
  • (=) 10 mn and it's ready!
  • Posts: 279
  • Thank you received: 36
  • Karma: 22
I tell you that I had to change my eyes !

Thanks a lot for this missing directory.
works fine now.
The administrator has disabled public write access.
Time to create page: 0.139 seconds

Get Started