[ Index ]

PHP Cross Reference of Joomla 4.2.2 documentation

title

Body

[close]

/administrator/components/com_tags/src/View/Tag/ -> HtmlView.php (source)

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


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