/**
* Add the page title and toolbar.
*
* @return void
*
* @since 1.6
*/
protected function addToolbar()
{
Factory::getApplication()->input->set('hidemainmenu', true);
$user = Factory::getUser();
$userId = $user->id;
$isNew = $this->item->id == 0;
$viewName = $this->getName();
$checkedOut = $this->getModel()->isCheckedOut($this->item);
$canDo = $this->canDo;
ToolbarHelper::title($this->toolbarTitle, $this->toolbarIcon);
// For new records, check the create permission.
if ($isNew && $canDo->get('core.create')) {
ToolbarHelper::saveGroup([['apply', $viewName . '.apply'], ['save', $viewName . '.save'], ['save2new', $viewName . '.save2new']], 'btn-success');
ToolbarHelper::cancel($viewName . '.cancel');
} else {
// Since it's an existing record, check the edit permission, or fall back to edit own if the owner.
if (property_exists($this->item, 'created_by')) {
$itemEditable = $canDo->get('core.edit') || $canDo->get('core.edit.own') && $this->item->created_by == $userId;
} else {
$itemEditable = $canDo->get('core.edit');
}
$toolbarButtons = [];
// Can't save the record if it's checked out and editable
if (!$checkedOut && $itemEditable) {
$toolbarButtons[] = ['apply', $viewName . '.apply'];
$toolbarButtons[] = ['save', $viewName . '.save'];
// We can save this record, but check the create permission to see if we can return to make a new one.
if ($canDo->get('core.create')) {
$toolbarButtons[] = ['save2new', $viewName . '.save2new'];
}
}
// If checked out, we can still save
if ($canDo->get('core.create')) {
$toolbarButtons[] = ['save2copy', $viewName . '.save2copy'];
}
ToolbarHelper::saveGroup($toolbarButtons, 'btn-success');
if (ComponentHelper::isEnabled('com_contenthistory') && $this->state->params->get('save_history', 0) && $itemEditable) {
ToolbarHelper::versions($this->option . '.' . $viewName, $this->item->id);
}
if (!$isNew && $this->previewLink) {
ToolbarHelper::preview($this->previewLink, Text::_('JGLOBAL_PREVIEW'), 'eye', 80, 90);
}
ToolbarHelper::cancel($viewName . '.cancel', 'JTOOLBAR_CLOSE');
}
ToolbarHelper::divider();
if ($this->helpLink) {
ToolbarHelper::help($this->helpLink);
}
}