Page MenuHomeIn-Portal Phabricator

D196.id586.diff
No OneTemporary

File Metadata

Created
Wed, Feb 26, 9:04 AM

D196.id586.diff

Index: branches/5.3.x/core/units/helpers/menu_helper.php
===================================================================
--- branches/5.3.x/core/units/helpers/menu_helper.php
+++ branches/5.3.x/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;
+ }
+
}

Event Timeline