[ 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_workflow 6 * 7 * @copyright (C) 2018 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\Workflow\Administrator\View\Transition; 12 13 use Joomla\CMS\Factory; 14 use Joomla\CMS\Language\Text; 15 use Joomla\CMS\MVC\View\GenericDataException; 16 use Joomla\CMS\MVC\View\HtmlView as BaseHtmlView; 17 use Joomla\CMS\Toolbar\ToolbarHelper; 18 use Joomla\Component\Workflow\Administrator\Helper\StageHelper; 19 20 // phpcs:disable PSR1.Files.SideEffects 21 \defined('_JEXEC') or die; 22 // phpcs:enable PSR1.Files.SideEffects 23 24 /** 25 * View class to add or edit a transition of a workflow 26 * 27 * @since 4.0.0 28 */ 29 class HtmlView extends BaseHtmlView 30 { 31 /** 32 * The model state 33 * 34 * @var object 35 * @since 4.0.0 36 */ 37 protected $state; 38 39 /** 40 * Form object to generate fields 41 * 42 * @var \Joomla\CMS\Form\Form 43 * 44 * @since 4.0.0 45 */ 46 protected $form; 47 48 /** 49 * Items array 50 * 51 * @var object 52 * @since 4.0.0 53 */ 54 protected $item; 55 56 /** 57 * That is object of Application 58 * 59 * @var \Joomla\CMS\Application\CMSApplication 60 * @since 4.0.0 61 */ 62 protected $app; 63 64 /** 65 * The application input object. 66 * 67 * @var \Joomla\CMS\Input\Input 68 * @since 4.0.0 69 */ 70 protected $input; 71 72 /** 73 * The ID of current workflow 74 * 75 * @var integer 76 * @since 4.0.0 77 */ 78 protected $workflowID; 79 80 /** 81 * The name of current extension 82 * 83 * @var string 84 * @since 4.0.0 85 */ 86 protected $extension; 87 88 /** 89 * The section of the current extension 90 * 91 * @var string 92 * @since 4.0.0 93 */ 94 protected $section; 95 96 /** 97 * Display item view 98 * 99 * @param string $tpl The name of the template file to parse; automatically searches through the template paths. 100 * 101 * @return void 102 * 103 * @since 4.0.0 104 */ 105 public function display($tpl = null) 106 { 107 $this->app = Factory::getApplication(); 108 $this->input = $this->app->input; 109 110 // Get the Data 111 $this->state = $this->get('State'); 112 $this->form = $this->get('Form'); 113 $this->item = $this->get('Item'); 114 115 // Check for errors. 116 if (count($errors = $this->get('Errors'))) { 117 throw new GenericDataException(implode("\n", $errors), 500); 118 } 119 120 $extension = $this->state->get('filter.extension'); 121 122 $parts = explode('.', $extension); 123 124 $this->extension = array_shift($parts); 125 126 if (!empty($parts)) { 127 $this->section = array_shift($parts); 128 } 129 130 // Get the ID of workflow 131 $this->workflowID = $this->input->getCmd("workflow_id"); 132 133 // Set the toolbar 134 $this->addToolbar(); 135 136 // Display the template 137 parent::display($tpl); 138 } 139 140 /** 141 * Add the page title and toolbar. 142 * 143 * @return void 144 * 145 * @since 4.0.0 146 */ 147 protected function addToolbar() 148 { 149 Factory::getApplication()->input->set('hidemainmenu', true); 150 151 $user = $this->getCurrentUser(); 152 $userId = $user->id; 153 $isNew = empty($this->item->id); 154 155 $canDo = StageHelper::getActions($this->extension, 'transition', $this->item->id); 156 157 ToolbarHelper::title(empty($this->item->id) ? Text::_('COM_WORKFLOW_TRANSITION_ADD') : Text::_('COM_WORKFLOW_TRANSITION_EDIT'), 'address'); 158 159 $toolbarButtons = []; 160 161 $canCreate = $canDo->get('core.create'); 162 163 if ($isNew) { 164 // For new records, check the create permission. 165 if ($canCreate) { 166 ToolbarHelper::apply('transition.apply'); 167 $toolbarButtons = [['save', 'transition.save'], ['save2new', 'transition.save2new']]; 168 } 169 170 ToolbarHelper::saveGroup( 171 $toolbarButtons, 172 'btn-success' 173 ); 174 175 ToolbarHelper::cancel( 176 'transition.cancel' 177 ); 178 } else { 179 // Since it's an existing record, check the edit permission, or fall back to edit own if the owner. 180 $itemEditable = $canDo->get('core.edit') || ($canDo->get('core.edit.own') && $this->item->created_by == $userId); 181 182 if ($itemEditable) { 183 ToolbarHelper::apply('transition.apply'); 184 $toolbarButtons[] = ['save', 'transition.save']; 185 186 // We can save this record, but check the create permission to see if we can return to make a new one. 187 if ($canCreate) { 188 $toolbarButtons[] = ['save2new', 'transition.save2new']; 189 $toolbarButtons[] = ['save2copy', 'transition.save2copy']; 190 } 191 } 192 193 if (count($toolbarButtons) > 1) { 194 ToolbarHelper::saveGroup( 195 $toolbarButtons, 196 'btn-success' 197 ); 198 } else { 199 ToolbarHelper::save('transition.save'); 200 } 201 202 ToolbarHelper::cancel( 203 'transition.cancel', 204 'JTOOLBAR_CLOSE' 205 ); 206 } 207 208 ToolbarHelper::divider(); 209 } 210 }
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 |