Source for file toolbar.php
Documentation is available at toolbar.php
* @package FrameworkOnFramework
* @copyright Copyright (C) 2010 - 2012 Akeeba Ltd. All rights reserved.
* @license GNU General Public License version 2 or later; see LICENSE.txt
// Protect from unauthorized access
* The Toolbar class renders the back-end component title area and the back-
* and front-end toolbars.
* @package FrameworkOnFramework
/** @var array Configuration parameters */
/** @var array Input (e.g. request) variables */
/** @var array Permissions map, see the __construct method for more information */
/** @var array The links to be rendered in the toolbar */
/** @var bool Should I render the submenu in the front-end? */
/** @var bool Should I render buttons in the front-end? */
* Gets an instance of a component's toolbar
* @param string $option The name of the component
* @param array $config The configuration array for the component
* @return FOFToolbar The toolbar instance for the component
public static function &getAnInstance($option =
null, $config =
array())
static $instances =
array();
// Make sure $config is an array
$config = (array)
$config;
elseif (!is_array($config))
if (!array_key_exists($hash, $instances))
if (array_key_exists('input', $config))
if ($config['input'] instanceof
FOFInput)
$input =
$config['input'];
$input =
new FOFInput($config['input']);
$config['option'] =
!is_null($option) ?
$option :
$input->getCmd('option', 'com_foobar');
$input->set('option', $config['option']);
$config['input'] =
$input;
$componentPaths['main'] .
'/toolbars',
$componentPaths['alt'] .
'/toolbars'
$searchPaths, 'toolbar.php'
$className =
'FOFToolbar';
$instance =
new $className($config);
$instances[$hash] =
$instance;
return $instances[$hash];
* @param array $config The configuration array of the component
// Make sure $config is an array
$config = (array)
$config;
// Get the input for this MVC triad
$this->input =
$config['input'];
// Get the default values for the component and view names
$this->component =
$this->input->getCmd('option', 'com_foobar');
// Overrides from the config
$this->component =
$config['option'];
$this->input->set('option', $this->component);
// Get default permissions (can be overriden by the view)
'manage' =>
$platform->authorise('core.manage', $this->input->getCmd('option', 'com_foobar')),
'create' =>
$platform->authorise('core.create', $this->input->getCmd('option', 'com_foobar')),
'edit' =>
$platform->authorise('core.edit', $this->input->getCmd('option', 'com_foobar')),
'editstate' =>
$platform->authorise('core.edit.state', $this->input->getCmd('option', 'com_foobar')),
'delete' =>
$platform->authorise('core.delete', $this->input->getCmd('option', 'com_foobar')),
// Save front-end toolbar and submenu rendering flags if present in the config
// If not in the administrative area, load the JToolbarHelper
// Pretty ugly require...
require_once JPATH_ROOT .
'/administrator/includes/toolbar.php';
// Things to do if we have to render a front-end toolbar
// Load back-end toolbar language files in front-end
// Load the core Javascript
JHtml::_('behavior.framework', true);
// Store permissions in the local toolbar object
* Renders the toolbar for the current view and task
* @param string $view The view of the component
* @param string $task The exact task of the view
* @param FOFInput $input An optional input object used to determine the defaults
public function renderToolbar($view =
null, $task =
null, $input =
null)
$saveInput =
$this->input;
// If tmpl=component the default behaviour is to not render the toolbar
if ($this->input->getCmd('tmpl', '') ==
'component')
// If there is a render_toolbar=0 in the URL, do not render a toolbar
$render_toolbar =
$this->input->getBool('render_toolbar', $render_toolbar);
$view =
$this->input->getCmd('view', 'cpanel');
$task =
$this->input->getCmd('task', 'default');
$component =
$input->get('option', 'com_foobar', 'cmd');
$toolbar =
$configProvider->get(
$component .
'.views.' .
'.toolbar'
// If we have a toolbar config specified
return $this->renderFromConfig($toolbar);
// Check for an onViewTask method
return $this->$methodName();
// Check for an onView method
$methodName =
'on' .
ucfirst($view);
return $this->$methodName();
// Check for an onTask method
$methodName =
'on' .
ucfirst($task);
return $this->$methodName();
$this->input =
$saveInput;
* Renders the toolbar for the component's Control Panel page
$option =
$this->input->getCmd('option', 'com_foobar');
JToolBarHelper::preferences($option, 550, 875);
* Renders the toolbar for the component's Browse pages (the plural views)
// On frontend, buttons must be added specifically
$option =
$this->input->getCmd('option', 'com_foobar');
$subtitle_key =
strtoupper($option .
'_TITLE_' .
$this->input->getCmd('view', 'cpanel'));
if ($this->perms->create)
JToolBarHelper::addNew();
JToolBarHelper::addNewX();
JToolBarHelper::editList();
JToolBarHelper::editListX();
JToolBarHelper::divider();
if ($this->perms->editstate)
JToolBarHelper::publishList();
JToolBarHelper::unpublishList();
JToolBarHelper::divider();
$msg =
JText::_($this->input->getCmd('option', 'com_foobar') .
'_CONFIRM_DELETE');
JToolBarHelper::deleteList($msg);
* Renders the toolbar for the component's Read pages
// On frontend, buttons must be added specifically
$option =
$this->input->getCmd('option', 'com_foobar');
$subtitle_key =
strtoupper($option .
'_TITLE_' .
$this->input->getCmd('view', 'cpanel') .
'_READ');
JToolBarHelper::title(JText::_(strtoupper($option)) .
' – <small>' .
JText::_($subtitle_key) .
'</small>', $componentName);
* Renders the toolbar for the component's Add pages
// On frontend, buttons must be added specifically
$option =
$this->input->getCmd('option', 'com_foobar');
JToolBarHelper::title(JText::_(strtoupper($option)) .
' – <small>' .
JText::_($subtitle_key) .
'</small>', $componentName);
JToolBarHelper::custom('savenew', 'save-new.png', 'save-new_f2.png', 'JTOOLBAR_SAVE_AND_NEW', false);
JToolBarHelper::cancel();
* Renders the toolbar for the component's Edit pages
// On frontend, buttons must be added specifically
* Removes all links from the link bar
* Get the link bar's link definitions
* Append a link to the link bar
* @param string $name The text of the link
* @param string|null $link The link to render; set to null to render a separator
* @param boolean $active True if it's an active link
* @param string|null $icon Icon class (used by some renderers, like the Bootstrap renderer)
* @param string|null $parent The parent element (referenced by name)) Thsi will create a dropdown list
public function appendLink($name, $link =
null, $active =
false, $icon =
null, $parent =
'')
$this->linkbar[$name] =
$linkDefinition;
$parentElement =
$linkDefinition;
$parentElement['link'] =
null;
$this->linkbar[$parent] =
$parentElement;
$parentElement['items'] =
array();
$parentElement =
$this->linkbar[$parent];
if (!array_key_exists('dropdown', $parentElement) &&
!empty($parentElement['link']))
$newSubElement =
$parentElement;
$parentElement['items'] =
array($newSubElement);
$parentElement['items'][] =
$linkDefinition;
$parentElement['dropdown'] =
true;
$this->linkbar[$parent] =
$parentElement;
* Prefixes (some people erroneously call this "prepend" – there is no such word) a link to the link bar
* @param string $name The text of the link
* @param string|null $link The link to render; set to null to render a separator
* @param boolean $active True if it's an active link
* @param string|null $icon Icon class (used by some renderers, like the Bootstrap renderer)
public function prefixLink($name, $link =
null, $active =
false, $icon =
null)
* Renders the submenu (toolbar links) for all detected views of this component
$activeView =
$this->input->getCmd('view', 'cpanel');
foreach ($views as $view)
$link =
'index.php?option=' .
$this->component .
'&view=' .
$view;
$active =
$view ==
$activeView;
* Automatically detects all views of the component
* @return array A list of all views, in the order to be displayed in the toolbar submenu
$searchPath =
$componentPaths['main'] .
'/views';
foreach ($allFolders as $folder)
// Do we have a 'skip.xml' file in there?
$files =
JFolder::files($searchPath .
'/' .
$view, '^skip\.xml$');
// Do we have extra information about this view? (ie. ordering)
$meta =
JFolder::files($searchPath .
'/' .
$view, '^metadata\.xml$');
// Not found, do we have it inside the plural one?
$meta =
JFolder::files($searchPath .
'/' .
$view, '^metadata\.xml$');
// Next place. It's ok since the index are 0-based and count is 1-based
$order =
count($to_order);
// If not using the metadata file, let's put the cpanel view on top
* Return the front-end toolbar rendering flag
* Return the front-end submenu rendering flag
* Render the toolbar from the configuration.
* @param array $toolbar The toolbar definition
private function renderFromConfig(array $toolbar)
foreach ($toolbar as $elementType =>
$elementAttributes)
$value = isset
($elementAttributes['value']) ?
$elementAttributes['value'] :
null;
$this->renderToolbarElement($elementType, $value, $elementAttributes);
* Render a toolbar element.
* @param string $type The element type.
* @param mixed $value The element value.
* @param array $attributes The element attributes.
* @throws InvalidArgumentException
private function renderToolbarElement($type, $value =
null, array $attributes =
array())
$icon = isset
($attributes['icon']) ?
$attributes['icon'] :
'generic.png';
$task = isset
($attributes['task']) ?
$attributes['task'] :
'';
$icon = isset
($attributes['icon']) ?
$attributes['icon'] :
'';
$iconOver = isset
($attributes['icon_over']) ?
$attributes['icon_over'] :
'';
$alt = isset
($attributes['alt']) ?
$attributes['alt'] :
'';
$listSelect = isset
($attributes['list_select']) ?
$url = isset
($attributes['url']) ?
$attributes['url'] :
'';
$update_editors = isset
($attributes['update_editors']) ?
if (!isset
($attributes['help']))
throw
new InvalidArgumentException(
'The help attribute is missing in the help button type.'
$ref =
$attributes['help'];
$override = isset
($attributes['override']) ?
$attributes['override'] :
null;
$component = isset
($attributes['component']) ?
$attributes['component'] :
null;
$alt = isset
($attributes['alt']) ?
$attributes['alt'] :
'JTOOLBAR_BACK';
$href = isset
($attributes['href']) ?
$attributes['href'] :
'javascript:history.back();';
$directory = isset
($attributes['directory']) ?
$attributes['directory'] :
'';
$alt = isset
($attributes['alt']) ?
$attributes['alt'] :
'JTOOLBAR_UPLOAD';
$task = isset
($attributes['task']) ?
$attributes['task'] :
'assign';
$alt = isset
($attributes['alt']) ?
$attributes['alt'] :
'JTOOLBAR_ASSIGN';
if ($this->perms->create)
$task = isset
($attributes['task']) ?
$attributes['task'] :
'add';
$alt = isset
($attributes['alt']) ?
$attributes['alt'] :
'JTOOLBAR_NEW';
$check = isset
($attributes['check']) ?
if ($this->perms->editstate)
$task = isset
($attributes['task']) ?
$attributes['task'] :
'publish';
$alt = isset
($attributes['alt']) ?
$attributes['alt'] :
'JTOOLBAR_PUBLISH';
$check = isset
($attributes['check']) ?
if ($this->perms->editstate)
$task = isset
($attributes['task']) ?
$attributes['task'] :
'publish';
$alt = isset
($attributes['alt']) ?
$attributes['alt'] :
'JTOOLBAR_PUBLISH';
if ($this->perms->editstate)
$task = isset
($attributes['task']) ?
$attributes['task'] :
'unpublish';
$alt = isset
($attributes['alt']) ?
$attributes['alt'] :
'JTOOLBAR_UNPUBLISH';
$check = isset
($attributes['check']) ?
if ($this->perms->editstate)
$task = isset
($attributes['task']) ?
$attributes['task'] :
'unpublish';
$alt = isset
($attributes['alt']) ?
$attributes['alt'] :
'JTOOLBAR_UNPUBLISH';
if ($this->perms->editstate)
$task = isset
($attributes['task']) ?
$attributes['task'] :
'archive';
$alt = isset
($attributes['alt']) ?
$attributes['alt'] :
'JTOOLBAR_ARCHIVE';
if ($this->perms->editstate)
$task = isset
($attributes['task']) ?
$attributes['task'] :
'unarchive';
$alt = isset
($attributes['alt']) ?
$attributes['alt'] :
'JTOOLBAR_UNARCHIVE';
$task = isset
($attributes['task']) ?
$attributes['task'] :
'edit';
$alt = isset
($attributes['alt']) ?
$attributes['alt'] :
'JTOOLBAR_EDIT';
$task = isset
($attributes['task']) ?
$attributes['task'] :
'edit_source';
$alt = isset
($attributes['alt']) ?
$attributes['alt'] :
'JTOOLBAR_EDIT_HTML';
$task = isset
($attributes['task']) ?
$attributes['task'] :
'edit_css';
$alt = isset
($attributes['alt']) ?
$attributes['alt'] :
'JTOOLBAR_EDIT_CSS';
$msg = isset
($attributes['msg']) ?
$attributes['msg'] :
'';
$task = isset
($attributes['task']) ?
$attributes['task'] :
'remove';
$alt = isset
($attributes['alt']) ?
$attributes['alt'] :
'JTOOLBAR_DELETE';
if ($this->perms->editstate)
$task = isset
($attributes['task']) ?
$attributes['task'] :
'remove';
$alt = isset
($attributes['alt']) ?
$attributes['alt'] :
'JTOOLBAR_TRASH';
$check = isset
($attributes['check']) ?
$task = isset
($attributes['task']) ?
$attributes['task'] :
'apply';
$alt = isset
($attributes['alt']) ?
$attributes['alt'] :
'JTOOLBAR_APPLY';
$task = isset
($attributes['task']) ?
$attributes['task'] :
'save';
$alt = isset
($attributes['alt']) ?
$attributes['alt'] :
'JTOOLBAR_SAVE';
$task = isset
($attributes['task']) ?
$attributes['task'] :
'save2new';
$alt = isset
($attributes['alt']) ?
$attributes['alt'] :
'JTOOLBAR_SAVE_AND_NEW';
$task = isset
($attributes['task']) ?
$attributes['task'] :
'save2copy';
$alt = isset
($attributes['alt']) ?
$attributes['alt'] :
'JTOOLBAR_SAVE_AS_COPY';
$task = isset
($attributes['task']) ?
$attributes['task'] :
'checkin';
$alt = isset
($attributes['alt']) ?
$attributes['alt'] :
'JTOOLBAR_CHECKIN';
$check = isset
($attributes['check']) ?
$task = isset
($attributes['task']) ?
$attributes['task'] :
'cancel';
$alt = isset
($attributes['alt']) ?
$attributes['alt'] :
'JTOOLBAR_CANCEL';
if (!isset
($attributes['component']))
throw
new InvalidArgumentException(
'The component attribute is missing in the preferences button type.'
$component =
$attributes['component'];
$height = isset
($attributes['height']) ?
$attributes['height'] :
'550';
$width = isset
($attributes['width']) ?
$attributes['width'] :
'875';
$alt = isset
($attributes['alt']) ?
$attributes['alt'] :
'JToolbar_Options';
$path = isset
($attributes['path']) ?
$attributes['path'] :
'';
throw
new InvalidArgumentException(sprintf('Unknown button type %s', $type));
Documentation generated on Tue, 19 Nov 2013 15:15:52 +0100 by phpDocumentor 1.4.3