Page Menu
Home
In-Portal Phabricator
Search
Configure Global Search
Log In
Files
F804027
D196.id482.diff
No One
Temporary
Actions
View File
Edit File
Delete File
View Transforms
Subscribe
Mute Notifications
Award Token
Flag For Later
Subscribers
None
File Metadata
Details
File Info
Storage
Attached
Created
Wed, Feb 26, 9:04 AM
Size
5 KB
Mime Type
text/x-diff
Expires
Thu, Feb 27, 9:04 AM (1 h, 24 m)
Engine
blob
Format
Raw Data
Handle
576742
Attached To
D196: INP-1157 - Support for user-defined fields in "st_CachedMenu" tag
D196.id482.diff
View Options
Index: core/units/helpers/menu_helper.php
===================================================================
--- core/units/helpers/menu_helper.php
+++ core/units/helpers/menu_helper.php
@@ -33,6 +33,41 @@
protected $parentPaths = Array ();
/**
+ * Extra parameters, that should be available in each menu item (key - param name, value - category field).
+ *
+ * @var array
+ */
+ protected $itemParams = array(
+ // 'filename' => array('Filename'),
+ // 'created_on' => array('CreatedOn', '-- d/m/Y --'),
+ );
+
+ /**
+ * Category dummy for formatting purposes.
+ *
+ * @var CategoriesItem
+ */
+ protected $categoryDummy;
+
+ /**
+ * Set's references to kApplication and DBConnection interface class instances
+ *
+ * @access public
+ */
+ public function __construct()
+ {
+ parent::__construct();
+
+ if ( $this->menuItemsRequireFormatting() ) {
+ $this->categoryDummy = $this->Application->recallObject(
+ 'c.menu-item',
+ null,
+ array('skip_autoload' => true)
+ );
+ }
+ }
+
+ /**
* Builds site menu
*
* @param string $prefix_special
@@ -244,6 +279,24 @@
'menu_icon' => $page['UseMenuIconUrl'] ? $page['MenuIconUrl'] : false,
);
+ if ( isset($this->categoryDummy) ) {
+ $this->categoryDummy->SetDBFieldsFromHash($page);
+ }
+
+ foreach ( $this->itemParams as $param_name => $category_field_data ) {
+ $category_field_name = $category_field_data[0];
+
+ if ( array_key_exists(1, $category_field_data) ) {
+ $block_params[$param_name] = $this->categoryDummy->GetField(
+ $category_field_name,
+ $category_field_data[1]
+ );
+ }
+ else {
+ $block_params[$param_name] = $page[$category_field_name];
+ }
+ }
+
return $block_params;
}
@@ -358,6 +411,11 @@
if ( !isset($items_by_parent) ) {
$items_by_parent = Array ();
+ $extra_select_clause = '';
+
+ foreach ( $this->itemParams as $category_field_data ) {
+ $extra_select_clause .= ', c.' . $category_field_data[0];
+ }
// Sub-categories from current category
$sql = 'SELECT
@@ -371,7 +429,7 @@
c.ParentId As ParentId,
\'cat\' AS ItemType,
c.IsMenu, c.Type, c.ThemeId, c.UseExternalUrl, c.ExternalUrl, c.UseMenuIconUrl, c.MenuIconUrl,
- c.Status
+ c.Status' . $extra_select_clause . '
FROM ' . TABLE_PREFIX . 'Categories AS c';
if ( isset($category_limit) && $category_limit ) {
@@ -409,4 +467,21 @@
return ($a['ItemPriority'] < $b['ItemPriority']) ? 1 : -1; // descending
}
+
+ /**
+ * Determines if menu item parameters require formatting.
+ *
+ * @return boolean
+ */
+ protected function menuItemsRequireFormatting()
+ {
+ foreach ( $this->itemParams as $category_field_data ) {
+ if ( array_key_exists(1, $category_field_data) ) {
+ return true;
+ }
+ }
+
+ return false;
+ }
+
}
Index: themes/advanced/platform/elements/menu.elm.tpl
===================================================================
--- themes/advanced/platform/elements/menu.elm.tpl
+++ themes/advanced/platform/elements/menu.elm.tpl
@@ -1,3 +1,5 @@
+<inp2:m_Include template="platform/elements/menu_sections.xml" />
+
<table class="menu-background fullwidth">
<tr>
<td align="left">
@@ -21,7 +23,6 @@
<menubar id="menubar" orient="H" showicon="true" showsubicon="false" stlprf="horz_" droponclick="true" >
<items>
<item id="sub-elem0" url="<inp2:m_Link template="index" m_cat_id="0" m_cat_page="1"/>" ico="['<inp2:m_TemplatesBase module="In-portal"/>img/menu_home.gif']" enb="true" title=""><![CDATA[<inp2:m_Phrase name="lu_rootcategory_name"/>]]></item>
- <inp2:m_Include template="platform/elements/menu_sections.xml" />
</items>
</menubar>
</menumgr>
@@ -104,4 +105,4 @@
</table>
</td>
</tr>
-</table>
\ No newline at end of file
+</table>
Index: themes/advanced/platform/elements/menu_sections.xml.tpl
===================================================================
--- themes/advanced/platform/elements/menu_sections.xml.tpl
+++ themes/advanced/platform/elements/menu_sections.xml.tpl
@@ -1,19 +1,10 @@
<inp2:m_Random result_to_var="rand"/>
<inp2:m_DefineElement name="top_menu_item" no_editing="1">
- <item id="menu<inp2:m_Param name="page_id"/>"
- url="<inp2:m_Link template="$template" m_cat_id="$cat_id" use_section="$use_section" m_cat_page="1"/>"
- <inp2:m_if check="m_Param" name="menu_icon">
- ico="['<inp2:m_TemplatesBase/><inp2:m_Param name="menu_icon"/>']"
- <inp2:m_else/>
- ico="['<inp2:m_TemplatesBase module="In-Portal"/>img/menu_inedit.gif']"
- </inp2:m_if>
- enb="true" title=""
- subid="subpages<inp2:m_Param name="page_id"/>"
- suburl="<inp2:m_link __NO_REWRITE__="1" template="platform/elements/menu_subsections.xml"
- m_cat_id="$cat_id"
- m_cat_page="1"
- page_id="$page_id"
- level="0" max_level="4"
- />" ><![CDATA[<inp2:m_Param name="title"/>]]></item>
+ <li>
+ <inp2:m_PrintCurrentParams/>
+ </li>
</inp2:m_DefineElement>
-<inp2:st_CachedMenu level="0" category_id="0" render_as="top_menu_item"/>
\ No newline at end of file
+
+<ul>
+ <inp2:st_CachedMenu level="0" category_id="0" render_as="top_menu_item"/>
+</ul>
Event Timeline
Log In to Comment