diff --git a/src/administrator/components/com_weblinks/src/View/Weblink/HtmlView.php b/src/administrator/components/com_weblinks/src/View/Weblink/HtmlView.php index ba84715..d5264d1 100644 --- a/src/administrator/components/com_weblinks/src/View/Weblink/HtmlView.php +++ b/src/administrator/components/com_weblinks/src/View/Weblink/HtmlView.php @@ -11,6 +11,7 @@ namespace Joomla\Component\Weblinks\Administrator\View\Weblink; defined('_JEXEC') or die; +use Joomla\CMS\Component\ComponentHelper; use Joomla\CMS\Factory; use Joomla\CMS\Helper\ContentHelper; use Joomla\CMS\Language\Text; @@ -93,9 +94,10 @@ class HtmlView extends BaseHtmlView */ protected function addToolbar() { - Factory::getApplication()->input->set('hidemainmenu', true); + $app = Factory::getApplication(); + $app->input->set('hidemainmenu', true); - $user = Factory::getUser(); + $user = $app->getIdentity(); $isNew = ($this->item->id == 0); $checkedOut = !($this->item->checked_out == 0 || $this->item->checked_out == $user->get('id')); @@ -104,36 +106,63 @@ class HtmlView extends BaseHtmlView ToolbarHelper::title($isNew ? Text::_('COM_WEBLINKS_MANAGER_WEBLINK_NEW') : Text::_('COM_WEBLINKS_MANAGER_WEBLINK_EDIT'), 'link weblinks'); - // If not checked out, can save the item. - if (!$checkedOut && ($canDo->get('core.edit')||(count($user->getAuthorisedCategories('com_weblinks', 'core.create'))))) - { - ToolbarHelper::apply('weblink.apply'); - ToolbarHelper::save('weblink.save'); - } - if (!$checkedOut && (count($user->getAuthorisedCategories('com_weblinks', 'core.create')))) - { - ToolbarHelper::save2new('weblink.save2new'); - } - // If an existing item, can save to a copy. - if (!$isNew && (count($user->getAuthorisedCategories('com_weblinks', 'core.create')) > 0)) - { - ToolbarHelper::save2copy('weblink.save2copy'); - } - if (empty($this->item->id)) + // Build the actions for new and existing records. + if ($isNew) { + // For new records, check the create permission. + if (count($user->getAuthorisedCategories('com_weblinks', 'core.create')) > 0) + { + ToolbarHelper::apply('weblink.apply'); + + ToolbarHelper::saveGroup( + [ + ['save', 'weblink.save'], + ['save2new', 'weblink.save2new'] + ], + 'btn-success' + ); + } + ToolbarHelper::cancel('weblink.cancel'); } else { - if ($this->state->params->get('save_history', 0) && $user->authorise('core.edit')) + // Since it's an existing record, check the edit permission, or fall back to edit own if the owner. + $itemEditable = $canDo->get('core.edit') || ($canDo->get('core.edit.own') && $this->item->created_by == $user->id); + + $toolbarButtons = []; + + // Can't save the record if it's checked out and editable + if (!$checkedOut && $itemEditable) + { + ToolbarHelper::apply('weblink.apply'); + + $toolbarButtons[] = ['save', 'weblink.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', 'weblink.save2new']; + } + } + + // If checked out, we can still save + if ($canDo->get('core.create')) + { + $toolbarButtons[] = ['save2copy', 'weblink.save2copy']; + } + + ToolbarHelper::saveGroup( + $toolbarButtons, + 'btn-success' + ); + + ToolbarHelper::cancel('weblink.cancel', 'JTOOLBAR_CLOSE'); + + if (ComponentHelper::isEnabled('com_contenthistory') && $this->state->params->get('save_history', 0) && $itemEditable) { ToolbarHelper::versions('com_weblinks.weblink', $this->item->id); } - - ToolbarHelper::cancel('weblink.cancel', 'JTOOLBAR_CLOSE'); } - - ToolbarHelper::divider(); - ToolbarHelper::help('JHELP_COMPONENTS_WEBLINKS_LINKS_EDIT'); } } diff --git a/src/administrator/components/com_weblinks/src/View/Weblinks/HtmlView.php b/src/administrator/components/com_weblinks/src/View/Weblinks/HtmlView.php index 2fff3c8..f3aaace 100644 --- a/src/administrator/components/com_weblinks/src/View/Weblinks/HtmlView.php +++ b/src/administrator/components/com_weblinks/src/View/Weblinks/HtmlView.php @@ -13,9 +13,6 @@ defined('_JEXEC') or die; use Joomla\CMS\Factory; use Joomla\CMS\Helper\ContentHelper; -use Joomla\CMS\HTML\HTMLHelper; -use Joomla\CMS\Language\Text; -use Joomla\CMS\Layout\FileLayout; use Joomla\CMS\MVC\View\GenericDataException; use Joomla\CMS\MVC\View\HtmlView as BaseHtmlView; use Joomla\CMS\Toolbar\Toolbar; @@ -121,55 +118,64 @@ class HtmlView extends BaseHtmlView */ protected function addToolbar() { - $state = $this->get('State'); - $canDo = ContentHelper::getActions('com_weblinks', 'category', $state->get('filter.category_id')); - $user = Factory::getUser(); + $canDo = ContentHelper::getActions('com_weblinks', 'category', $this->state->get('filter.category_id')); + $user = Factory::getApplication()->getIdentity(); // Get the toolbar object instance - $bar = Toolbar::getInstance('toolbar'); + $toolbar = Toolbar::getInstance('toolbar'); ToolbarHelper::title(\JText::_('COM_WEBLINKS_MANAGER_WEBLINKS'), 'link weblinks'); - if (count($user->getAuthorisedCategories('com_weblinks', 'core.create')) > 0) + if ($canDo->get('core.create') || \count($user->getAuthorisedCategories('com_weblinks', 'core.create')) > 0) { ToolbarHelper::addNew('weblink.add'); } - if ($canDo->get('core.edit') || $canDo->get('core.edit.own')) - { - ToolbarHelper::editList('weblink.edit'); - } - if ($canDo->get('core.edit.state')) { - ToolbarHelper::publish('weblinks.publish', 'JTOOLBAR_PUBLISH', true); - ToolbarHelper::unpublish('weblinks.unpublish', 'JTOOLBAR_UNPUBLISH', true); + $dropdown = $toolbar->dropdownButton('status-group') + ->text('JTOOLBAR_CHANGE_STATUS') + ->toggleSplit(false) + ->icon('icon-ellipsis-h') + ->buttonClass('btn btn-action') + ->listCheck(true); - ToolbarHelper::archiveList('weblinks.archive'); - ToolbarHelper::checkin('weblinks.checkin'); + $childBar = $dropdown->getChildToolbar(); + + $childBar->publish('weblinks.publish')->listCheck(true); + + $childBar->unpublish('weblinks.unpublish')->listCheck(true); + + $childBar->archive('weblinks.archive')->listCheck(true); + + if ($user->authorise('core.admin')) + { + $childBar->checkin('weblinks.checkin')->listCheck(true); + } + + if ($this->state->get('filter.published') != -2) + { + $childBar->trash('weblinks.trash')->listCheck(true); + } + + // Add a batch button + if ($user->authorise('core.create', 'com_weblinks') + && $user->authorise('core.edit', 'com_weblinks') + && $user->authorise('core.edit.state', 'com_weblinks')) + { + $childBar->popupButton('batch') + ->text('JTOOLBAR_BATCH') + ->selector('collapseModal') + ->listCheck(true); + } } - if ($state->get('filter.published') == -2 && $canDo->get('core.delete')) + if ($this->state->get('filter.published') == -2 && $canDo->get('core.delete')) { - ToolbarHelper::deleteList('JGLOBAL_CONFIRM_DELETE', 'weblinks.delete', 'JTOOLBAR_EMPTY_TRASH'); - } - elseif ($canDo->get('core.edit.state')) - { - ToolbarHelper::trash('weblinks.trash'); - } - - // Add a batch button - if ($user->authorise('core.create', 'com_weblinks') && $user->authorise('core.edit', 'com_weblinks') - && $user->authorise('core.edit.state', 'com_weblinks')) - { - HTMLHelper::_('bootstrap.renderModal', 'collapseModal'); - $title = Text::_('JTOOLBAR_BATCH'); - - // Instantiate a new JLayoutFile instance and render the batch button - $layout = new FileLayout('joomla.toolbar.batch'); - - $dhtml = $layout->render(array('title' => $title)); - $bar->appendButton('Custom', $dhtml, 'batch'); + $toolbar->delete('contacts.delete') + ->text('JTOOLBAR_EMPTY_TRASH') + ->message('JGLOBAL_CONFIRM_DELETE') + ->listCheck(true); } if ($user->authorise('core.admin', 'com_weblinks') || $user->authorise('core.options', 'com_weblinks'))