[ 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_content 6 * 7 * @copyright (C) 2008 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\Content\Administrator\View\Article; 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\Plugin\PluginHelper; 21 use Joomla\CMS\Router\Route; 22 use Joomla\CMS\Toolbar\Toolbar; 23 use Joomla\CMS\Toolbar\ToolbarHelper; 24 use Joomla\Component\Content\Site\Helper\RouteHelper; 25 26 // phpcs:disable PSR1.Files.SideEffects 27 \defined('_JEXEC') or die; 28 // phpcs:enable PSR1.Files.SideEffects 29 30 /** 31 * View to edit an article. 32 * 33 * @since 1.6 34 */ 35 class HtmlView extends BaseHtmlView 36 { 37 /** 38 * The \JForm object 39 * 40 * @var \Joomla\CMS\Form\Form 41 */ 42 protected $form; 43 44 /** 45 * The active item 46 * 47 * @var object 48 */ 49 protected $item; 50 51 /** 52 * The model state 53 * 54 * @var object 55 */ 56 protected $state; 57 58 /** 59 * The actions the user is authorised to perform 60 * 61 * @var \Joomla\CMS\Object\CMSObject 62 */ 63 protected $canDo; 64 65 /** 66 * Pagebreak TOC alias 67 * 68 * @var string 69 */ 70 protected $eName; 71 72 /** 73 * Execute and display a template script. 74 * 75 * @param string $tpl The name of the template file to parse; automatically searches through the template paths. 76 * 77 * @return void 78 * 79 * @since 1.6 80 * 81 * @throws \Exception 82 */ 83 public function display($tpl = null) 84 { 85 if ($this->getLayout() == 'pagebreak') { 86 parent::display($tpl); 87 88 return; 89 } 90 91 $this->form = $this->get('Form'); 92 $this->item = $this->get('Item'); 93 $this->state = $this->get('State'); 94 $this->canDo = ContentHelper::getActions('com_content', 'article', $this->item->id); 95 96 // Check for errors. 97 if (count($errors = $this->get('Errors'))) { 98 throw new GenericDataException(implode("\n", $errors), 500); 99 } 100 101 // If we are forcing a language in modal (used for associations). 102 if ($this->getLayout() === 'modal' && $forcedLanguage = Factory::getApplication()->input->get('forcedLanguage', '', 'cmd')) { 103 // Set the language field to the forcedLanguage and disable changing it. 104 $this->form->setValue('language', null, $forcedLanguage); 105 $this->form->setFieldAttribute('language', 'readonly', 'true'); 106 107 // Only allow to select categories with All language or with the forced language. 108 $this->form->setFieldAttribute('catid', 'language', '*,' . $forcedLanguage); 109 110 // Only allow to select tags with All language or with the forced language. 111 $this->form->setFieldAttribute('tags', 'language', '*,' . $forcedLanguage); 112 } 113 114 $this->addToolbar(); 115 116 parent::display($tpl); 117 } 118 119 /** 120 * Add the page title and toolbar. 121 * 122 * @return void 123 * 124 * @since 1.6 125 * 126 * @throws \Exception 127 */ 128 protected function addToolbar() 129 { 130 Factory::getApplication()->input->set('hidemainmenu', true); 131 $user = $this->getCurrentUser(); 132 $userId = $user->id; 133 $isNew = ($this->item->id == 0); 134 $checkedOut = !(is_null($this->item->checked_out) || $this->item->checked_out == $userId); 135 136 // Built the actions for new and existing records. 137 $canDo = $this->canDo; 138 139 $toolbar = Toolbar::getInstance(); 140 141 ToolbarHelper::title( 142 Text::_('COM_CONTENT_PAGE_' . ($checkedOut ? 'VIEW_ARTICLE' : ($isNew ? 'ADD_ARTICLE' : 'EDIT_ARTICLE'))), 143 'pencil-alt article-add' 144 ); 145 146 // For new records, check the create permission. 147 if ($isNew && (count($user->getAuthorisedCategories('com_content', 'core.create')) > 0)) { 148 $toolbar->apply('article.apply'); 149 150 $saveGroup = $toolbar->dropdownButton('save-group'); 151 152 $saveGroup->configure( 153 function (Toolbar $childBar) use ($user) { 154 $childBar->save('article.save'); 155 156 if ($user->authorise('core.create', 'com_menus.menu')) { 157 $childBar->save('article.save2menu', 'JTOOLBAR_SAVE_TO_MENU'); 158 } 159 160 $childBar->save2new('article.save2new'); 161 } 162 ); 163 164 $toolbar->cancel('article.cancel', 'JTOOLBAR_CANCEL'); 165 } else { 166 // Since it's an existing record, check the edit permission, or fall back to edit own if the owner. 167 $itemEditable = $canDo->get('core.edit') || ($canDo->get('core.edit.own') && $this->item->created_by == $userId); 168 169 if (!$checkedOut && $itemEditable) { 170 $toolbar->apply('article.apply'); 171 } 172 173 $saveGroup = $toolbar->dropdownButton('save-group'); 174 175 $saveGroup->configure( 176 function (Toolbar $childBar) use ($checkedOut, $itemEditable, $canDo, $user) { 177 // Can't save the record if it's checked out and editable 178 if (!$checkedOut && $itemEditable) { 179 $childBar->save('article.save'); 180 181 // We can save this record, but check the create permission to see if we can return to make a new one. 182 if ($canDo->get('core.create')) { 183 $childBar->save2new('article.save2new'); 184 } 185 } 186 187 // If checked out, we can still save2menu 188 if ($user->authorise('core.create', 'com_menus.menu')) { 189 $childBar->save('article.save2menu', 'JTOOLBAR_SAVE_TO_MENU'); 190 } 191 192 // If checked out, we can still save 193 if ($canDo->get('core.create')) { 194 $childBar->save2copy('article.save2copy'); 195 } 196 } 197 ); 198 199 $toolbar->cancel('article.cancel', 'JTOOLBAR_CLOSE'); 200 201 if (!$isNew) { 202 if (ComponentHelper::isEnabled('com_contenthistory') && $this->state->params->get('save_history', 0) && $itemEditable) { 203 $toolbar->versions('com_content.article', $this->item->id); 204 } 205 206 $url = RouteHelper::getArticleRoute($this->item->id . ':' . $this->item->alias, $this->item->catid, $this->item->language); 207 208 $toolbar->preview(Route::link('site', $url, true), 'JGLOBAL_PREVIEW') 209 ->bodyHeight(80) 210 ->modalWidth(90); 211 212 if (PluginHelper::isEnabled('system', 'jooa11y')) { 213 $toolbar->jooa11y(Route::link('site', $url . '&jooa11y=1', true), 'JGLOBAL_JOOA11Y') 214 ->bodyHeight(80) 215 ->modalWidth(90); 216 } 217 218 if (Associations::isEnabled() && ComponentHelper::isEnabled('com_associations')) { 219 $toolbar->standardButton('contract') 220 ->text('JTOOLBAR_ASSOCIATIONS') 221 ->task('article.editAssociations'); 222 } 223 } 224 } 225 226 $toolbar->divider(); 227 228 ToolbarHelper::inlinehelp(); 229 230 $toolbar->help('Articles:_Edit'); 231 } 232 }
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 |