Back to ListView class

Method addToolbar

protected void
addToolbar
()
Add the page title and toolbar.
Returns
  • void
Since
  • 1.6
Class: ListView
Project: Joomla

Method addToolbar - Source code

/**
 * Add the page title and toolbar.
 *
 * @return  void
 *
 * @since   1.6
 */
protected function addToolbar()
{
    $canDo = $this->canDo;
    $user = Factory::getUser();
    // Get the toolbar object instance
    $bar = Toolbar::getInstance('toolbar');
    $viewName = $this->getName();
    $singularViewName = \Joomla\String\Inflector::getInstance()->toSingular($viewName);
    ToolbarHelper::title(Text::_($this->toolbarTitle), $this->toolbarIcon);
    if ($canDo->get('core.create')) {
        ToolbarHelper::addNew($singularViewName . '.add');
    }
    if ($canDo->get('core.edit') || $canDo->get('core.edit.own')) {
        ToolbarHelper::editList($singularViewName . '.edit');
    }
    if ($canDo->get('core.edit.state')) {
        ToolbarHelper::publish($viewName . '.publish', 'JTOOLBAR_PUBLISH', true);
        ToolbarHelper::unpublish($viewName . '.unpublish', 'JTOOLBAR_UNPUBLISH', true);
        if (isset($this->items[0]->featured)) {
            ToolbarHelper::custom($viewName . '.featured', 'featured', '', 'JFEATURE', true);
            ToolbarHelper::custom($viewName . '.unfeatured', 'unfeatured', '', 'JUNFEATURE', true);
        }
        ToolbarHelper::archiveList($viewName . '.archive');
        ToolbarHelper::checkin($viewName . '.checkin');
    }
    // Add a batch button
    if ($this->supportsBatch && $user->authorise('core.create', $this->option) && $user->authorise('core.edit', $this->option) && $user->authorise('core.edit.state', $this->option)) {
        $title = Text::_('JTOOLBAR_BATCH');
        // Instantiate a new LayoutFile instance and render the popup button
        $layout = new FileLayout('joomla.toolbar.popup');
        $dhtml = $layout->render(array('title' => $title));
        $bar->appendButton('Custom', $dhtml, 'batch');
    }
    if ($this->state->get('filter.published') == -2 && $canDo->get('core.delete')) {
        ToolbarHelper::deleteList('JGLOBAL_CONFIRM_DELETE', $viewName . '.delete', 'JTOOLBAR_EMPTY_TRASH');
    } elseif ($canDo->get('core.edit.state')) {
        ToolbarHelper::trash($viewName . '.trash');
    }
    if ($user->authorise('core.admin', $this->option) || $user->authorise('core.options', $this->option)) {
        ToolbarHelper::preferences($this->option);
    }
    if ($this->helpLink) {
        ToolbarHelper::help($this->helpLink);
    }
}