[ Index ]

PHP Cross Reference of Joomla 4.2.2 documentation

title

Body

[close]

/administrator/components/com_templates/src/View/Style/ -> HtmlView.php (source)

   1  <?php
   2  
   3  /**
   4   * @package     Joomla.Administrator
   5   * @subpackage  com_templates
   6   *
   7   * @copyright   (C) 2009 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\Templates\Administrator\View\Style;
  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\Object\CMSObject;
  19  use Joomla\CMS\Toolbar\ToolbarHelper;
  20  
  21  // phpcs:disable PSR1.Files.SideEffects
  22  \defined('_JEXEC') or die;
  23  // phpcs:enable PSR1.Files.SideEffects
  24  
  25  /**
  26   * View to edit a template style.
  27   *
  28   * @since  1.6
  29   */
  30  class HtmlView extends BaseHtmlView
  31  {
  32      /**
  33       * The CMSObject (on success, false on failure)
  34       *
  35       * @var   CMSObject
  36       */
  37      protected $item;
  38  
  39      /**
  40       * The form object
  41       *
  42       * @var  \Joomla\CMS\Form\Form
  43       */
  44      protected $form;
  45  
  46      /**
  47       * The model state
  48       *
  49       * @var  CMSObject
  50       */
  51      protected $state;
  52  
  53      /**
  54       * The actions the user is authorised to perform
  55       *
  56       * @var    CMSObject
  57       *
  58       * @since  4.0.0
  59       */
  60      protected $canDo;
  61  
  62      /**
  63       * Execute and display a template script.
  64       *
  65       * @param   string  $tpl  The name of the template file to parse; automatically searches through the template paths.
  66       *
  67       * @return  void
  68       *
  69       * @since   1.6
  70       */
  71      public function display($tpl = null)
  72      {
  73          $this->item  = $this->get('Item');
  74          $this->state = $this->get('State');
  75          $this->form  = $this->get('Form');
  76          $this->canDo = ContentHelper::getActions('com_templates');
  77  
  78          // Check for errors.
  79          if (count($errors = $this->get('Errors'))) {
  80              throw new GenericDataException(implode("\n", $errors), 500);
  81          }
  82  
  83          $this->addToolbar();
  84  
  85          parent::display($tpl);
  86      }
  87  
  88      /**
  89       * Add the page title and toolbar.
  90       *
  91       * @return  void
  92       *
  93       * @since   1.6
  94       */
  95      protected function addToolbar()
  96      {
  97          Factory::getApplication()->input->set('hidemainmenu', true);
  98  
  99          $isNew = ($this->item->id == 0);
 100          $canDo = $this->canDo;
 101  
 102          ToolbarHelper::title(
 103              $isNew ? Text::_('COM_TEMPLATES_MANAGER_ADD_STYLE')
 104              : Text::_('COM_TEMPLATES_MANAGER_EDIT_STYLE'),
 105              'paint-brush thememanager'
 106          );
 107  
 108          $toolbarButtons = [];
 109  
 110          // If not checked out, can save the item.
 111          if ($canDo->get('core.edit')) {
 112              ToolbarHelper::apply('style.apply');
 113              $toolbarButtons[] = ['save', 'style.save'];
 114          }
 115  
 116          // If an existing item, can save to a copy.
 117          if (!$isNew && $canDo->get('core.create')) {
 118              $toolbarButtons[] = ['save2copy', 'style.save2copy'];
 119          }
 120  
 121          ToolbarHelper::saveGroup(
 122              $toolbarButtons,
 123              'btn-success'
 124          );
 125  
 126          if (empty($this->item->id)) {
 127              ToolbarHelper::cancel('style.cancel');
 128          } else {
 129              ToolbarHelper::cancel('style.cancel', 'JTOOLBAR_CLOSE');
 130          }
 131  
 132          ToolbarHelper::divider();
 133  
 134          // Get the help information for the template item.
 135          $lang = Factory::getLanguage();
 136          $help = $this->get('Help');
 137  
 138          if ($lang->hasKey($help->url)) {
 139              $debug = $lang->setDebug(false);
 140              $url = Text::_($help->url);
 141              $lang->setDebug($debug);
 142          } else {
 143              $url = null;
 144          }
 145  
 146          ToolbarHelper::help($help->key, false, $url);
 147      }
 148  }


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