[ 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_fields 6 * 7 * @copyright (C) 2016 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\Fields\Administrator\View\Group; 12 13 use Joomla\CMS\Factory; 14 use Joomla\CMS\Filesystem\Path; 15 use Joomla\CMS\Helper\ContentHelper; 16 use Joomla\CMS\Language\Text; 17 use Joomla\CMS\MVC\View\GenericDataException; 18 use Joomla\CMS\MVC\View\HtmlView as BaseHtmlView; 19 use Joomla\CMS\Object\CMSObject; 20 use Joomla\CMS\Toolbar\ToolbarHelper; 21 use Joomla\Component\Fields\Administrator\Helper\FieldsHelper; 22 23 // phpcs:disable PSR1.Files.SideEffects 24 \defined('_JEXEC') or die; 25 // phpcs:enable PSR1.Files.SideEffects 26 27 /** 28 * Group View 29 * 30 * @since 3.7.0 31 */ 32 class HtmlView extends BaseHtmlView 33 { 34 /** 35 * @var \Joomla\CMS\Form\Form 36 * 37 * @since 3.7.0 38 */ 39 protected $form; 40 41 /** 42 * @var CMSObject 43 * 44 * @since 3.7.0 45 */ 46 protected $item; 47 48 /** 49 * @var CMSObject 50 * 51 * @since 3.7.0 52 */ 53 protected $state; 54 55 /** 56 * The actions the user is authorised to perform 57 * 58 * @var CMSObject 59 * 60 * @since 3.7.0 61 */ 62 protected $canDo; 63 64 65 /** 66 * Execute and display a template script. 67 * 68 * @param string $tpl The name of the template file to parse; automatically searches through the template paths. 69 * 70 * @return void 71 * 72 * @see JViewLegacy::loadTemplate() 73 * 74 * @since 3.7.0 75 */ 76 public function display($tpl = null) 77 { 78 $this->form = $this->get('Form'); 79 $this->item = $this->get('Item'); 80 $this->state = $this->get('State'); 81 82 $component = ''; 83 $parts = FieldsHelper::extract($this->state->get('filter.context')); 84 85 if ($parts) { 86 $component = $parts[0]; 87 } 88 89 $this->canDo = ContentHelper::getActions($component, 'fieldgroup', $this->item->id); 90 91 // Check for errors. 92 if (count($errors = $this->get('Errors'))) { 93 throw new GenericDataException(implode("\n", $errors), 500); 94 } 95 96 Factory::getApplication()->input->set('hidemainmenu', true); 97 98 $this->addToolbar(); 99 100 parent::display($tpl); 101 } 102 103 /** 104 * Adds the toolbar. 105 * 106 * @return void 107 * 108 * @since 3.7.0 109 */ 110 protected function addToolbar() 111 { 112 $component = ''; 113 $parts = FieldsHelper::extract($this->state->get('filter.context')); 114 115 if ($parts) { 116 $component = $parts[0]; 117 } 118 119 $userId = $this->getCurrentUser()->get('id'); 120 $canDo = $this->canDo; 121 122 $isNew = ($this->item->id == 0); 123 $checkedOut = !(is_null($this->item->checked_out) || $this->item->checked_out == $userId); 124 125 // Avoid nonsense situation. 126 if ($component == 'com_fields') { 127 return; 128 } 129 130 // Load component language file 131 $lang = Factory::getLanguage(); 132 $lang->load($component, JPATH_ADMINISTRATOR) 133 || $lang->load($component, Path::clean(JPATH_ADMINISTRATOR . '/components/' . $component)); 134 135 $title = Text::sprintf('COM_FIELDS_VIEW_GROUP_' . ($isNew ? 'ADD' : 'EDIT') . '_TITLE', Text::_(strtoupper($component))); 136 137 // Prepare the toolbar. 138 ToolbarHelper::title( 139 $title, 140 'puzzle-piece field-' . ($isNew ? 'add' : 'edit') . ' ' . substr($component, 4) . '-group-' . 141 ($isNew ? 'add' : 'edit') 142 ); 143 144 $toolbarButtons = []; 145 146 // For new records, check the create permission. 147 if ($isNew) { 148 ToolbarHelper::apply('group.apply'); 149 150 ToolbarHelper::saveGroup( 151 [ 152 ['save', 'group.save'], 153 ['save2new', 'group.save2new'] 154 ], 155 'btn-success' 156 ); 157 158 ToolbarHelper::cancel('group.cancel'); 159 } else { 160 // Since it's an existing record, check the edit permission, or fall back to edit own if the owner. 161 $itemEditable = $canDo->get('core.edit') || ($canDo->get('core.edit.own') && $this->item->created_by == $userId); 162 163 $toolbarButtons = []; 164 165 // Can't save the record if it's checked out and editable 166 if (!$checkedOut && $itemEditable) { 167 ToolbarHelper::apply('group.apply'); 168 169 $toolbarButtons[] = ['save', 'group.save']; 170 171 // We can save this record, but check the create permission to see if we can return to make a new one. 172 if ($canDo->get('core.create')) { 173 $toolbarButtons[] = ['save2new', 'group.save2new']; 174 } 175 } 176 177 // If an existing item, can save to a copy. 178 if ($canDo->get('core.create')) { 179 $toolbarButtons[] = ['save2copy', 'group.save2copy']; 180 } 181 182 ToolbarHelper::saveGroup( 183 $toolbarButtons, 184 'btn-success' 185 ); 186 187 ToolbarHelper::cancel('group.cancel', 'JTOOLBAR_CLOSE'); 188 } 189 190 ToolbarHelper::help('Component:_New_or_Edit_Field_Group'); 191 } 192 }
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 |