I am rendering zend file element using following decorator..
$decoratorFile = array
(
'File',
'Errors',
array(array('data' => 'HtmlTag'), array('tag' => 'td', 'class'=>'elements')),
array('Label', array('tag' => 'td')),
array(array('row' => 'HtmlTag'), array('tag' => 'tr'))
);
But i want to create a custom decorator like the following one...
class My_Decorator_Td extends Zend_Form_Decorator_Abstract
{
public function buildLabel()
{
$element = $this->getElement();
$label = $element->getLabel();
if ($translator = $element->getTranslator()) {
$label = $translator->translate($label);
}
if ($element->isRequired()) {
$label .= '*';
}
$label .= '';
return $element->getView()
->formLabel($element->getName(), $label);
}
public function buildInput()
{
$element = $this->getElement();
$helper = $element->helper;
return $element->getView()->$helper(
$element->getName(),
$element->getValue(),
$element->getAttribs(),
$element->options
);
}
public function buildErrors()
{
$element = $this->getElement();
$messages = $element->getMessages();
if (empty($messages)) {
return '';
}
list($key, $error) = each($messages);
return '<div class="errors">' .
$error . '</div>';
}
public function buildDescription()
{
$element = $this->getElement();
$desc = $element->getDescription();
if (empty($desc)) {
return '';
}
return '<div class="description">' . $desc . '</div>';
}
public function render($content)
{
$element = $this->getElement();
if (!$element instanceof Zend_Form_Element) {
return $content;
}
if (null === $element->getView()) {
return $content;
}
$separator = $this->getSeparator();
$placement = $this->getPlacement();
$label = $this->buildLabel();
$input = $this->buildInput();
$errors = $this->buildErrors();
$desc = $this->buildDescription();
$output = '<tr>'
. '<td class="labels">'
. $label
. '</td>'
. '<td class="elements">'
. $input
. $desc
. $errors
. '</td>'
. '</tr>';
switch ($placement) {
case (self::PREPEND):
return $output . $separator . $content;
case (self::APPEND):
default:
return $content . $separator . $output;
}
}
}
I am using this one for text elements.
How to create a custom decorator decorator for file element. Any Help?
You can find the answer to your question here
I had the same problem and came up with the solution to create a custom decorator that extends the default File decorator and override the render method to add your markup :
<?php
class My_Super_Custom_File_Decorator extends Zend_Form_Decorator_File
{
public function render($content)
{
$element = $this->getElement();
if (!$element instanceof Zend_Form_Element) {
return $content;
}
$view = $element->getView();
if (!$view instanceof Zend_View_Interface) {
return $content;
}
$name = $element->getName();
$attribs = $this->getAttribs();
if (!array_key_exists('id', $attribs)) {
$attribs['id'] = $name;
}
$separator = $this->getSeparator();
$placement = $this->getPlacement();
$markup = array();
$size = $element->getMaxFileSize();
if ($size > 0) {
$element->setMaxFileSize(0);
$markup[] = $view->formHidden('MAX_FILE_SIZE', $size);
}
if (Zend_File_Transfer_Adapter_Http::isApcAvailable()) {
$markup[] = $view->formHidden(ini_get('apc.rfc1867_name'), uniqid(), array('id' => 'progress_key'));
} else if (Zend_File_Transfer_Adapter_Http::isUploadProgressAvailable()) {
$markup[] = $view->formHidden('UPLOAD_IDENTIFIER', uniqid(), array('id' => 'progress_key'));
}
if ($element->isArray()) {
$name .= "[]";
$count = $element->getMultiFile();
for ($i = 0; $i < $count; ++$i) {
$htmlAttribs = $attribs;
$htmlAttribs['id'] .= '-' . $i;
$markup[] = $view->formFile($name, $htmlAttribs);
}
} else {
$markup[] = $view->formFile($name, $attribs);
}
$markup = implode($separator, $markup);
switch ($placement) {
case self::PREPEND:
return $markup . $separator . $content;
case self::APPEND:
default:
return $content . $separator . '<div>My Super Custom Markup : '.$markup.'</div>';
}
}
}
You should follow the basics to create a custom decorator (prefixPath, etc.) and apply your new decorator to your file element instead of 'File'.
Related
I use Moodle 3.9.1+ . I want to change summary exam table to div to be able to show the each question and its situation beside each-other like below. I want to have each 5 question in a row in fact. As I know it's not possible to do so with table and because of that I want to use div to be able to do so with css.
I found the file /mod/quiz/renderer.php has a function with below code that makes the summary exam table.
public function summary_table($attemptobj, $displayoptions) {
// Prepare the summary table header.
$table = new html_table();
$table->attributes['class'] = 'generaltable quizsummaryofattempt boxaligncenter';
$table->head = array(get_string('question', 'quiz'), get_string('status', 'quiz'));
$table->align = array('left', 'left');
$table->size = array('', '');
$markscolumn = $displayoptions->marks >= question_display_options::MARK_AND_MAX;
if ($markscolumn) {
$table->head[] = get_string('marks', 'quiz');
$table->align[] = 'left';
$table->size[] = '';
}
$tablewidth = count($table->align);
$table->data = array();
// Get the summary info for each question.
$slots = $attemptobj->get_slots();
foreach ($slots as $slot) {
// Add a section headings if we need one here.
$heading = $attemptobj->get_heading_before_slot($slot);
if ($heading) {
$cell = new html_table_cell(format_string($heading));
$cell->header = true;
$cell->colspan = $tablewidth;
$table->data[] = array($cell);
$table->rowclasses[] = 'quizsummaryheading';
}
// Don't display information items.
if (!$attemptobj->is_real_question($slot)) {
continue;
}
// Real question, show it.
$flag = '';
if ($attemptobj->is_question_flagged($slot)) {
// Quiz has custom JS manipulating these image tags - so we can't use the pix_icon method here.
$flag = html_writer::empty_tag('img', array('src' => $this->image_url('i/flagged'),
'alt' => get_string('flagged', 'question'), 'class' => 'questionflag icon-post'));
}
if ($attemptobj->can_navigate_to($slot)) {
$row = array(html_writer::link($attemptobj->attempt_url($slot),
$attemptobj->get_question_number($slot) . $flag),
$attemptobj->get_question_status($slot, $displayoptions->correctness));
} else {
$row = array($attemptobj->get_question_number($slot) . $flag,
$attemptobj->get_question_status($slot, $displayoptions->correctness));
}
if ($markscolumn) {
$row[] = $attemptobj->get_question_mark($slot);
}
$table->data[] = $row;
$table->rowclasses[] = 'quizsummary' . $slot . ' ' . $attemptobj->get_question_state_class(
$slot, $displayoptions->correctness);
}
// Print the summary table.
$output = html_writer::table($table);
return $output;
}
Can anyone help me to change this code and show desired information in div format?
I could at last solve the problem but it may not be very professional:
* Create the summary page
*
* #param quiz_attempt $attemptobj
* #param mod_quiz_display_options $displayoptions
*/
public function summary_page($attemptobj, $displayoptions) {
$output = '';
$output .= $this->header();
$output .= $this->heading(format_string($attemptobj->get_quiz_name()));
$output .= $this->heading(get_string('summaryofattempt', 'quiz'), 3);
$output .= $this->summary_table($attemptobj, $displayoptions);
$output .= $this->summary_page_controls($attemptobj);
$output .= $this->footer();
return $output;
}
/**
* Generates the table of summarydata
* sara
* #param quiz_attempt $attemptobj
* #param mod_quiz_display_options $displayoptions
*/
public function summary_table($attemptobj, $displayoptions) {
// Prepare the summary table header.
$table = new html_table();
$table->attributes['class'] = 'generaltable quizsummaryofattempt boxaligncenter';
$table->head = array(get_string('question', 'quiz'), get_string('status', 'quiz'));
$table->align = array('left', 'left');
$table->size = array('', '');
$markscolumn = $displayoptions->marks >= question_display_options::MARK_AND_MAX;
if ($markscolumn) {
$table->head[] = get_string('marks', 'quiz');
$table->align[] = 'left';
$table->size[] = '';
}
$tablewidth = count($table->align);
$table->data = array();
// Get the summary info for each question.
$slots = $attemptobj->get_slots();
foreach ($slots as $slot) {
// Add a section headings if we need one here.
$heading = $attemptobj->get_heading_before_slot($slot);
if ($heading) {
$cell = new html_table_cell(format_string($heading));
$cell->header = true;
$cell->colspan = $tablewidth;
$table->data[] = array($cell);
$table->rowclasses[] = 'quizsummaryheading';
}
// Don't display information items.
if (!$attemptobj->is_real_question($slot)) {
continue;
}
// Real question, show it.
$flag = '';
if ($attemptobj->is_question_flagged($slot)) {
// Quiz has custom JS manipulating these image tags - so we can't use the pix_icon method here.
$flag = html_writer::empty_tag('img', array('src' => $this->image_url('i/flagged'),
'alt' => get_string('flagged', 'question'), 'class' => 'questionflag icon-post'));
}
if ($attemptobj->can_navigate_to($slot)) {
$row = array(html_writer::link($attemptobj->attempt_url($slot),
$attemptobj->get_question_number($slot) . $flag),
$attemptobj->get_question_status($slot, $displayoptions->correctness));
} else {
$row = array($attemptobj->get_question_number($slot) . $flag,
$attemptobj->get_question_status($slot, $displayoptions->correctness));
}
if ($markscolumn) {
$row[] = $attemptobj->get_question_mark($slot);
}
$table->data[] = $row;
$table->rowclasses[] = 'quizsummary' . $slot . ' ' . $attemptobj->get_question_state_class(
$slot, $displayoptions->correctness);
$counter=0;
foreach($row as $r)
{
if($counter ==0)
{
$output .= html_writer::start_tag('div', array('class' => 'qsummary'.' '.'questionNo' .' q'. $slot. ' '.$attemptobj->get_question_status($slot, $displayoptions->correctness)));
$output .= $r;
$output .= html_writer::end_tag('div');
$counter=1;
}
else{
if($counter ==1)
{
$output .= html_writer::start_tag('div', array('class' => 'qsummary' .' '.'questionStat'.' q'. $slot. ' '.$attemptobj->get_question_status($slot, $displayoptions->correctness)));
$output .= $r;
$output .= html_writer::end_tag('div');
$counter=1;
}
}
}
}
// Print the summary table.
// $output = html_writer::table($table);
return $output;
}
I've created the following function to print HTML tags in PHP.
function div($attr = [], $child = []) {
$div = "<div";
if (is_array($attr)) {
foreach ($attr as $key => $value) {
$div .= " " . $key . '="' . $value . '"';
}
}
$div .= ">";
if (is_array($child)) {
foreach ($child as $value) {
$div .= $value;
}
}
$div .= "</div>";
return $div;
}
echo div(["class" => "container"], [
div(["class" => "title"], ["Lorem Ipsum"]])
]);
Now, I use this function with multiple tags; div, table, tr, td, etc.
For each tag, I declare the function over and over again with little modification in the body. This seems redundant. I want to create a main function which will return the actual function. For example,
$div = construct("div");
$tr = construct("div");
Of course, PHP is different than JS. In JS, this would work:
function construct(tagName) {
var elm = tagName;
return function(value) {
console.log(elm + ": " + value);
}
}
var div = construct("div");
var tr = construct("tr");
div("test"); // div: test
tr("test"); // tr: test
How should I proceed?
Similar actually as in js:
Just use the first argument of the function to pass the element type as a string.
function construct($elem, $attr = [], $child = []) {
$out = "<".$elem;
if (is_array($attr)) {
foreach ($attr as $key => $value) {
$out .= " " . $key . '="' . $value . '"';
}
}
$out .= ">";
if (is_array($child)) {
foreach ($child as $value) {
$out .= $value;
}
}
$out .= "</".$elem.">";
return $out;
}
echo construct("div",["class" => "container"], [
div(["class" => "title"], ["Lorem Ipsum"]])
]);
You could pass the type of tag through a parameter of the function.
function ConstrucElement($tag, $attr, $body)
{
$output = '<' . $tag;
....
$output .= '</' . $tag . '>';
}
This is how I would solve the problem at hand:
function element($elementName, $attr = [], $child = []) {
$element = "<" . $elementName;
...
return $element;
}
function div($attr = [], $child = []) {
return element("div", $attr, $child);
}
This has the additional benefit of enabling element specific validations etc.: (pseudocode)
function a($attr = [], $child = []) {
if(attr contains no href) return ERROR;
return element("div", $attr, $child);
}
Doing some more digging, I figured out a way to make it work the JS way. The use of use in the examples in PHP: Closure - Manual did the job.
function construct($tag_name = "") {
return function($attr = [], $child = []) use ($tag_name) {
$element = "<$tag_name";
if (is_array($attr)) {
foreach ($attr as $key => $value) {
$element .= " " . $key . '="' . $value . '"';
}
}
$element .= ">";
if (is_string($child)) {
$element .= $child;
}
if (is_array($child)) {
foreach ($child as $value) {
$element .= $value;
}
}
$element .= "</$tag_name>";
return $element;
};
}
$h2 = construct("h2");
$span = construct("span");
$div = construct("div");
$table = construct("table");
$tr = construct("tr");
$td = construct("td");
Using a generic function to print the tags seems like a more practical approach, but not that desirable, because the code gets harder to read. Compare the following blocks.
while ($row = $albums->fetch_assoc()) {
echo $div(["class" => "album"], [
$h2([], [$row["album"] . " (" . $row["year"] . ")"]),
$div(["class" => "album-cover"], [
img(["src" => "covers/" . $row["cover"]]),
]),
$div(["class" => "songs"], [
$table([], [
loop_songs($row["album"]),
]),
]),
]);
}
while ($row = $albums->fetch_assoc()) {
echo construct("div", ["class" => "album"], [
construct("h2", [], [$row["album"] . " (" . $row["year"] . ")"]),
construct("div", ["class" => "album-cover"], [
construct("img", ["src" => "covers/" . $row["cover"]]),
]),
construct("div", ["class" => "songs"], [
construct("table", [], [
loop_songs($row["album"]),
]),
]),
]);
}
First one seems more readable to me.
Here's another approach using __callStatic:
So now you can build your HTML with these:
Build::div(...)
Build::span(...)
Build::table(...)
Like this:
<?php
class Build {
public static function __callStatic($name, $arguments) {
$attr = $arguments[0];
$child = $arguments[1];
$div = "<" . $name;
if (is_array($attr))
foreach ($attr as $key => $value)
$div .= " " . $key . '="' . $value . '"';
$div .= ">";
if (is_array($child))
foreach ($child as $value)
$div .= $value;
$div .= "</" . $name . ">";
return $div;
}
}
echo Build::div(["class" => "container"], [
Build::span(["class" => "title"], ["Lorem Ipsum"])
]);
Output:
<div class="container"><span class="title">Lorem Ipsum</span></div>
I'm currently working on a Magento installation with multiple websites and store views. I'm attempting to redesign one of the four sub websites.
There has been a custom module added which appears to rewrite/extend the default top navigation menu to automatically include CMS pages and add a banner slot to the menu. The problem is that I want to restore the default Magento top menu (i.e. no CMS pages) for a single website view.
I've tried disabling the module inside System -> Config -> Advanced -> Advanced for that website, however this seems to make the entire top navigation disappear. I believe the function I want to remove is this:
<?php
/**
* extend functions from navigation.php
*
*/
class Fvzzy_Category_Block_Navigation extends Mage_Catalog_Block_Navigation
{
protected $_menus;
protected function _getCategoryMenuItemHtml($category, $level = 0, $isLast = false, $isFirst = false,
$isOutermost = false, $outermostItemClass = '', $childrenWrapClass = '', $noEventAttributes = false)
{
if (!$category->getIsActive()) {
return '';
}
$html = array();
// get all children
if (Mage::helper('catalog/category_flat')->isEnabled()) {
$children = (array)$category->getChildrenNodes();
$childrenCount = count($children);
} else {
$children = $category->getChildren();
$childrenCount = $children->count();
}
$hasChildren = ($children && $childrenCount);
// select active children
$activeChildren = array();
foreach ($children as $child) {
if ($child->getIsActive()) {
$activeChildren[] = $child;
}
}
$activeChildrenCount = count($activeChildren);
$hasActiveChildren = ($activeChildrenCount > 0);
// prepare list item html classes
$classes = array();
$classes[] = 'level' . $level;
//$classes[] = 'nav-' . $this->_getItemPosition($level);
$text = preg_replace('/[^A-Za-z0-9]/i', '-', strtolower($category->getName()));
//$classes[] = $category->;
if ($this->isCategoryActive($category)) {
$classes[] = 'active';
}
$linkClass = '';
if ($isOutermost && $outermostItemClass) {
$classes[] = $outermostItemClass;
$linkClass = ' class="'.$outermostItemClass.'"';
}
if ($isFirst) {
$classes[] = 'first';
}
if ($isLast) {
//$classes[] = 'last';
}
if ($hasActiveChildren) {
$classes[] = 'parent';
}
if(strtolower($text) == 'sale') $classes[] = strtolower($text);
// prepare list item attributes
$attributes = array();
if (count($classes) > 0) {
$attributes['class'] = implode(' ', $classes);
}
if ($hasActiveChildren && !$noEventAttributes) {
$attributes['onmouseover'] = 'toggleMenu(this,1)';
$attributes['onmouseout'] = 'toggleMenu(this,0)';
}
// assemble list item with attributes
$htmlLi = '<li';
foreach ($attributes as $attrName => $attrValue) {
$htmlLi .= ' ' . $attrName . '="' . str_replace('"', '\"', $attrValue) . '"';
}
$htmlLi .= '>';
$html[] = $htmlLi;
$html[] = '<a href="'.$this->getCategoryUrl($category).'"'.$linkClass.'>';
$html[] = '<span>' . $this->escapeHtml($category->getName()) . '</span>';
$html[] = '</a>';
// render children
$htmlChildren = '';
$j = 0;
foreach ($activeChildren as $child) {
$htmlChildren .= $this->_getCategoryMenuItemHtml(
$child,
($level + 1),
($j == $activeChildrenCount - 1),
($j == 0),
false,
$outermostItemClass,
$childrenWrapClass,
$noEventAttributes
);
$j++;
}
$promotion = $this->addPromotions($category->getId());
if (!empty($htmlChildren)) {
if ($childrenWrapClass) {
$html[] = '<div class="' . $childrenWrapClass . '">';
}
$html[] = '<ul class="level' . $level . '"><div class="menu-text">';
if($promotion) $html[] = '';
$html[] = $htmlChildren;
if($promotion) $html[] = '';
if($promotion) $html[] = '</div><li class="level1 parent menu-promotion">'.$promotion.'</li>';
$html[] = '</ul>';
if ($childrenWrapClass) {
$html[] = '</div>';
}
}
$html[] = '</li>';
$html = implode("\n", $html);
return $html;
}
public function renderCategoriesMenuHtml($level = 0, $outermostItemClass = '', $childrenWrapClass = '')
{
$activeCategories = array();
foreach ($this->getStoreCategories() as $child) {
if ($child->getIsActive()) {
$activeCategories[] = $child;
}
}
$activeCategoriesCount = count($activeCategories);
$hasActiveCategoriesCount = ($activeCategoriesCount > 0);
if (!$hasActiveCategoriesCount) {
return '';
}
$html = '';
$j = 0;
foreach ($activeCategories as $category) {
$html .= $this->_getCategoryMenuItemHtml(
$category,
$level,
($j == $activeCategoriesCount - 1),
($j == 0),
true,
$outermostItemClass,
$childrenWrapClass,
true
);
$j++;
}
//main store
if(Mage::app()->getStore()) $html .= $this->addMenu($childrenWrapClass,Mage::app()->getStore());
return $html;
}
protected function addPromotions($id = 0){
if($id){
$base = Mage::getBaseUrl('media',true).'promotion_box_images/';
$file_base = Mage::getBaseDir('media').'/promotion_box_images';
$html = ''; $img = '';
$promotion = Mage::getModel('promotion/box')->getCollection()->addFieldToFilter('menu_ids',array(
array('like'=>$id),
array('like'=>$id.',%'),
array('like'=>'%,'.$id.',%'),
array('like'=>'%,'.$id)))->setOrder('position')->getFirstItem(); //default is desc
if($promotion && $promotion->getId()){
$type=$promotion->getDisplayType();
$link = ''; $img = ''; $content = ''; $width = '';
if(file_exists($file_base.'/'.$promotion->getImage())){
list($width) = getimagesize($file_base.'/'.$promotion->getImage());
}
if($type!=null){
switch($type){
case 0:
if($promotion->getImage()!='') $img = '<img src="'.$base.$promotion->getImage().'" alt="'.$promotion->getTitle().'" width="'.$width.'"/>';
if(trim($promotion->getLink())!='') $link = $promotion->getLink();
break;
case 1:
if($promotion->getImage()!='') $img = '<img src="'.$base.$promotion->getImage().'" alt="'.$promotion->getTitle().'" width="'.$width.'"/>';
if($promotion->getCategoryId()){
$c = Mage::getModel('catalog/category')->load($promotion->getCategoryId());
if($c->getId() && $c->getIsActive()) $link = Mage::helper('catalog/category')->getCategoryUrl($c);
}
break;
case 2:
if($promotion->getImage()!='') $img = '<img src="'.$base.$promotion->getImage().'" alt="'.$promotion->getTitle().'" width="'.$width.'"/>';
if($promotion->getProductSku()){
$id = Mage::getModel('catalog/product')->getIdBySku($promotion->getProductSku());
$p = Mage::getModel('catalog/product')->load($id);
if($p->getId()) $link = $p->getProductUrl();
}
break;
case 3:
if($promotion->getImage()!='') $img = '<img src="'.$base.$promotion->getImage().'" alt="'.$promotion->getTitle().'" width="'.$width.'"/>';
if($promotion->getPageId()){
$_link = Mage::Helper('cms/page')->getPageUrl($promotion->getPageId());
if($_link != ''){
$nodes = Mage::getModel('enterprise_cms/hierarchy_node')->getCollection()
->addFieldToFilter('page_id', array('eq' => $promotion->getPageId()));
foreach($nodes as $_node){
$link = $_node->getRequestUrl();
}
if(!$link){$link = Mage::Helper('cms/page')->getPageUrl($promotion->getPageId());}
}
}
break;
case 4:
$content = $promotion->getContent();
break;
}
}
if($img && $link){
$html = ''.$img.'';
}
elseif($img){
$html = ''.$img.'';
}
else{
$html = $content;
}
}
return $html;
}else{return false;}
}
//$menu = array( array('label'=>'News','href'=>'blog','module'=>'blog','sub'=>array(array('label'=>'submenu','href'=>'blog2','module'=>'blog'))) );
public function setOtherMenu($menu){
$this->_menus = $menu;
}
public function addMenu( $childrenWrapClass = '', $store ) {
$this->_node_ids = array();
$current_module = $this->getRequest()->getModuleName();
$page_id = $this->getRequest()->getParam('page_id');
// get all the cms page nodes not folder or containers
$nodes = Mage::getModel('enterprise_cms/hierarchy_node')->getCollection()
->joinMetaData()
->addFieldToFilter( 'level', 1 )
//->addFieldToFilter( 'menu_visibility', 1 )
->addFieldToFilter( 'main_table.page_id', array( 'notnull' => true ))
->setOrder('sort_order','ASC');
if ( $store instanceof Mage_Core_Model_Store ) {
$store = $store->getId();
$storeIds = array( 0, $store );
$nodes->getSelect()
->joinLeft( array( 'cs' => 'cms_page_store' ), 'main_table.page_id=cs.page_id', array( 'cs.store_id' ) )
->where( 'cs.store_id IN ('. implode( ',', $storeIds ) .')' ); // not the best sql here but it works as store id will be one at a time.
}
$active_node = Mage::registry('current_cms_hierarchy_node');
$active_node_ids = array();
if($active_node){
$xpath = $active_node->getXpath();
$all = explode( '/', $xpath );
foreach ( $all as $index ) $active_node_ids[] = $index;
}
$this->_node_ids = $active_node_ids;
if ( $this->_menus ) {
$menus = $this->_menus;
}
else {
$menus = array();
}
$links = '';
foreach ( $nodes as $node ) {
$tree = $node->setCollectActivePagesOnly(true)
->setCollectIncludedPagesOnly(true)
->setTreeMaxDepth(0)
->setTreeIsBrief(1) //this way it won't show the container link
->getTreeSlice(0, 1); //up to tree top and down to one level
$links .= $this->drawCmsMenu($tree,0,1,$childrenWrapClass);
}
foreach ( $menus as $menu ) {
if(isset($menu['sub'])) $has_sub_class = ' parent'; else $has_sub_class = '';
if (isset($menu['module']) && $current_module == $menu['module'] ) {
$links .= '<li class="level0 level-top active'.$has_sub_class.'">';
}
else {
$links .= '<li class="level0 level-top'.$has_sub_class.'">';
}
$html = '';
if(isset($menu['sub']) && is_array($menu['sub'])){
$submenu = $menu['sub'];
$html .= '<div class="'.$childrenWrapClass.'"><ul class="level0">';
foreach($submenu as $sub){
if(is_array($sub) &&isset($sub['href']) && isset($sub['label']))
//2012-11-20 AU TEAM coding for change <h2> -> <span>
$html .= '<li class="level1"><span>'.$sub['label'].'</span></li>';
}
$html .= '</div>';
}
if(isset($menu['href']) && isset($menu['label']))
$links .= '<a class="level-top" href="'.Mage::getBaseUrl().$menu['href'].'"><span>'.$menu['label'].'</span></a>';
//add submenu
if($html != '') $links .= $html;
$links .= '</li>';
}
return $links;
}
/* Add Maximal Depth filter
* 2012.04.11 by Bruce
*/
public function drawCmsMenu( array $tree, $parentNodeId = 0, $level = 0, $childrenWrapClass = '' ) {
$html = '';
if ( !isset($tree[$parentNodeId ])) return $html;
foreach ( $tree[ $parentNodeId ] as $nodeId => $node ) {
/* #var $node Enterprise_Cms_Model_Hierarchy_Node */
$nested = $this->drawCmsMenu( $tree, $nodeId, $node->getLevel()+1, $childrenWrapClass);
$hasChildren = ( $nested != '' );
// set style classes
$class = array();
$class[] = 'level'. ( $level - 1 );
if ( $level - 1 == 0 )
$class[] = 'level-top';
if ( $this->_node_ids && in_array( $node->getNodeId(), $this->_node_ids ) )
$class[] = 'active';
if ( $hasChildren )
$class[] = 'parent';
// li wrapper header
$html .= '<li class="'. implode( ' ', $class ) .'">';
$html .= $this->_getNodeLabel( $node, $level - 1 );
// div wrapper header
if ( $hasChildren ){
if ( $childrenWrapClass ) $html .= '<div class="'. $childrenWrapClass .'">';
$html .= '<ul class="level'. ( $level - 1 ) .'">';
}
// children
$html .= $nested;
// div wrapper footer
if ( $hasChildren ) {
$html.='</ul>';
if ( $childrenWrapClass ) $html .= '</div>';
}
// li wrapper footer
$html .= '</li>';
}
return $html;
}
protected function _getNodeLabel($node,$level)
{
if($level==0) $class = 'level-top'; else $class = '';
if($node->getPageTitle()) return '<a class="'.$class.'" href="'.$node->getUrl().'"><span>'.$node->getPageTitle().'</span></a>';
else return '<a class="'.$class.'" href="'.$node->getUrl().'"><span>'.$node->getLabel().'</span></a>';
}
}
I know that the config file for this module looks like the following:
<?xml version="1.0"?>
<config>
<modules>
<Fvzzy_Category>
<version>0.1.0</version>
</Fvzzy_Category>
</modules>
<global>
<blocks>
<fvzzy_category>
<class>Fvzzy_Category_Block</class>
</fvzzy_category>
<catalog>
<rewrite>
<navigation>Fvzzy_Category_Block_Navigation</navigation>
</rewrite>
</catalog>
</blocks>
<resources>
<fvzzy_category_setup>
<setup>
<module>Fvzzy_Category</module>
<class>Mage_Catalog_Model_Resource_Eav_Mysql4_Setup</class>
</setup>
</fvzzy_category_setup>
</resources>
</global>
</config>
And that if I'm able to remove the following part from that file, I get my intended outcome:
<catalog>
<rewrite>
<navigation>Fvzzy_Category_Block_Navigation</navigation>
</rewrite>
</catalog>
The problem is, I just want to get the top navigation menu function restored back to normal for one website view.
Is there any way to overwrite that navigation rewrite event for one store/website view?
If not, is it possible to disable this module without it disabling my whole top menu for that website view?
I've tried completely duplicating the module, disabling the original one and enabling the new one in my desired website but that also appears to be making the top menu disappear entirely.
I'm really not sure what else to do with this - if anyone is able to help it would be hugely appreciated.
Thanks so much.
if you want this extension still for your Magento application, then disabling the extension will not produce expecting result.
In this case, you can do two things
Overwrite this custom extension with your module and make changes according to your need
comment out the config section that defines that core block overwrite. You have already tried it and worked it
There is another alternative. You can do a condition checking inside the rewrite block class. This condition check somewhat look like this.
if(Mage::app()->getStore()->getCode()== 'website_code_for_sub_site'){
//execute existing code
}
This method ensure that, the method that defined inside the rewrite block class will get executed only when the site with a code website_code_for_sub_site is viewing.
Hope that helps
I what to put a span element for $term['nodes']
I have tried to put after bracket and between but nothing works for me
if (isset($term['nodes'])) {
$term['name'] = $term['name'] . ' (' . $term['nodes'] . ')';
}
here is the all functin
function bootstrap_taxonomy_menu_block($variables) {
$tree = $variables['items'];
$config = $variables['config'];
$num_items = count($tree);
$i = 0;
$output = '<ul class="nav nav-pills nav-stacked">';
foreach ($tree as $tid => $term) {
$i++;
// Add classes.
$attributes = array();
if ($i == 1) {
$attributes['class'][] = '';
}
if ($i == $num_items) {
$attributes['class'][] = '';
}
if ($term['active_trail'] == '1') {
$attributes['class'][] = 'active-trail';
}
if ($term['active_trail'] == '2') {
$attributes['class'][] = 'active';
}
// Alter link text if we have to display the nodes attached.
if (isset($term['nodes']))
{
$term['name'] = $term['name'] . ' (<span>' . $term['nodes'] . '</span>)';
}
// Set alias option to true so we don't have to query for the alias every
// time, as this is cached anyway.
$output .= '<li' . drupal_attributes($attributes) . '>' . l($term['name'], $term['path'], $options = array('alias' => TRUE));
if (!empty($term['children'])) {
$output .= theme('taxonomy_menu_block__' . $config['delta'], (array('items' => $term['children'], 'config' => $config)));
}
$output .= '</li>';
}
$output .= '</ul>';
return $output;
}
i what this for the bootstrap cdn class , i have move the function on template.php , of drupal theme , but the span element is in plain text in browser
Try this:
if (isset($term['nodes']))
{
$term['name'] = $term['name'] . ' (<span>' . $term['nodes'] . '</span>)';
echo $term['name']; // To see the output
}
I have this Form with several subForms I'm using a tabContainer,
In one of them I have a button when clicked would like that in that "space" subForm
a datagrid would appear with some values.
Is it possible to do this, how?
I tried creating a datagrid View Helper but this didn't work properly the DataGrid does not show.
Code used:
/** * Description of DataGrid * * #author andref * #version $Id$
*/ class Zend_View_Helper_DataGrid {
private $_nameDG = 'DefaultSt';
private $_action = '';
private $_key = '';
private $_selectMode = "single";
private $_fields = array();
private $_storage = 'getall/';
public function dataGrid($key, $action = null, $options = array() )
{
if (count($options) > 0 ) {
if (array_key_exists("selectmode", $options)) {
$this->_selectMode = $options['selectmode'];
} elseif (array_key_exists("fields", $options)) {
if (!is_array($options['fields'])) {
throw new Exception("fields is not an array");
}
$this->_fields = $options['fields'];
} elseif(array_key_exists("selectmode", $options)) {
$this->_selectMode = $options['selectmode'];
} elseif(array_key_exists("storage", $options)) {
$this->_storage = $options['storage'];
}
}
if ($action !== null ) {
$this->_action = $action;
}
if ($key === null ) {
throw new Exception("Key cannot be null.");
}
$this->_key = $key;
return $this->_init();
}
private function _init()
{
$str = '';
if (!empty($this->_action)) {
$str .= $this->addJS();
}
$str .= $this->storageType();
$str .= $this->draw();
return $str;
}
/**
* Returns double click handler to direct to a form
*
* #return String
*/
public function addJS()
{
$str = "<script type=\"text/Javascript\">\n";
$str .= "function pickit(event)\n";
$str .= "{\n";
$str .= "grid = dijit.byId('grid".$this->_key."');\n";
$str .= "selected_index = grid.focus.rowIndex;\n";
$str .= "selected_item = grid.getItem(selected_index);\n";
//Not sure if this is the most efficient way but it worked for me
$str .= "selected_id = grid.store.getValue(selected_item, \"".$this->_key."\");\n";
$str .= "location.href = " . $this->_action . "+selected_id;\n";
$str .= "}\n";
$str .= "</script>\n";
return $str;
}
public function storageType()
{
if (strpos($this->_storage, "[") !== false ) {
$st = "jsonData".$this->_key . " = " . $this->_storage."\n";
$st .= "<gett dojoType=\"dojo.data.ItemFileReadStore\"
jsId=\"jsonStore" . $this->_key . "\"
data=\"jsonData" . $this->_key . "\" id=\"store" . $this->_key . "\" />";
} else {
$st = '<gett dojoType="dojo.data.ItemFileReadStore" jsId=\"jsonStore'.$this->_key.'"
url="' . $this->_storage . '" id="store'.$this->_key.'" />';
}
return $st;
}
public function draw()
{
$str = '';
$str .= "<table dojoType=\"dojox.grid.DataGrid\" id=\"grid".$this->_key."\" jsid=\"gridJ".$this->_key."\"
query=\"{ " . $this->_key . ": '*' }\" store=\"jsonStore".$this->_key."\"
selectionMode=\"" . $this->_selectMode . "\" autoWidth=\"true\"
style=\"width: 100%; height: 400px\" onRowDblClick='pickit();'>\n";
$str .= "<thead>\n";
$str .= "<tr>\n";
foreach ($this->_fields as $k => $v ) {
$str .= "\t<th field=\"$k\">$v</th>\n";
}
$str .= "</tr>\n";;
$str .= "</thead>\n";
$str .= "</table>\n";
return $str;
}
}
try creating a grid in pure js and place it
using grid.placeat("idOfElement") in your element. Take a look here:
http://dojotoolkit.org/reference-guide/1.8/dojox/grid/DataGrid.html