- md5
- b4f4b8ca9d841ed30944023cc83714cc
- sha1
- 08e1aaf8e041caf4d734e47f21d627f905b6e201
- sha256
- 4acee51246c2782f62677dc745a212e8fe1f5f2a9a6115b8c359986f57136d39
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151
<?php
/**
* @package Joomla.Administrator
* @subpackage com_menus
*
* @copyright (C) 2009 Open Source Matters, Inc. <https://www.joomla.org>
* @license GNU General Public License version 2 or later; see LICENSE.txt
*/
namespace Joomla\Component\Menus\Administrator\View\Menu;
use Joomla\CMS\Factory;
use Joomla\CMS\Helper\ContentHelper;
use Joomla\CMS\Language\Text;
use Joomla\CMS\MVC\View\GenericDataException;
use Joomla\CMS\MVC\View\HtmlView as BaseHtmlView;
use Joomla\CMS\Toolbar\Toolbar;
use Joomla\CMS\Toolbar\ToolbarHelper;
use Joomla\Component\Menus\Administrator\Model\MenuModel;
// phpcs:disable PSR1.Files.SideEffects
\defined('_JEXEC') or die;
// phpcs:enable PSR1.Files.SideEffects
/**
* The HTML Menus Menu Item View.
*
* @since 1.6
*/
class HtmlView extends BaseHtmlView
{
/**
* The Form object
*
* @var \Joomla\CMS\Form\Form
*/
protected $form;
/**
* The active item
*
* @var object
*/
protected $item;
/**
* The model state
*
* @var \Joomla\Registry\Registry
*/
protected $state;
/**
* The actions the user is authorised to perform
*
* @var \Joomla\Registry\Registry
*/
protected $canDo;
/**
* Display the view
*
* @param string $tpl The name of the template file to parse; automatically searches through the template paths.
*
* @return void
*
* @since 1.6
*/
public function display($tpl = null)
{
/** @var MenuModel $model */
$model = $this->getModel();
$this->form = $model->getForm();
$this->item = $model->getItem();
$this->state = $model->getState();
$this->canDo = ContentHelper::getActions('com_menus', 'menu', $this->item->id);
// Check for errors.
if (\count($errors = $model->getErrors())) {
throw new GenericDataException(implode("\n", $errors), 500);
}
// Add form control fields
$this->form->addControlField('task', '');
parent::display($tpl);
$this->addToolbar();
}
/**
* Add the page title and toolbar.
*
* @return void
*
* @since 1.6
*/
protected function addToolbar()
{
$input = Factory::getApplication()->getInput();
$input->set('hidemainmenu', true);
$isNew = ($this->item->id == 0);
$toolbar = $this->getDocument()->getToolbar();
ToolbarHelper::title(Text::_($isNew ? 'COM_MENUS_VIEW_NEW_MENU_TITLE' : 'COM_MENUS_VIEW_EDIT_MENU_TITLE'), 'list menu');
// If a new item, can save the item. Allow users with edit permissions to apply changes to prevent returning to grid.
if ($isNew && $this->canDo->get('core.create') && $this->canDo->get('core.edit')) {
$toolbar->apply('menu.apply');
}
// If user can edit, can save the item.
if (!$isNew && $this->canDo->get('core.edit')) {
$toolbar->apply('menu.apply');
}
$saveGroup = $toolbar->dropdownButton('save-group');
$canDo = $this->canDo;
$saveGroup->configure(
function (Toolbar $childBar) use ($isNew, $canDo) {
// If a new item, can save the item. Allow users with edit permissions to apply changes to prevent returning to grid.
if ($isNew && $canDo->get('core.create')) {
$childBar->save('menu.save');
}
// If user can edit, can save the item.
if (!$isNew && $canDo->get('core.edit')) {
$childBar->save('menu.save');
}
// If the user can create new items, allow them to see Save & New
if ($canDo->get('core.create')) {
$childBar->save2new('menu.save2new');
}
}
);
if ($isNew) {
$toolbar->cancel('menu.cancel', 'JTOOLBAR_CANCEL');
} else {
$toolbar->cancel('menu.cancel');
}
$toolbar->divider();
$toolbar->help('Menus:_Edit');
}
}
The same content is in 68 releases, Joomla 5.3.0-alpha1 to 6.1.0-alpha2. See them all, or every version of this file.