1- List view
We start from Cars list view
/ administrator / components / com_dealer / views / cars / view.html.php
Have a look at view.html.php file for cars listing:
<?php
// No direct access to this file
defined('_JEXEC') or die('Restricted access');
/**
* View file
*/
class DealerViewCars extends JViewLegacy
{
/**
* An array of items
*
* @var array
*/
protected $items;
/**
* The pagination object
*
* @var JPagination
*/
protected $pagination;
/**
* The model state
*
* @var object
*/
protected $state;
/**
* Form object for search filters
*
* @var JForm
*/
public $filterForm;
/**
* The active search filters
*
* @var array
*/
public $activeFilters;
/**
* The sidebar markup
*
* @var string
*/
protected $sidebar;
/**
* Array of options to customize the list form
*
* @var array
*/
public $options;
public function display($tpl = null)
{
// Get data from the model
$this->items = $this->get('Items');
$this->pagination = $this->get('Pagination');
$this->state = $this->get('State');
$this->filterForm = $this->get('FilterForm');
$this->activeFilters = $this->get('ActiveFilters');
// Check for errors.
if (count($errors = $this->get('Errors'))):
throw new Exception(implode("\n", $errors), 500);
endif;
// process plugin
$this->prms = new stdClass();
JPluginHelper::importPlugin( Bp::getComponent() );
$dispatcher = JEventDispatcher::getInstance();
$results = $dispatcher->trigger( 'on'.ucfirst(Bp::getComponent()).ucfirst(Bp::getView()).'ContentPrepare'
, array( &$this->items, &$this->filterForm, &$this->activeFilters, &$this->prms )
);
if ($this->getLayout() !== 'modal'):
// Load menu and submenu.
DealerHelper::addSubmenu( $this->getName());
endif;
BpForm::admAddListButtons();
$this->sidebar = JHtmlSidebar::render();
parent::display($tpl);
}
}
// pure php no tag
As you can see, you can copy and paste the whole script for every list view in your component, changing only the class' name.
The display method also triggers plugin, with a customized event "onDealerCarsContentPrepare" performed by these lines:
<?php
$results = $dispatcher->trigger( 'on'.ucfirst(Bp::getComponent()).ucfirst(Bp::getView()).'ContentPrepare'
, array( &$this->items, &$this->filterForm, &$this->activeFilters, &$this->prms )
);
and customized automatically by the class Bp.
The list buttons are managed by the class BpForm automatically, using admAddListButtons() method:
<?php
BpForm::admAddListButtons();
The method appends the (most commonly used) buttons:
- component preference
- new
- edit
- publish
- delete
What if you don't need the "component preference" button but do require a custom link button instead?
Just pass an array of your instructions to the method :
<?php
// prepare the options to customize the toolbar
$options = array();
$options['preference'] = false; // disable component preference button
// to add a custom link you can pass an object or an array
// let's pass an array for this example but the object is the same process
$customLink = array();
// you can fully customize the button
$customLink['class'] = 'myclass myclass-expanded'; // the a tag class
$customLink['href'] = 'my/path/to/file.html'; // the href link
$customLink['extra'] = 'extra attribute to the a tag I nedd to append'; // extra content for the a tag
$customLink['iconClass'] = "icon class to include an icon before the button name"; // add an icon to the button
$customLink['txt'] = "COM_DEALER_CUSTOM_LINK_LABEL"; // language label key
// then pass the instructions array to the method
$options['custom_link'] = $customLink;
BpForm::admAddListButtons($options);
For the full customization options have a look inside the BpForm class file and customize following the same process.
The dealerHelper class is the standard submenu helper class:
<?php
// No direct access to this file
defined('_JEXEC') or die('Restricted access');
/**
* Dealer's component helper.
*
* @param string $submenu The name of the active view.
*
* @return void
*
* @since 1.6
*/
abstract class DealerHelper
{
/**
* Configure the Linkbar.
*
* @param string $vName The name of the active view.
*
* @return void
*/
public static function addSubmenu($vName = 'cars')
{
// dealer categories
JHtmlSidebar::addEntry( '<i class="fa fa-folder"> </i>'
. JText::_('COM_DEALER_SUBMENU_CARS_CATEGORIES'),
'index.php?option=com_categories&view=categories&extension=com_dealer',
$vName == 'categories'
);
// cars
JHtmlSidebar::addEntry(
JText::_('COM_DEALER_SUBMENU_CARS'),
'index.php?option=com_dealer&view=cars',
$vName == 'cars'
);
// customers
JHtmlSidebar::addEntry(
JText::_('COM_DEALER_SUBMENU_CUSTOMERS'),
'index.php?option=com_dealer&view=customers',
$vName == 'customers'
);
if ($vName == 'categories'):
$doc = JFactory::getDocument();
$doc->setTitle(JText::_('COM_DEALER_SUBMENU_CARS_CATEGORIES'));
endif;
}
}