[ Index ]

PHP Cross Reference of Joomla 4.2.2 documentation

title

Body

[close]

/administrator/components/com_installer/src/View/Updatesite/ -> HtmlView.php (source)

   1  <?php
   2  
   3  /**
   4   * @package     Joomla.Administrator
   5   * @subpackage  com_installer
   6   *
   7   * @copyright   (C) 2019 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\Installer\Administrator\View\Updatesite;
  12  
  13  use Joomla\CMS\Factory;
  14  use Joomla\CMS\Form\Form;
  15  use Joomla\CMS\Helper\ContentHelper;
  16  use Joomla\CMS\Language\Text;
  17  use Joomla\CMS\MVC\View\GenericDataException;
  18  use Joomla\CMS\Toolbar\ToolbarHelper;
  19  use Joomla\Component\Installer\Administrator\Helper\InstallerHelper;
  20  use Joomla\Component\Installer\Administrator\Model\UpdatesiteModel;
  21  use Joomla\Component\Installer\Administrator\View\Installer\HtmlView as InstallerViewDefault;
  22  
  23  // phpcs:disable PSR1.Files.SideEffects
  24  \defined('_JEXEC') or die;
  25  // phpcs:enable PSR1.Files.SideEffects
  26  
  27  /**
  28   * View to edit an update site.
  29   *
  30   * @since  4.0.0
  31   */
  32  class HtmlView extends InstallerViewDefault
  33  {
  34      /**
  35       * The Form object
  36       *
  37       * @var  Form
  38       *
  39       * @since   4.0.0
  40       */
  41      protected $form;
  42  
  43      /**
  44       * The active item
  45       *
  46       * @var  object
  47       *
  48       * @since   4.0.0
  49       */
  50      protected $item;
  51  
  52      /**
  53       * Display the view.
  54       *
  55       * @param   string  $tpl  The name of the template file to parse; automatically searches through the template paths.
  56       *
  57       * @return  void
  58       *
  59       * @since   4.0.0
  60       *
  61       * @throws \Exception
  62       */
  63      public function display($tpl = null): void
  64      {
  65          /** @var UpdatesiteModel $model */
  66          $model      = $this->getModel();
  67          $this->form = $model->getForm();
  68          $this->item = $model->getItem();
  69  
  70          // Remove the extra_query field if it's a free download extension
  71          $dlidSupportingSites = InstallerHelper::getDownloadKeySupportedSites(false);
  72          $update_site_id = $this->item->get('update_site_id');
  73  
  74          if (!in_array($update_site_id, $dlidSupportingSites)) {
  75              $this->form->removeField('extra_query');
  76          }
  77  
  78          // Check for errors.
  79          if (count($errors = $model->getErrors())) {
  80              throw new GenericDataException(implode("\n", $errors), 500);
  81          }
  82  
  83          parent::display($tpl);
  84      }
  85  
  86      /**
  87       * Add the page title and toolbar.
  88       *
  89       * @return  void
  90       *
  91       * @since   4.0.0
  92       *
  93       * @throws  \Exception
  94       */
  95      protected function addToolbar(): void
  96      {
  97          $app = Factory::getApplication();
  98          $app->input->set('hidemainmenu', true);
  99  
 100          $user       = $app->getIdentity();
 101          $userId     = $user->id;
 102          $checkedOut = !(is_null($this->item->checked_out) || $this->item->checked_out === $userId);
 103  
 104          // Since we don't track these assets at the item level, use the category id.
 105          $canDo = ContentHelper::getActions('com_installer', 'updatesite');
 106  
 107          ToolbarHelper::title(Text::_('COM_INSTALLER_UPDATESITE_EDIT_TITLE'), 'address contact');
 108  
 109          // Since it's an existing record, check the edit permission, or fall back to edit own if the owner.
 110          $itemEditable   = $canDo->get('core.edit');
 111          $toolbarButtons = [];
 112  
 113          // Can't save the record if it's checked out and editable
 114          if (!$checkedOut && $itemEditable && $this->form->getField('extra_query')) {
 115              $toolbarButtons[] = ['apply', 'updatesite.apply'];
 116              $toolbarButtons[] = ['save', 'updatesite.save'];
 117          }
 118  
 119          ToolbarHelper::saveGroup($toolbarButtons);
 120  
 121          ToolbarHelper::cancel('updatesite.cancel', 'JTOOLBAR_CLOSE');
 122  
 123          ToolbarHelper::help('Edit_Update_Site');
 124      }
 125  }


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