[ Index ]

PHP Cross Reference of Joomla 4.2.2 documentation

title

Body

[close]

/administrator/components/com_fields/src/View/Groups/ -> HtmlView.php (source)

   1  <?php
   2  
   3  /**
   4   * @package     Joomla.Administrator
   5   * @subpackage  com_fields
   6   *
   7   * @copyright   (C) 2016 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\Fields\Administrator\View\Groups;
  12  
  13  use Joomla\CMS\Factory;
  14  use Joomla\CMS\Filesystem\Path;
  15  use Joomla\CMS\Helper\ContentHelper;
  16  use Joomla\CMS\Language\Multilanguage;
  17  use Joomla\CMS\Language\Text;
  18  use Joomla\CMS\MVC\View\GenericDataException;
  19  use Joomla\CMS\MVC\View\HtmlView as BaseHtmlView;
  20  use Joomla\CMS\Plugin\PluginHelper;
  21  use Joomla\CMS\Router\Route;
  22  use Joomla\CMS\Toolbar\Toolbar;
  23  use Joomla\CMS\Toolbar\ToolbarHelper;
  24  use Joomla\Component\Fields\Administrator\Helper\FieldsHelper;
  25  
  26  // phpcs:disable PSR1.Files.SideEffects
  27  \defined('_JEXEC') or die;
  28  // phpcs:enable PSR1.Files.SideEffects
  29  
  30  /**
  31   * Groups View
  32   *
  33   * @since  3.7.0
  34   */
  35  class HtmlView extends BaseHtmlView
  36  {
  37      /**
  38       * @var    \Joomla\CMS\Form\Form
  39       *
  40       * @since  3.7.0
  41       */
  42      public $filterForm;
  43  
  44      /**
  45       * @var    array
  46       *
  47       * @since  3.7.0
  48       */
  49      public $activeFilters;
  50  
  51      /**
  52       * @var    array
  53       *
  54       * @since  3.7.0
  55       */
  56      protected $items;
  57  
  58      /**
  59       * @var    \Joomla\CMS\Pagination\Pagination
  60       *
  61       * @since  3.7.0
  62       */
  63      protected $pagination;
  64  
  65      /**
  66       * @var    \Joomla\CMS\Object\CMSObject
  67       *
  68       * @since  3.7.0
  69       */
  70      protected $state;
  71  
  72      /**
  73       * Execute and display a template script.
  74       *
  75       * @param   string  $tpl  The name of the template file to parse; automatically searches through the template paths.
  76       *
  77       * @return  void
  78       *
  79       * @see     HtmlView::loadTemplate()
  80       *
  81       * @since   3.7.0
  82       */
  83      public function display($tpl = null)
  84      {
  85          $this->state         = $this->get('State');
  86          $this->items         = $this->get('Items');
  87          $this->pagination    = $this->get('Pagination');
  88          $this->filterForm    = $this->get('FilterForm');
  89          $this->activeFilters = $this->get('ActiveFilters');
  90  
  91          // Check for errors.
  92          if (count($errors = $this->get('Errors'))) {
  93              throw new GenericDataException(implode("\n", $errors), 500);
  94          }
  95  
  96          // Display a warning if the fields system plugin is disabled
  97          if (!PluginHelper::isEnabled('system', 'fields')) {
  98              $link = Route::_('index.php?option=com_plugins&task=plugin.edit&extension_id=' . FieldsHelper::getFieldsPluginId());
  99              Factory::getApplication()->enqueueMessage(Text::sprintf('COM_FIELDS_SYSTEM_PLUGIN_NOT_ENABLED', $link), 'warning');
 100          }
 101  
 102          $this->addToolbar();
 103  
 104          // We do not need to filter by language when multilingual is disabled
 105          if (!Multilanguage::isEnabled()) {
 106              unset($this->activeFilters['language']);
 107              $this->filterForm->removeField('language', 'filter');
 108          }
 109  
 110          parent::display($tpl);
 111      }
 112  
 113      /**
 114       * Adds the toolbar.
 115       *
 116       * @return  void
 117       *
 118       * @since   3.7.0
 119       */
 120      protected function addToolbar()
 121      {
 122          $groupId   = $this->state->get('filter.group_id');
 123          $component = '';
 124          $parts     = FieldsHelper::extract($this->state->get('filter.context'));
 125  
 126          if ($parts) {
 127              $component = $parts[0];
 128          }
 129  
 130          $canDo     = ContentHelper::getActions($component, 'fieldgroup', $groupId);
 131  
 132          // Get the toolbar object instance
 133          $toolbar = Toolbar::getInstance('toolbar');
 134  
 135          // Avoid nonsense situation.
 136          if ($component == 'com_fields') {
 137              return;
 138          }
 139  
 140          // Load component language file
 141          $lang = Factory::getLanguage();
 142          $lang->load($component, JPATH_ADMINISTRATOR)
 143          || $lang->load($component, Path::clean(JPATH_ADMINISTRATOR . '/components/' . $component));
 144  
 145          $title = Text::sprintf('COM_FIELDS_VIEW_GROUPS_TITLE', Text::_(strtoupper($component)));
 146  
 147          // Prepare the toolbar.
 148          ToolbarHelper::title($title, 'puzzle-piece fields ' . substr($component, 4) . '-groups');
 149  
 150          if ($canDo->get('core.create')) {
 151              $toolbar->addNew('group.add');
 152          }
 153  
 154          if ($canDo->get('core.edit.state') || $this->getCurrentUser()->authorise('core.admin')) {
 155              $dropdown = $toolbar->dropdownButton('status-group')
 156                  ->text('JTOOLBAR_CHANGE_STATUS')
 157                  ->toggleSplit(false)
 158                  ->icon('icon-ellipsis-h')
 159                  ->buttonClass('btn btn-action')
 160                  ->listCheck(true);
 161  
 162              $childBar = $dropdown->getChildToolbar();
 163  
 164              if ($canDo->get('core.edit.state')) {
 165                  $childBar->publish('groups.publish')->listCheck(true);
 166  
 167                  $childBar->unpublish('groups.unpublish')->listCheck(true);
 168  
 169                  $childBar->archive('groups.archive')->listCheck(true);
 170              }
 171  
 172              if ($this->getCurrentUser()->authorise('core.admin')) {
 173                  $childBar->checkin('groups.checkin')->listCheck(true);
 174              }
 175  
 176              if ($canDo->get('core.edit.state') && !$this->state->get('filter.state') == -2) {
 177                  $childBar->trash('groups.trash')->listCheck(true);
 178              }
 179  
 180              // Add a batch button
 181              if ($canDo->get('core.create') && $canDo->get('core.edit') && $canDo->get('core.edit.state')) {
 182                  $childBar->popupButton('batch')
 183                      ->text('JTOOLBAR_BATCH')
 184                      ->selector('collapseModal')
 185                      ->listCheck(true);
 186              }
 187          }
 188  
 189          if ($this->state->get('filter.state') == -2 && $canDo->get('core.delete', $component)) {
 190              $toolbar->delete('groups.delete')
 191                  ->text('JTOOLBAR_EMPTY_TRASH')
 192                  ->message('JGLOBAL_CONFIRM_DELETE')
 193                  ->listCheck(true);
 194          }
 195  
 196          if ($canDo->get('core.admin') || $canDo->get('core.options')) {
 197              $toolbar->preferences($component);
 198          }
 199  
 200          $toolbar->help('Component:_Field_Groups');
 201      }
 202  }


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