Hidding empty titles

Hey there!
This time it’s not really about asking questions, this is more like a contribution. In the MegaMenu I’ve saw that when you create a new item (used for CMS block I mean) if you inspect the code, there was an empty title block even if you set the « Show title » to « No » :

<div class="group-title">
<a href="#" class="mega first group dynamic-width" id="menu135" title="">
<span class="menu-title"></span>
</a>
</div>

Like I am not a empty lines lover, I fixed this by modifying the « app/code/Ubertheme/UbMegaMenu/Helper/Mega.php » helper with the following lines :
# Lines 634 to 644 -- Wrapped with a if taf here’s the result :

if(!empty($menuText)){
//add font awesome
if ($item->getFontAwesome()) {
$menuText = '<i class="fa ' . $item->getFontAwesome() . '"></i>' . $menuText;
}
$menuText = '<span class="menu-title">' . $menuText.$productCountingText . '</span>';

//add menu icon image
if ($item->getIconImage()) {
$icon = '<span class="menu-icon"><img alt="' . strip_tags($menuTitle) . '" src="' . $this->imageModel->getBaseUrl() . $item->getIconImage() . '" /></span> ';
$menuText = $icon . $menuText;
}
}

# Line 668 -- Added a !empty($var) here’s the result :

if (!empty($menuText)) {
if ($link) {
switch ($item->getLinkTarget()) {
default:
case '_top':
$data .= '<a href="' . $link . '" ' . $class . ' ' . $id . ' ' . $titleAttr . '>' . $menuText . '</a>';
break;
case '_blank':
$data .= '<a href="' . $link . '" target="_blank" ' . $class . ' ' . $id . ' ' . $titleAttr . '>' . $menuText . '</a>';
break;
case '_parent':
$data .= '<a href="' . $link . '" target="_parent" ' . $class . ' ' . $id . ' ' . $titleAttr . '>' . $menuText . '</a>';
break;
}
} else {
$data .= '<a ' . $class . ' ' . $id . ' ' . $titleAttr . '>' . $menuText . '</a>';
}

//add description to menu item
if (isset($megaParam->desc) AND $megaParam->desc) {
$desc = \Magento\Framework\App\ObjectManager::getInstance()->create('Ubertheme\UbMegaMenu\Model\Processor')->filter($megaParam->desc);
$data .= '<div class="menu-desc">' . $desc . '</div>';
}

//append menu parent icon
$hasChildClass = substr_count($class, 'has-child');
if ($hasChildClass) {
$data .= '<span class="menu-parent-icon'. (($isActivated) ? ' active' : '') . '"></span>';
if($link AND strlen(trim($link)) AND $link != '#') {
$data .= '<span class="menu-group-link'.(($isActivated) ? ' active' : '').'" title="'.__('Shop all').'">' . __('Shop all') . '</span>';
}
}
}

Final result : By adding those lines above I got no empty title blocks anymore! Maybe this could be added to the next extension update ?
Other Idea : I saw that when you add new item as custom block (like CMS block I mean), there’s always the link fields, this would be great to add some select field to check if you want a custom link or not (like you made it for the title block).
That’s it guys! Have a nice day. Thanks for all your gorgeous extensions!
Regards,
Laurent

2 answers

Profile photo of ubdev Staff 36100.00 $tone January 25, 2019
Public

Hi Laurent, 
Great thanks for your detailed suggestion. 
Please give us a bit more time to follow up with you since our technical team is off during the weekend. We will get back to you as soon as possible. 
Sincerely,
Ubertheme team

#1
Profile photo of ubdev Staff 36100.00 $tone January 28, 2019
Public

Hi Laurent, 
Great thanks for your contribution. Our team will update and enhance our mega menu further following both points you suggested: 

In the MegaMenu I’ve saw that when you create a new item (used for CMS block I mean) if you inspect the code, there was an empty title block even if you set the « Show title » to « No » :

Yes, we will optimize the code to remove the empty title blocks when the Show Title is set to No.

Other Idea : I saw that when you add new item as custom block (like CMS block I mean), there’s always the link fields, this would be great to add some select field to check if you want a custom link or not (like you made it for the title block).

Yes, we will enhance this feature in the upcoming release as well. We will try our best to make this update available as soon as possible. 
Regards,
Ubertheme team
 

#2

Please login or Register to Submit Answer

Written By

Comments