[ Index ]

PHP Cross Reference of Joomla 4.2.2 documentation

title

Body

[close]

/administrator/components/com_banners/src/View/Banner/ -> HtmlView.php (source)

   1  <?php
   2  
   3  /**
   4   * @package     Joomla.Administrator
   5   * @subpackage  com_banners
   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\Banners\Administrator\View\Banner;
  12  
  13  use Exception;
  14  use Joomla\CMS\Component\ComponentHelper;
  15  use Joomla\CMS\Factory;
  16  use Joomla\CMS\Form\Form;
  17  use Joomla\CMS\Helper\ContentHelper;
  18  use Joomla\CMS\Language\Text;
  19  use Joomla\CMS\MVC\View\GenericDataException;
  20  use Joomla\CMS\MVC\View\HtmlView as BaseHtmlView;
  21  use Joomla\CMS\Toolbar\ToolbarHelper;
  22  use Joomla\Component\Banners\Administrator\Model\BannerModel;
  23  
  24  // phpcs:disable PSR1.Files.SideEffects
  25  \defined('_JEXEC') or die;
  26  // phpcs:enable PSR1.Files.SideEffects
  27  
  28  /**
  29   * View to edit a banner.
  30   *
  31   * @since  1.5
  32   */
  33  class HtmlView extends BaseHtmlView
  34  {
  35      /**
  36       * The Form object
  37       *
  38       * @var    Form
  39       * @since  1.5
  40       */
  41      protected $form;
  42  
  43      /**
  44       * The active item
  45       *
  46       * @var    object
  47       * @since  1.5
  48       */
  49      protected $item;
  50  
  51      /**
  52       * The model state
  53       *
  54       * @var    object
  55       * @since  1.5
  56       */
  57      protected $state;
  58  
  59      /**
  60       * Display the view
  61       *
  62       * @param   string  $tpl  The name of the template file to parse; automatically searches through the template paths.
  63       *
  64       * @return  void
  65       *
  66       * @since   1.5
  67       *
  68       * @throws  Exception
  69       */
  70      public function display($tpl = null): void
  71      {
  72          /** @var BannerModel $model */
  73          $model       = $this->getModel();
  74          $this->form  = $model->getForm();
  75          $this->item  = $model->getItem();
  76          $this->state = $model->getState();
  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       * @throws  Exception
  95       */
  96      protected function addToolbar(): void
  97      {
  98          Factory::getApplication()->input->set('hidemainmenu', true);
  99  
 100          $user       = $this->getCurrentUser();
 101          $userId     = $user->id;
 102          $isNew      = ($this->item->id == 0);
 103          $checkedOut = !(\is_null($this->item->checked_out) || $this->item->checked_out == $userId);
 104  
 105          // Since we don't track these assets at the item level, use the category id.
 106          $canDo = ContentHelper::getActions('com_banners', 'category', $this->item->catid);
 107  
 108          ToolbarHelper::title($isNew ? Text::_('COM_BANNERS_MANAGER_BANNER_NEW') : Text::_('COM_BANNERS_MANAGER_BANNER_EDIT'), 'bookmark banners');
 109  
 110          $toolbarButtons = [];
 111  
 112          // If not checked out, can save the item.
 113          if (!$checkedOut && ($canDo->get('core.edit') || \count($user->getAuthorisedCategories('com_banners', 'core.create')) > 0)) {
 114              ToolbarHelper::apply('banner.apply');
 115              $toolbarButtons[] = ['save', 'banner.save'];
 116  
 117              if ($canDo->get('core.create')) {
 118                  $toolbarButtons[] = ['save2new', 'banner.save2new'];
 119              }
 120          }
 121  
 122          // If an existing item, can save to a copy.
 123          if (!$isNew && $canDo->get('core.create')) {
 124              $toolbarButtons[] = ['save2copy', 'banner.save2copy'];
 125          }
 126  
 127          ToolbarHelper::saveGroup(
 128              $toolbarButtons,
 129              'btn-success'
 130          );
 131  
 132          if (empty($this->item->id)) {
 133              ToolbarHelper::cancel('banner.cancel');
 134          } else {
 135              ToolbarHelper::cancel('banner.cancel', 'JTOOLBAR_CLOSE');
 136  
 137              if (ComponentHelper::isEnabled('com_contenthistory') && $this->state->params->get('save_history', 0) && $canDo->get('core.edit')) {
 138                  ToolbarHelper::versions('com_banners.banner', $this->item->id);
 139              }
 140          }
 141  
 142          ToolbarHelper::divider();
 143          ToolbarHelper::help('Banners:_Edit');
 144      }
 145  }


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