[ Index ] |
PHP Cross Reference of Joomla 4.2.2 documentation |
[Summary view] [Print] [Text view]
1 <?php 2 3 /** 4 * @package Joomla.Administrator 5 * @subpackage com_menus 6 * 7 * @copyright (C) 2009 Open Source Matters, Inc. <https://www.joomla.org> 8 * @license GNU General Public License version 2 or later; see LICENSE.txt 9 */ 10 11 namespace Joomla\Component\Menus\Administrator\View\Item; 12 13 use Joomla\CMS\Component\ComponentHelper; 14 use Joomla\CMS\Factory; 15 use Joomla\CMS\Helper\ContentHelper; 16 use Joomla\CMS\Language\Associations; 17 use Joomla\CMS\Language\Text; 18 use Joomla\CMS\MVC\View\GenericDataException; 19 use Joomla\CMS\MVC\View\HtmlView as BaseHtmlView; 20 use Joomla\CMS\Object\CMSObject; 21 use Joomla\CMS\Toolbar\ToolbarHelper; 22 23 // phpcs:disable PSR1.Files.SideEffects 24 \defined('_JEXEC') or die; 25 // phpcs:enable PSR1.Files.SideEffects 26 27 /** 28 * The HTML Menus Menu Item View. 29 * 30 * @since 1.6 31 */ 32 class HtmlView extends BaseHtmlView 33 { 34 /** 35 * The Form object 36 * 37 * @var \Joomla\CMS\Form\Form 38 */ 39 protected $form; 40 41 /** 42 * The active item 43 * 44 * @var CMSObject 45 */ 46 protected $item; 47 48 /** 49 * @var mixed 50 */ 51 protected $modules; 52 53 /** 54 * The model state 55 * 56 * @var CMSObject 57 */ 58 protected $state; 59 60 /** 61 * The actions the user is authorised to perform 62 * 63 * @var CMSObject 64 * @since 3.7.0 65 */ 66 protected $canDo; 67 68 /** 69 * A list of view levels containing the id and title of the view level 70 * 71 * @var \stdClass[] 72 * @since 4.0.0 73 */ 74 protected $levels; 75 76 /** 77 * Display the view 78 * 79 * @param string $tpl The name of the template file to parse; automatically searches through the template paths. 80 * 81 * @return void 82 * 83 * @since 1.6 84 */ 85 public function display($tpl = null) 86 { 87 $this->state = $this->get('State'); 88 $this->form = $this->get('Form'); 89 $this->item = $this->get('Item'); 90 $this->modules = $this->get('Modules'); 91 $this->levels = $this->get('ViewLevels'); 92 $this->canDo = ContentHelper::getActions('com_menus', 'menu', (int) $this->state->get('item.menutypeid')); 93 94 // Check if we're allowed to edit this item 95 // No need to check for create, because then the moduletype select is empty 96 if (!empty($this->item->id) && !$this->canDo->get('core.edit')) { 97 throw new \Exception(Text::_('JERROR_ALERTNOAUTHOR'), 403); 98 } 99 100 // Check for errors. 101 if (count($errors = $this->get('Errors'))) { 102 throw new GenericDataException(implode("\n", $errors), 500); 103 } 104 105 // If we are forcing a language in modal (used for associations). 106 if ($this->getLayout() === 'modal' && $forcedLanguage = Factory::getApplication()->input->get('forcedLanguage', '', 'cmd')) { 107 // Set the language field to the forcedLanguage and disable changing it. 108 $this->form->setValue('language', null, $forcedLanguage); 109 $this->form->setFieldAttribute('language', 'readonly', 'true'); 110 111 // Only allow to select categories with All language or with the forced language. 112 $this->form->setFieldAttribute('parent_id', 'language', '*,' . $forcedLanguage); 113 } 114 115 parent::display($tpl); 116 $this->addToolbar(); 117 } 118 119 /** 120 * Add the page title and toolbar. 121 * 122 * @return void 123 * 124 * @since 1.6 125 */ 126 protected function addToolbar() 127 { 128 $input = Factory::getApplication()->input; 129 $input->set('hidemainmenu', true); 130 131 $user = $this->getCurrentUser(); 132 $isNew = ($this->item->id == 0); 133 $checkedOut = !(is_null($this->item->checked_out) || $this->item->checked_out == $user->get('id')); 134 $canDo = $this->canDo; 135 $clientId = $this->state->get('item.client_id', 0); 136 137 ToolbarHelper::title(Text::_($isNew ? 'COM_MENUS_VIEW_NEW_ITEM_TITLE' : 'COM_MENUS_VIEW_EDIT_ITEM_TITLE'), 'list menu-add'); 138 139 $toolbarButtons = []; 140 141 // If a new item, can save the item. Allow users with edit permissions to apply changes to prevent returning to grid. 142 if ($isNew && $canDo->get('core.create')) { 143 if ($canDo->get('core.edit')) { 144 ToolbarHelper::apply('item.apply'); 145 } 146 147 $toolbarButtons[] = ['save', 'item.save']; 148 } 149 150 // If not checked out, can save the item. 151 if (!$isNew && !$checkedOut && $canDo->get('core.edit')) { 152 ToolbarHelper::apply('item.apply'); 153 154 $toolbarButtons[] = ['save', 'item.save']; 155 } 156 157 // If the user can create new items, allow them to see Save & New 158 if ($canDo->get('core.create')) { 159 $toolbarButtons[] = ['save2new', 'item.save2new']; 160 } 161 162 // If an existing item, can save to a copy only if we have create rights. 163 if (!$isNew && $canDo->get('core.create')) { 164 $toolbarButtons[] = ['save2copy', 'item.save2copy']; 165 } 166 167 ToolbarHelper::saveGroup( 168 $toolbarButtons, 169 'btn-success' 170 ); 171 172 if (!$isNew && Associations::isEnabled() && ComponentHelper::isEnabled('com_associations') && $clientId != 1) { 173 ToolbarHelper::custom('item.editAssociations', 'contract', '', 'JTOOLBAR_ASSOCIATIONS', false, false); 174 } 175 176 if ($isNew) { 177 ToolbarHelper::cancel('item.cancel'); 178 } else { 179 ToolbarHelper::cancel('item.cancel', 'JTOOLBAR_CLOSE'); 180 } 181 182 ToolbarHelper::divider(); 183 184 // Get the help information for the menu item. 185 $lang = Factory::getLanguage(); 186 187 $help = $this->get('Help'); 188 189 if ($lang->hasKey($help->url)) { 190 $debug = $lang->setDebug(false); 191 $url = Text::_($help->url); 192 $lang->setDebug($debug); 193 } else { 194 $url = $help->url; 195 } 196 197 ToolbarHelper::help($help->key, $help->local, $url); 198 } 199 }
title
Description
Body
title
Description
Body
title
Description
Body
title
Body
Generated: Wed Sep 7 05:41:13 2022 | Chilli.vc Blog - For Webmaster,Blog-Writer,System Admin and Domainer |