[ Index ]

PHP Cross Reference of Joomla 4.2.2 documentation

title

Body

[close]

/administrator/components/com_modules/src/View/Module/ -> HtmlView.php (source)

   1  <?php
   2  
   3  /**
   4   * @package     Joomla.Administrator
   5   * @subpackage  com_modules
   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\Modules\Administrator\View\Module;
  12  
  13  use Joomla\CMS\Factory;
  14  use Joomla\CMS\Helper\ContentHelper;
  15  use Joomla\CMS\Language\Text;
  16  use Joomla\CMS\MVC\View\GenericDataException;
  17  use Joomla\CMS\MVC\View\HtmlView as BaseHtmlView;
  18  use Joomla\CMS\Toolbar\ToolbarHelper;
  19  
  20  // phpcs:disable PSR1.Files.SideEffects
  21  \defined('_JEXEC') or die;
  22  // phpcs:enable PSR1.Files.SideEffects
  23  
  24  /**
  25   * View to edit a module.
  26   *
  27   * @since  1.6
  28   */
  29  class HtmlView extends BaseHtmlView
  30  {
  31      /**
  32       * The Form object
  33       *
  34       * @var  \Joomla\CMS\Form\Form
  35       */
  36      protected $form;
  37  
  38      /**
  39       * The active item
  40       *
  41       * @var  object
  42       */
  43      protected $item;
  44  
  45      /**
  46       * The model state
  47       *
  48       * @var  \Joomla\CMS\Object\CMSObject
  49       */
  50      protected $state;
  51  
  52      /**
  53       * The actions the user is authorised to perform
  54       *
  55       * @var    \Joomla\CMS\Object\CMSObject
  56       *
  57       * @since  4.0.0
  58       */
  59      protected $canDo;
  60  
  61      /**
  62       * Display the view
  63       *
  64       * @param   string  $tpl  The name of the template file to parse; automatically searches through the template paths.
  65       *
  66       * @return  void
  67       */
  68      public function display($tpl = null)
  69      {
  70          $this->form  = $this->get('Form');
  71          $this->item  = $this->get('Item');
  72          $this->state = $this->get('State');
  73          $this->canDo = ContentHelper::getActions('com_modules', 'module', $this->item->id);
  74  
  75          // Check for errors.
  76          if (count($errors = $this->get('Errors'))) {
  77              throw new GenericDataException(implode("\n", $errors), 500);
  78          }
  79  
  80          $this->addToolbar();
  81          parent::display($tpl);
  82      }
  83  
  84      /**
  85       * Add the page title and toolbar.
  86       *
  87       * @return  void
  88       *
  89       * @since   1.6
  90       */
  91      protected function addToolbar()
  92      {
  93          Factory::getApplication()->input->set('hidemainmenu', true);
  94  
  95          $user       = $this->getCurrentUser();
  96          $isNew      = ($this->item->id == 0);
  97          $checkedOut = !(is_null($this->item->checked_out) || $this->item->checked_out == $user->get('id'));
  98          $canDo      = $this->canDo;
  99  
 100          ToolbarHelper::title(Text::sprintf('COM_MODULES_MANAGER_MODULE', Text::_($this->item->module)), 'cube module');
 101  
 102          // For new records, check the create permission.
 103          if ($isNew && $canDo->get('core.create')) {
 104              ToolbarHelper::apply('module.apply');
 105  
 106              ToolbarHelper::saveGroup(
 107                  [
 108                      ['save', 'module.save'],
 109                      ['save2new', 'module.save2new']
 110                  ],
 111                  'btn-success'
 112              );
 113  
 114              ToolbarHelper::cancel('module.cancel');
 115          } else {
 116              $toolbarButtons = [];
 117  
 118              // Can't save the record if it's checked out.
 119              if (!$checkedOut) {
 120                  // Since it's an existing record, check the edit permission.
 121                  if ($canDo->get('core.edit')) {
 122                      ToolbarHelper::apply('module.apply');
 123  
 124                      $toolbarButtons[] = ['save', 'module.save'];
 125  
 126                      // We can save this record, but check the create permission to see if we can return to make a new one.
 127                      if ($canDo->get('core.create')) {
 128                          $toolbarButtons[] = ['save2new', 'module.save2new'];
 129                      }
 130                  }
 131              }
 132  
 133              // If checked out, we can still save
 134              if ($canDo->get('core.create')) {
 135                  $toolbarButtons[] = ['save2copy', 'module.save2copy'];
 136              }
 137  
 138              ToolbarHelper::saveGroup(
 139                  $toolbarButtons,
 140                  'btn-success'
 141              );
 142  
 143              ToolbarHelper::cancel('module.cancel', 'JTOOLBAR_CLOSE');
 144          }
 145  
 146          // Get the help information for the menu item.
 147          $lang = Factory::getLanguage();
 148  
 149          $help = $this->get('Help');
 150  
 151          if ($lang->hasKey($help->url)) {
 152              $debug = $lang->setDebug(false);
 153              $url = Text::_($help->url);
 154              $lang->setDebug($debug);
 155          } else {
 156              $url = null;
 157          }
 158  
 159          ToolbarHelper::inlinehelp();
 160          ToolbarHelper::help($help->key, false, $url);
 161      }
 162  }


Generated: Wed Sep 7 05:41:13 2022 Chilli.vc Blog - For Webmaster,Blog-Writer,System Admin and Domainer