Hi Guys this may be my own misunderstanding and Totally happy to accept that this might be user error rather than a bug.
I have been looking at the guidance here https://docs.joomla.org/Menu_and_Menuitems_API_Guide for menu items.
I'm try to check if any menu items have been created for a specified view. e.g. if "option" =>"com_mycom", "view"=>"myview"
in this instance I want to pull out a list of menu items that are linked to articles i.e. "option" => "com_content", "view" => "article"
$app = Factory::getApplication();
$sitemenu = $app->getMenu();
$menuitems = $sitemenu->getItems(array("component"), array("com_content"));
var_dump($menuitems);
$articlemenuitems = $sitemenu->getItems(array("query"), array(array("option" => "com_content", "view" => "article")));
var_dump($articlemenuitems);
$menuitems -> brings back array of 2 items one is Featured and one is single article (id 101 & 328)
$articlemenuitems -> return single article (id 328)
$menuitems -> Brings back 2 items as expected -> example Output in block at bottom
$articlemenuitems -> array(0) { }
Localhost / Joomla 3.9.14 / php 7.1.32
it is entirely possible that i have mis-interpreted how the getItems should work. Please feel free to confirm .
I can of course put the $menuitems through a foreach loop to check the values in the query property.
Example output of above $menuitems = $sitemenu->getItems(array("component"), array("com_content"));
array(2) { [0]=> object(Joomla\CMS\Menu\MenuItem)#2291 (21) { ["id"]=> string(3) "101" ["menutype"]=> string(8) "mainmenu" ["title"]=> string(4) "Home" ["alias"]=> string(4) "home" ["note"]=> string(0) "" ["route"]=> string(4) "home" ["link"]=> string(42) "index.php?option=com_content&view=featured" ["type"]=> string(9) "component" ["level"]=> string(1) "1" ["language"]=> string(1) "*" ["browserNav"]=> string(1) "0" ["access"]=> string(1) "1" ["params":protected]=> string(969) "{"featured_categories":[""],"layout_type":"blog","num_leading_articles":"1","num_intro_articles":"3","num_columns":"3","num_links":"0","multi_column_order":"1","orderby_pri":"","orderby_sec":"front","order_date":"","show_pagination":"2","show_pagination_results":"1","show_title":"","link_titles":"","show_intro":"","info_block_position":"","show_category":"","link_category":"","show_parent_category":"","link_parent_category":"","show_author":"","link_author":"","show_create_date":"","show_modify_date":"","show_publish_date":"","show_item_navigation":"","show_vote":"","show_readmore":"","show_readmore_title":"","show_icons":"","show_print_icon":"","show_email_icon":"","show_hits":"","show_noauth":"","show_feed_link":"1","feed_summary":"","menu-anchor_title":"","menu-anchor_css":"","menu_image":"","menu_text":1,"page_title":"","show_page_heading":1,"page_heading":"","pageclass_sfx":"","menu-meta_description":"","menu-meta_keywords":"","robots":"","secure":0}" ["home"]=> string(1) "1" ["img"]=> string(0) "" ["template_style_id"]=> string(1) "0" ["component_id"]=> string(2) "22" ["parent_id"]=> string(1) "1" ["component"]=> string(11) "com_content" ["tree"]=> array(1) { [0]=> string(3) "101" } ["query"]=> array(2) { ["option"]=> string(11) "com_content" ["view"]=> string(8) "featured" } } [1]=> object(Joomla\CMS\Menu\MenuItem)#2280 (21) { ["id"]=> string(3) "328" ["menutype"]=> string(8) "mainmenu" ["title"]=> string(17) "test article page" ["alias"]=> string(17) "test-article-page" ["note"]=> string(0) "" ["route"]=> string(17) "test-article-page" ["link"]=> string(46) "index.php?option=com_content&view=article&id=1" ["type"]=> string(9) "component" ["level"]=> string(1) "1" ["language"]=> string(1) "*" ["browserNav"]=> string(1) "0" ["access"]=> string(1) "1" ["params":protected]=> string(1224) "{"show_title":"","link_titles":"","show_intro":"","info_block_position":"","info_block_show_title":"","show_category":"","link_category":"","show_parent_category":"","link_parent_category":"","show_associations":"","show_author":"","link_author":"","show_create_date":"","show_modify_date":"","show_publish_date":"","show_item_navigation":"","show_vote":"","show_icons":"","show_print_icon":"","show_email_icon":"","show_hits":"","show_tags":"","show_noauth":"","urls_position":"","menu-anchor_title":"","menu-anchor_css":"","menu_image":"","menu_image_css":"","menu_text":1,"menu_show":1,"page_title":"","show_page_heading":"","page_heading":"","pageclass_sfx":"","menu-meta_description":"","menu-meta_keywords":"","robots":"","secure":0,"helixultimatemenulayout":"{\"width\":600,\"menualign\":\"right\",\"megamenu\":0,\"showtitle\":1,\"faicon\":\"\",\"customclass\":\"\",\"dropdown\":\"right\",\"badge\":\"\",\"badge_position\":\"\",\"badge_bg_color\":\"\",\"badge_text_color\":\"\",\"layout\":[]}","helixultimate_enable_page_title":"0","helixultimate_page_title_alt":"","helixultimate_page_subtitle":"","helixultimate_page_title_heading":"h2","helixultimate_page_title_bg_color":"","helixultimate_page_title_bg_image":""}" ["home"]=> string(1) "0" ["img"]=> string(1) " " ["template_style_id"]=> string(1) "0" ["component_id"]=> string(2) "22" ["parent_id"]=> string(1) "1" ["component"]=> string(11) "com_content" ["tree"]=> array(1) { [0]=> string(3) "328" } ["query"]=> array(3) { ["option"]=> string(11) "com_content" ["view"]=> string(7) "article" ["id"]=> string(1) "1" } } }
Labels |
Added:
?
|
Ah ok thanks for the info @SharkyKZ , I could have spent ages trying to get it to work !
Probably needs an update in the Documentation
a quick implementation if anyone wanted to filter by query might be something like
//get menu items filter by type if appropriate
$menuitems = $sitemenu->getItems(array("component"), array("com_content"));
// array of query options to look for
$checkarray =array("option" => "com_content", "view" => "article");
$queryfiltered = array();
foreach($menuitems as $item):
$result=array_diff($checkarray,$item->query);
if(count($result)==0){$queryfiltered[]=$item;}
endforeach ;
// returns just the menuitems with the query parameters you are looking for
var_dump($queryfiltered);
Closing as not a bug.
Status | New | ⇒ | Closed |
Closed_Date | 0000-00-00 00:00:00 | ⇒ | 2020-02-08 11:24:27 |
Closed_By | ⇒ | infograf768 |
Filtering by query parameters is not supported. But would be a nice feature to have.