[GH-ISSUE #271] Menu Items #232

Closed
opened 2026-02-25 21:34:30 +03:00 by kerem · 5 comments
Owner

Originally created by @bet0x on GitHub (May 16, 2018).
Original GitHub issue: https://github.com/cypht-org/cypht/issues/271

Originally assigned to: @jasonmunro on GitHub.

How i do modify or add menu items?

Originally created by @bet0x on GitHub (May 16, 2018). Original GitHub issue: https://github.com/cypht-org/cypht/issues/271 Originally assigned to: @jasonmunro on GitHub. How i do modify or add menu items?
kerem 2026-02-25 21:34:30 +03:00
  • closed this issue
  • added the
    question
    label
Author
Owner

@jasonmunro commented on GitHub (May 18, 2018):

This is where the site module set comes in. You can use it to override other modules, or add your own, including menu items. I don't have time to elaborate just now, but will follow up when I can (and on your other issues). Sorry about that!

<!-- gh-comment-id:390246043 --> @jasonmunro commented on GitHub (May 18, 2018): This is where the site module set comes in. You can use it to override other modules, or add your own, including menu items. I don't have time to elaborate just now, but will follow up when I can (and on your other issues). Sorry about that!
Author
Owner

@jasonmunro commented on GitHub (Jun 27, 2018):

To add a link to the main menu of Cypht, you will need to modify the site module set in 2 places. First you will assign your module (your custom code) to a page request identifier in the modules/site/setup.php file like so:

/* explination of the values:
 * 'ajax_hm_folders   the page request id to execute our module code on
 * 'my_custom_link'   the name of the module to execute, see modules.php
 * true               boolean to control is this should fire when logged in only
 * 'site'             module set the module belongs to
 * 'main_menu_end'    a module associated with this page request to peg ours to
 * 'before'           fire our module before the main_menu_end (supports both before or after)
 */
add_output('ajax_hm_folders', 'my_custom_link', true, 'site', 'main_menu_end', 'before');

then you need to create the module in modules/site/modules.php. It will be named with both the module type, and the value from above (my_custom_link), like so:

/**
 * @subpackage site/output
 */
class Hm_Output_my_custom_link extends Hm_Output_Module {
    protected function output() {

        $link = '<li><a>FOO</a></li>';
        $this->concat('formatted_folder_list', $link);
    }
}

That's it :) modify the $link variable to control what you want to insert into the menu. Make sure the site module set is enabled in your config, if it isn't add it and rerun the config gen script.

<!-- gh-comment-id:400780372 --> @jasonmunro commented on GitHub (Jun 27, 2018): To add a link to the main menu of Cypht, you will need to modify the site module set in 2 places. First you will assign your module (your custom code) to a page request identifier in the modules/site/setup.php file like so: ``` /* explination of the values: * 'ajax_hm_folders the page request id to execute our module code on * 'my_custom_link' the name of the module to execute, see modules.php * true boolean to control is this should fire when logged in only * 'site' module set the module belongs to * 'main_menu_end' a module associated with this page request to peg ours to * 'before' fire our module before the main_menu_end (supports both before or after) */ add_output('ajax_hm_folders', 'my_custom_link', true, 'site', 'main_menu_end', 'before'); ``` then you need to create the module in modules/site/modules.php. It will be named with both the module type, and the value from above (my_custom_link), like so: ``` /** * @subpackage site/output */ class Hm_Output_my_custom_link extends Hm_Output_Module { protected function output() { $link = '<li><a>FOO</a></li>'; $this->concat('formatted_folder_list', $link); } } ``` That's it :) modify the $link variable to control what you want to insert into the menu. Make sure the site module set is enabled in your config, if it isn't add it and rerun the config gen script.
Author
Owner

@bet0x commented on GitHub (Jun 27, 2018):

Great, i started to implement my custom menu, required a bit more of code to make a new section but it works.

class Hm_Output_my_custom_link extends Hm_Output_Module {
    protected function output() {
        $res .= '<div class="src_name main_menu_hotel" data-source="">TITLE</div>';
        $res .= '<ul class="folders">';
        $res .= '<li class="menu_home"><a class="unread_link" href="LINK">';
        $res .= '<img class="account_icon" src="'.$this->html_safe(Hm_Image_Sources::$home).'" alt="" width="16" height="16" /> ';
        $res .= 'LINK NAME</a></li>';
        $res .= '</ul>';
        $this->concat('formatted_folder_list', $res);
    }
}

I added a new block element for this, using main_menu_start for the output.

Also after a change, you need to RE login to take effect on the changes made, maybe because i didn't use debug mode right?

<!-- gh-comment-id:400817592 --> @bet0x commented on GitHub (Jun 27, 2018): Great, i started to implement my custom menu, required a bit more of code to make a new section but it works. ``` class Hm_Output_my_custom_link extends Hm_Output_Module { protected function output() { $res .= '<div class="src_name main_menu_hotel" data-source="">TITLE</div>'; $res .= '<ul class="folders">'; $res .= '<li class="menu_home"><a class="unread_link" href="LINK">'; $res .= '<img class="account_icon" src="'.$this->html_safe(Hm_Image_Sources::$home).'" alt="" width="16" height="16" /> '; $res .= 'LINK NAME</a></li>'; $res .= '</ul>'; $this->concat('formatted_folder_list', $res); } } ``` I added a new block element for this, using `main_menu_start ` for the output. Also after a change, you need to RE login to take effect on the changes made, maybe because i didn't use debug mode right?
Author
Owner

@jasonmunro commented on GitHub (Jun 27, 2018):

Nice! actually the folder list is cached, so refreshing the page does not actually refresh it. You need to use the "reload" link at the bottom to cause it to be recreated. You will want to use debug mode for module development - specifically when adding/remove/re-assigning modules because in production mode that is cached when the config gen is run. As you noticed output modules have a built in html_save() method for potentially dangerous output, there is also a trans() method if you care about supporting i18n.

<!-- gh-comment-id:400819531 --> @jasonmunro commented on GitHub (Jun 27, 2018): Nice! actually the folder list is cached, so refreshing the page does not actually refresh it. You need to use the "reload" link at the bottom to cause it to be recreated. You will want to use debug mode for module development - specifically when adding/remove/re-assigning modules because in production mode that is cached when the config gen is run. As you noticed output modules have a built in html_save() method for potentially dangerous output, there is also a trans() method if you care about supporting i18n.
Author
Owner

@bet0x commented on GitHub (Jun 27, 2018):

@jasonmunro Yes, i just started and i already saw the trans module, i will be working on some tutorials for people. Everything is so clean!

<!-- gh-comment-id:400826548 --> @bet0x commented on GitHub (Jun 27, 2018): @jasonmunro Yes, i just started and i already saw the trans module, i will be working on some tutorials for people. Everything is so clean!
Sign in to join this conversation.
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference
starred/cypht#232
No description provided.