[ Index ]

PHP Cross Reference of Joomla 4.2.2 documentation

title

Body

[close]

/administrator/components/com_content/src/View/Articles/ -> HtmlView.php (source)

   1  <?php
   2  
   3  /**
   4   * @package     Joomla.Administrator
   5   * @subpackage  com_content
   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\Content\Administrator\View\Articles;
  12  
  13  use Joomla\CMS\Component\ComponentHelper;
  14  use Joomla\CMS\Factory;
  15  use Joomla\CMS\Language\Multilanguage;
  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\Plugin\PluginHelper;
  20  use Joomla\CMS\Toolbar\Toolbar;
  21  use Joomla\CMS\Toolbar\ToolbarHelper;
  22  use Joomla\Component\Content\Administrator\Extension\ContentComponent;
  23  use Joomla\Component\Content\Administrator\Helper\ContentHelper;
  24  
  25  // phpcs:disable PSR1.Files.SideEffects
  26  \defined('_JEXEC') or die;
  27  // phpcs:enable PSR1.Files.SideEffects
  28  
  29  /**
  30   * View class for a list of articles.
  31   *
  32   * @since  1.6
  33   */
  34  class HtmlView extends BaseHtmlView
  35  {
  36      /**
  37       * An array of items
  38       *
  39       * @var  array
  40       */
  41      protected $items;
  42  
  43      /**
  44       * The pagination object
  45       *
  46       * @var  \Joomla\CMS\Pagination\Pagination
  47       */
  48      protected $pagination;
  49  
  50      /**
  51       * The model state
  52       *
  53       * @var   \Joomla\CMS\Object\CMSObject
  54       */
  55      protected $state;
  56  
  57      /**
  58       * Form object for search filters
  59       *
  60       * @var  \Joomla\CMS\Form\Form
  61       */
  62      public $filterForm;
  63  
  64      /**
  65       * The active search filters
  66       *
  67       * @var  array
  68       */
  69      public $activeFilters;
  70  
  71      /**
  72       * All transition, which can be executed of one if the items
  73       *
  74       * @var  array
  75       */
  76      protected $transitions = [];
  77  
  78      /**
  79       * Is this view an Empty State
  80       *
  81       * @var   boolean
  82       * @since 4.0.0
  83       */
  84      private $isEmptyState = false;
  85  
  86      /**
  87       * Display the view
  88       *
  89       * @param   string  $tpl  The name of the template file to parse; automatically searches through the template paths.
  90       *
  91       * @return  void
  92       */
  93      public function display($tpl = null)
  94      {
  95          $this->items         = $this->get('Items');
  96          $this->pagination    = $this->get('Pagination');
  97          $this->state         = $this->get('State');
  98          $this->filterForm    = $this->get('FilterForm');
  99          $this->activeFilters = $this->get('ActiveFilters');
 100          $this->vote          = PluginHelper::isEnabled('content', 'vote');
 101          $this->hits          = ComponentHelper::getParams('com_content')->get('record_hits', 1);
 102  
 103          if (!\count($this->items) && $this->isEmptyState = $this->get('IsEmptyState')) {
 104              $this->setLayout('emptystate');
 105          }
 106  
 107          if (ComponentHelper::getParams('com_content')->get('workflow_enabled')) {
 108              PluginHelper::importPlugin('workflow');
 109  
 110              $this->transitions = $this->get('Transitions');
 111          }
 112  
 113          // Check for errors.
 114          if (\count($errors = $this->get('Errors')) || $this->transitions === false) {
 115              throw new GenericDataException(implode("\n", $errors), 500);
 116          }
 117  
 118          // We don't need toolbar in the modal window.
 119          if ($this->getLayout() !== 'modal') {
 120              $this->addToolbar();
 121  
 122              // We do not need to filter by language when multilingual is disabled
 123              if (!Multilanguage::isEnabled()) {
 124                  unset($this->activeFilters['language']);
 125                  $this->filterForm->removeField('language', 'filter');
 126              }
 127          } else {
 128              // In article associations modal we need to remove language filter if forcing a language.
 129              // We also need to change the category filter to show show categories with All or the forced language.
 130              if ($forcedLanguage = Factory::getApplication()->input->get('forcedLanguage', '', 'CMD')) {
 131                  // If the language is forced we can't allow to select the language, so transform the language selector filter into a hidden field.
 132                  $languageXml = new \SimpleXMLElement('<field name="language" type="hidden" default="' . $forcedLanguage . '" />');
 133                  $this->filterForm->setField($languageXml, 'filter', true);
 134  
 135                  // Also, unset the active language filter so the search tools is not open by default with this filter.
 136                  unset($this->activeFilters['language']);
 137  
 138                  // One last changes needed is to change the category filter to just show categories with All language or with the forced language.
 139                  $this->filterForm->setFieldAttribute('category_id', 'language', '*,' . $forcedLanguage, 'filter');
 140              }
 141          }
 142  
 143          parent::display($tpl);
 144      }
 145  
 146      /**
 147       * Add the page title and toolbar.
 148       *
 149       * @return  void
 150       *
 151       * @since   1.6
 152       */
 153      protected function addToolbar()
 154      {
 155          $canDo = ContentHelper::getActions('com_content', 'category', $this->state->get('filter.category_id'));
 156          $user  = $this->getCurrentUser();
 157  
 158          // Get the toolbar object instance
 159          $toolbar = Toolbar::getInstance('toolbar');
 160  
 161          ToolbarHelper::title(Text::_('COM_CONTENT_ARTICLES_TITLE'), 'copy article');
 162  
 163          if ($canDo->get('core.create') || \count($user->getAuthorisedCategories('com_content', 'core.create')) > 0) {
 164              $toolbar->addNew('article.add');
 165          }
 166  
 167          if (!$this->isEmptyState && ($canDo->get('core.edit.state') || \count($this->transitions))) {
 168              $dropdown = $toolbar->dropdownButton('status-group')
 169                  ->text('JTOOLBAR_CHANGE_STATUS')
 170                  ->toggleSplit(false)
 171                  ->icon('icon-ellipsis-h')
 172                  ->buttonClass('btn btn-action')
 173                  ->listCheck(true);
 174  
 175              $childBar = $dropdown->getChildToolbar();
 176  
 177              if (\count($this->transitions)) {
 178                  $childBar->separatorButton('transition-headline')
 179                      ->text('COM_CONTENT_RUN_TRANSITIONS')
 180                      ->buttonClass('text-center py-2 h3');
 181  
 182                  $cmd = "Joomla.submitbutton('articles.runTransition');";
 183                  $messages = "{error: [Joomla.JText._('JLIB_HTML_PLEASE_MAKE_A_SELECTION_FROM_THE_LIST')]}";
 184                  $alert = 'Joomla.renderMessages(' . $messages . ')';
 185                  $cmd   = 'if (document.adminForm.boxchecked.value == 0) { ' . $alert . ' } else { ' . $cmd . ' }';
 186  
 187                  foreach ($this->transitions as $transition) {
 188                      $childBar->standardButton('transition')
 189                          ->text($transition['text'])
 190                          ->buttonClass('transition-' . (int) $transition['value'])
 191                          ->icon('icon-project-diagram')
 192                          ->onclick('document.adminForm.transition_id.value=' . (int) $transition['value'] . ';' . $cmd);
 193                  }
 194  
 195                  $childBar->separatorButton('transition-separator');
 196              }
 197  
 198              if ($canDo->get('core.edit.state')) {
 199                  $childBar->publish('articles.publish')->listCheck(true);
 200  
 201                  $childBar->unpublish('articles.unpublish')->listCheck(true);
 202  
 203                  $childBar->standardButton('featured')
 204                      ->text('JFEATURE')
 205                      ->task('articles.featured')
 206                      ->listCheck(true);
 207  
 208                  $childBar->standardButton('unfeatured')
 209                      ->text('JUNFEATURE')
 210                      ->task('articles.unfeatured')
 211                      ->listCheck(true);
 212  
 213                  $childBar->archive('articles.archive')->listCheck(true);
 214  
 215                  $childBar->checkin('articles.checkin')->listCheck(true);
 216  
 217                  if ($this->state->get('filter.published') != ContentComponent::CONDITION_TRASHED) {
 218                      $childBar->trash('articles.trash')->listCheck(true);
 219                  }
 220              }
 221  
 222              // Add a batch button
 223              if (
 224                  $user->authorise('core.create', 'com_content')
 225                  && $user->authorise('core.edit', 'com_content')
 226                  && $user->authorise('core.execute.transition', 'com_content')
 227              ) {
 228                  $childBar->popupButton('batch')
 229                      ->text('JTOOLBAR_BATCH')
 230                      ->selector('collapseModal')
 231                      ->listCheck(true);
 232              }
 233          }
 234  
 235          if (!$this->isEmptyState && $this->state->get('filter.published') == ContentComponent::CONDITION_TRASHED && $canDo->get('core.delete')) {
 236              $toolbar->delete('articles.delete')
 237                  ->text('JTOOLBAR_EMPTY_TRASH')
 238                  ->message('JGLOBAL_CONFIRM_DELETE')
 239                  ->listCheck(true);
 240          }
 241  
 242          if ($user->authorise('core.admin', 'com_content') || $user->authorise('core.options', 'com_content')) {
 243              $toolbar->preferences('com_content');
 244          }
 245  
 246          $toolbar->help('Articles');
 247      }
 248  }


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