what is the use of links__system_main_menu in drupal?
<?php if ($main_menu): ?>
<div id="main-menu" class="navigation">
<?php print theme('links__system_main_menu', array(
'links' => $main_menu,
'attributes' => array(
'id' => 'main-menu-links',
'class' => array('links', 'clearfix'),
),
'heading' => array(
'text' => t('Main menu'),
'level' => 'h2',
'class' => array('element-invisible'),
),
)); ?>
</div> <!-- /#main-menu -->
This is a pattern for theme hook, in the form [base hook]__[context]. When links theme with theme('links__system_main_menu', $variables), theme() function search for *theme_links__system_main_menu()* and use it. Otherwise, if it doesn't find, it will use *theme_links()*. For more information check the theme Doc
Related
I've managed to generate menu using Zend Navigation. However, the active page is never set (active class is not set for any <li> element).
My partial:
foreach ($pages as $page): ?>
<?php if (!$page->isVisible() || !$this->navigation()->menu()->accept($page)) continue; ?>
<li role="presentation" <?php if ($page->isActive()) echo 'class="active"' ?>>
<a href="<?php echo $page->getHref() ?>">
<?php if ($icon = $page->get('icon')) {
echo '<span class="' . $icon . '"></span>';
} ?>
<span> <?php echo $this->translate($page->getLabel()) ?> </span>
</a>
</li>
<?php endforeach ?>
Extract of module.config.php:
'navigation' => array(
'default' => array(
array(
'label' => 'Page 1',
'route' => 'application/default',
'namespace' => 'Application\Controller',
'controller' => 'Index',
'action' => 'page1',
'icon' => 'fa fa-2x fa-file-text',
'order' => 10,
),
array(
'label' => 'Page 2',
'route' => 'application/default',
'namespace' => 'Application\Controller',
'controller' => 'Index',
'action' => 'page2',
'icon' => 'fa fa-2x fa-file-text',
'order' => 20,
),
),
),
The menu is rendered properly on the page, but without any active class:
$partial = array('partial/menu.phtml', 'default');
echo $this->navigation('navigation')
->menu()
->setMinDepth(0)
->setMaxDepth(0)
->setPartial($partial);
After some research into ZF code, I've found something I don't understand (in Zend\View\Helper\Navigation\Menu.php):
// in renderNormalMenu function, line 288
$isActive = $page->isActive(true);
Any idea or suggestion regarding my problem?
Thanks a lot,
Problem was in module.config.php ; the isActive method (from Zend\Navigation\Mvc) was expected the "full" controller name (including namespace).
My config was splitting namespace and controller name, wich causes the issue.
Solution:
array(
'label' => 'Page 1',
'route' => 'application/default',
'controller' => 'Application\Controller\Index',
'action' => 'page1',
'icon' => 'fa fa-2x fa-file-text',
'order' => 10,
),
I have the following configuration for my navigation in my application module in Application/config/module.config.php:
'navigation' => array(
'default' => array(
array(
'label' => 'Home',
'route' => 'home'
)
)
)
I have the following configuration for my navigation in my cortana module in Cortana/config/module.config.php:
'navigation' => array(
'default' => array(
array(
'label' => 'Home',
'route' => 'cortana-home'
),
array(
'label' => 'Resources',
'route' => 'cortana-resources'
),
array(
'label' => 'Reports',
'route' => 'cortana-reports'
),
array(
'label' => 'Services',
'route' => 'cortana-services'
),
array(
'label' => 'System',
'route' => 'cortana-system'
)
)
)
Im using the layout in my Cortana modulle. Here is the navigation code:
<div class="collapse navbar-collapse">
<?php echo $this->navigation('navigation')
->menu()
->setMinDepth(0)
->setMaxDepth(0)
->setUlClass('nav navbar-nav');
?>
</div><!--/.nav-collapse -->
And finally, unfortunately my result compiles the following HTML:
<li>
Home
</li>
<li class="active">
Home
</li>
<li>
Resources
</li>
<li>
Reports
</li>
<li>
Services
</li>
<li>
System
</li>
</ul> </div><!--/.nav-collapse -->
As you can see, there is 2 home navigation pages. It looks like the code merged the Application navigation module and the Cortana navigation module.
What I need is to have a navigation for the Cortana module and then a separate navigation for the Application module.
UPDATE
I've also tried changing the navigation key to cortana-navigation the following:
/Cortana/config/module.config.php
'service_manager' => array(
'factories' => array(
'cortana-navigation' => 'Zend\Navigation\Service\DefaultNavigationFactory'
)
),
'cortana-navigation' => array(
'default' => array(
array(
'label' => 'Home',
'route' => 'cortana-home'
),
array(
'label' => 'Resources',
'route' => 'cortana-resources'
),
array(
'label' => 'Reports',
'route' => 'cortana-reports'
),
array(
'label' => 'Services',
'route' => 'cortana-services'
),
array(
'label' => 'System',
'route' => 'cortana-system'
)
)
)
And then in my Cortana layout (Cortana/view/layout/layout.phtml)
<div class="collapse navbar-collapse">
<?php echo $this->navigation('cortana-navigation')
->menu()
->setMinDepth(0)
->setMaxDepth(0)
->setUlClass('nav navbar-nav');
?>
</div><!--/.nav-collapse -->
And now my result compiled HTML is:
<ul class="nav navbar-nav">
<li>
Home
</li>
</ul> </div><!--/.nav-collapse -->
I unfortunately have no explanation for why its now using the Application navigation (navigation) instead of the (cortana-navigation) but it does mean that its responding to the change of factory
SECOND UPDATE
I did notice that in the file `Zend/Navigaiton/Service/DefaultNavigationFactory.php' :
class DefaultNavigationFactory extends AbstractNavigationFactory
{
/**
* #return string
*/
protected function getName()
{
return 'default';
}
}
This might mean something with using the default name
I have a custom admin page in prestashop and i would like to add a URL link at the bottom of that page. However, i am very new to prestashop and can not figure out how to do this.
I have an admin controller file for the module that creates the custom page with a form on it and was wondering how i can add a link at the bottom of the page that simply goes to another static page on the site or even an external page.
AdminFedeltaSchoolsController.php content
<?php
class AdminFedeltaSchoolsController extends ModuleAdminController {
public function __construct() {
// Configure admin controller with table, model, language and bootstrap theme
$this->table = 'fedeltapos_school';
$this->className = 'FedeltaposModel';
$this->lang = true;
$this->bootstrap = true;
// Generat action on list
$this->addRowAction('edit');
$this->addRowAction('delete');
// This adds a multiple deletion button
$this->bulk_actions = array(
'delete' => array(
'text' => $this->l('Delete selected'),
'confirm' => $this->l('Delete selected items?')
)
);
// Generat list
$this->fields_list = array(
'id_fedeltapos_school' => array(
'title' => $this->l('ID'),
'align' => 'center',
'width' => 25
),
'school_name' => array(
'title' => $this->l('School Name'),
'width' => 'auto'
),
'delivery' => array(
'title' => $this->l('Delivery'),
'width' => 'auto'
),
'pickup' => array(
'title' => $this->l('Pickup'),
'width' => 'auto'
),
'pricelevel' => array(
'title' => $this->l('Price Level'),
'width' => 'auto',
),
);
parent::__construct();
}
// This method generates the Add/Edit form
public function renderForm() {
// Building the Add/Edit form
$this->fields_form = array(
'legend' => array(
'title' => $this->l('Schools'),
'icon' => 'icon-envelope-alt'
),
'input' => array(
array(
'type' => 'text',
'label' => $this->l('School Name:'),
'name' => 'school_name',
'lang' => true,
'size' => 33,
'required' => true,
), array(
'type' => 'text',
'label' => $this->l('Delivery:'),
'name' => 'delivery',
'size' => 33,
'required' => true,
),
array(
'type' => 'text',
'label' => $this->l('Pickup:'),
'name' => 'pickup',
'size' => 33,
'required' => true,
),
array(
'type' => 'text',
'label' => $this->l('Price Level:'),
'name' => 'pricelevel',
'size' => 33,
'required' => true,
),
),
'submit' => array(
'title' => $this->l('Save')
)
);
return parent::renderForm();
}
}
I would like the link at the bottom of the page (see screenshot):
http://awesomescreenshot.com/08252wdh8a
Any assistance will be appreciated.
Override the default content admin template file of your admin controller.
Create /your-admin-folder/themes/default/template/controllers/fedelta_schools/content.tpl
{if isset($content)}
{$content}
{/if}
{block name="override_tpl_schools"}
<div class="row">
<div class="col-lg-12">
<div class="panel">
<h3>
<i class="icon-info"></i>
{l s='Help'}
</h3>
<p>{l s='You can find answer of your question here :'} <a href='#'>{l s='FAQ'}</a> </p>
</div>
</div>
</div>
{/block}
Here's my form
<?php $form=$this->beginWidget('booster.widgets.TbActiveForm',array(
'id'=>'listing-main-form',
'enableAjaxValidation'=>false,
'action'=>Yii::app()->createUrl('site/search'),
'method'=>'get',
)); ?>
<div class="form-group" style="padding-bottom:0px;border:none">
<label class="control-label" for="selecttype">Type</label>
<?php echo $form->dropDownListGroup(
$model,
'prp',
array(
'wrapperHtmlOptions' => array(
'class' => 'col-sm-5',
),
'widgetOptions' => array(
'data' => CHtml::listData(Type::model()->findAll(), 'id', 'type'),
'htmlOptions' => array('id'=>'selecttype'),
),
'label' => ''
)
); ?>
</div>
<div class="form-group">
<div id="resproperties">
<div class="resdv">
<?php echo $form->checkboxListGroup(
$model,
'rs',
array(
'widgetOptions' => array(
'data' =>CHtml::listData(ResourceCategory::model()->findAll(), 'id', 'res_category'),
),
'label' => ''
)
); ?>
</div>
</div>
............
............
When the form is submitted, I can read all the field's data fine. But the url appears with Model[field] for each fields and looks very ugly (see below). Is there any where I can remove the model name from there?
index.php?r=site/search&ItemModel[prp]=1&ItemModel[rs]=&ItemModel[rs][]=2&ItemModel[rs][]=3&ItemModel[rs][]=4&ItemModel[cm] ............
You can explicitly set input name.
...
'htmlOptions' => array(
'id'=>'selecttype',
'name' => 'fieldname'
)
...
Also you can override CHtml and CActiveForm classes.
In your array for each element, add
'name'=>'your_custom_name'
So...
<?php echo $form->dropDownListGroup(
$model,
'prp',
array(
'wrapperHtmlOptions' => array(
'class' => 'col-sm-5',
),
'widgetOptions' => array(
'data' => CHtml::listData(Type::model()->findAll(), 'id', 'type'),
'htmlOptions' => array('id'=>'selecttype'),
),
'label' => '',
'name' => 'customName'
)
); ?>
I can render my menu "Main Menu":
<?php if ($main_menu): ?>
<?php print theme('links__system_main_menu', array(
'links' => $main_menu,
'attributes' => array(
'id' => 'main-menu-links',
'class' => array('nav', 'navbar-nav'),
),
'heading' => array(
'text' => t('Main menu'),
'level' => 'h2',
'class' => array('element-invisible'),
),
)); ?>
<?php endif; ?>
All works fine!
Then i create custom menu "Custom Menu" with machine name: "custom-menu".
How can I render a this menu similar to the example above?
Thanks in advance.
Each Menu creates a block, and you can do templates for each blocks. Maybe that's an easier way to do it, see How to theme a menu block in Drupal?