[ Index ]

PHP Cross Reference of Joomla 4.2.2 documentation

title

Body

[close]

/administrator/components/com_contenthistory/src/View/History/ -> HtmlView.php (source)

   1  <?php
   2  
   3  /**
   4   * @package     Joomla.Administrator
   5   * @subpackage  com_contenthistory
   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\Contenthistory\Administrator\View\History;
  12  
  13  use Joomla\CMS\Factory;
  14  use Joomla\CMS\Filter\InputFilter;
  15  use Joomla\CMS\MVC\View\GenericDataException;
  16  use Joomla\CMS\MVC\View\HtmlView as BaseHtmlView;
  17  use Joomla\CMS\Pagination\Pagination;
  18  use Joomla\CMS\Router\Route;
  19  use Joomla\CMS\Session\Session;
  20  use Joomla\CMS\Toolbar\Toolbar;
  21  use Joomla\CMS\Toolbar\ToolbarFactoryInterface;
  22  
  23  // phpcs:disable PSR1.Files.SideEffects
  24  \defined('_JEXEC') or die;
  25  // phpcs:enable PSR1.Files.SideEffects
  26  
  27  /**
  28   * View class for a list of contenthistory.
  29   *
  30   * @since  3.2
  31   */
  32  class HtmlView extends BaseHtmlView
  33  {
  34      /**
  35       * An array of items
  36       *
  37       * @var  array
  38       */
  39      protected $items;
  40  
  41      /**
  42       * The model state
  43       *
  44       * @var  Pagination
  45       */
  46      protected $pagination;
  47  
  48      /**
  49       * The model state
  50       *
  51       * @var  \Joomla\CMS\Object\CMSObject
  52       */
  53      protected $state;
  54  
  55      /**
  56       * Method to display the view.
  57       *
  58       * @param   string  $tpl  A template file to load. [optional]
  59       *
  60       * @return  void
  61       *
  62       * @since   3.2
  63       */
  64      public function display($tpl = null)
  65      {
  66          $this->state = $this->get('State');
  67          $this->items = $this->get('Items');
  68          $this->pagination = $this->get('Pagination');
  69  
  70          // Check for errors.
  71          if (count($errors = $this->get('Errors'))) {
  72              throw new GenericDataException(implode("\n", $errors), 500);
  73          }
  74  
  75          $this->toolbar = $this->addToolbar();
  76  
  77          parent::display($tpl);
  78      }
  79  
  80      /**
  81       * Add the page toolbar.
  82       *
  83       * @return  Toolbar
  84       *
  85       * @since  4.0.0
  86       */
  87      protected function addToolbar(): Toolbar
  88      {
  89          /** @var Toolbar $toolbar */
  90          $toolbar = Factory::getContainer()->get(ToolbarFactoryInterface::class)->createToolbar('toolbar');
  91  
  92          // Cache a session token for reuse throughout.
  93          $token = Session::getFormToken();
  94  
  95          // Clean up input to ensure a clean url.
  96          $aliasArray = explode('.', $this->state->item_id);
  97          $option     = $aliasArray[1] == 'category'
  98              ? 'com_categories&amp;extension=' . implode('.', array_slice($aliasArray, 0, count($aliasArray) - 2))
  99              : $aliasArray[0];
 100          $filter     = InputFilter::getInstance();
 101          $task       = $filter->clean($aliasArray[1], 'cmd') . '.loadhistory';
 102  
 103          // Build the final urls.
 104          $loadUrl    = Route::_('index.php?option=' . $filter->clean($option, 'cmd') . '&amp;task=' . $task . '&amp;' . $token . '=1');
 105          $previewUrl = Route::_('index.php?option=com_contenthistory&view=preview&layout=preview&tmpl=component&' . $token . '=1');
 106          $compareUrl = Route::_('index.php?option=com_contenthistory&view=compare&layout=compare&tmpl=component&' . $token . '=1');
 107  
 108          $toolbar->basicButton('load')
 109              ->attributes(['data-url' => $loadUrl])
 110              ->icon('icon-upload')
 111              ->buttonClass('btn btn-success')
 112              ->text('COM_CONTENTHISTORY_BUTTON_LOAD')
 113              ->listCheck(true);
 114  
 115          $toolbar->basicButton('preview')
 116              ->attributes(['data-url' => $previewUrl])
 117              ->icon('icon-search')
 118              ->text('COM_CONTENTHISTORY_BUTTON_PREVIEW')
 119              ->listCheck(true);
 120  
 121          $toolbar->basicButton('compare')
 122              ->attributes(['data-url' => $compareUrl])
 123              ->icon('icon-search-plus')
 124              ->text('COM_CONTENTHISTORY_BUTTON_COMPARE')
 125              ->listCheck(true);
 126  
 127          $toolbar->basicButton('keep')
 128              ->task('history.keep')
 129              ->buttonClass('btn btn-inverse')
 130              ->icon('icon-lock')
 131              ->text('COM_CONTENTHISTORY_BUTTON_KEEP')
 132              ->listCheck(true);
 133  
 134          $toolbar->basicButton('delete')
 135              ->task('history.delete')
 136              ->buttonClass('btn btn-danger')
 137              ->icon('icon-times')
 138              ->text('COM_CONTENTHISTORY_BUTTON_DELETE')
 139              ->listCheck(true);
 140  
 141          return $toolbar;
 142      }
 143  }


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