Sub Menu functionality on NordCMS

After having played around with NORDCMS. I was looking to get submenus under menus. I added a new field to the menuitem table 

Alter table cms_table_item add submenu varchar(255) after url

I did the required changes to the model CmsMenuItem.php. Following functions were changed

 public function rules() { 
return array(
array('menuId, locale, label, url, weight', 'required'),
array('menuId, weight, visible', 'numerical', 'integerOnly'=>true),
array('menuId', 'length', 'max'=>10),
array('locale', 'length', 'max'=>50),
array('label, url, submenu', 'length', 'max'=>255),
array('id, menuId, label, url, visible', 'safe', 'on'=>'search'),
);
}

public function attributeLabels() {
return array(
'id' => '#',
'menuId' => Yii::t('CmsModule.core', 'Menu'),
'label' => Yii::t('CmsModule.core', 'Label'),
'url' => Yii::t('CmsModule.core', 'URL'),
'submenu' => Yii::t('CmsModule.core', 'Sub-menu'),
'weight' => Yii::t('CmsModule.core', 'Weight'),
'visible' => Yii::t('CmsModule.core', 'Visible'), );
}

public function createConfig() {
$config = array();

if ($this->visible) {
$visible = true;
if (strpos($this->url, 'http') !== false)
$url = $this->url;
else if (strpos($this->url, '/') !== false)
$url = array($this->url);
else {
/** @var Cms $cms */
$cms = Yii::app()->cms;
$name = $this->url;
$page = $cms->loadPage($name);

// Ensure that we don't like to unpublished pages.
if (!$page->published)
$visible = false;

$url = $cms->createUrl($name);
$active = $cms->isActive($name);
}

if (isset($url)) {
$config['label'] = $this->label;
$config['url'] = $url;
$config['visible'] = $visible;

if (isset($active))
$config['active'] = $active;
}

if($this->submenu != "") {
$config['items'] = array();
$model = CmsMenu::model()->find('name = :name', array(':name' => $this->submenu));
$config['items'] = CMap::mergeArray($model->createItems(), $config['items']);
}
}

return $config;
}

That largely did it.

Now that for each menu item, we have a submenu. Any menu system name can be used to appear as submenu for a menu item. I now needed the admin form for menu item to show submenu field as well

cms/views/menuItem/_form.php

 echo $form->textFieldRow($model,'submenu');

Now, whenever the menu widget is called, submenu will also get rendered. Hope this help people using Nordcms on yii framework.

0 0 votes
Article Rating
Subscribe
Notify of
guest
0 Comments
Oldest
Newest Most Voted
Inline Feedbacks
View all comments
0
Would love your thoughts, please comment.x
()
x