diff --git a/administrator/components/com_actionlogs/src/View/Actionlogs/HtmlView.php b/administrator/components/com_actionlogs/src/View/Actionlogs/HtmlView.php index 503a31f55c6b3..11518d0616a75 100644 --- a/administrator/components/com_actionlogs/src/View/Actionlogs/HtmlView.php +++ b/administrator/components/com_actionlogs/src/View/Actionlogs/HtmlView.php @@ -11,14 +11,10 @@ namespace Joomla\Component\Actionlogs\Administrator\View\Actionlogs; use Joomla\CMS\Component\ComponentHelper; -use Joomla\CMS\Form\Form; use Joomla\CMS\Language\Text; -use Joomla\CMS\MVC\View\GenericDataException; -use Joomla\CMS\MVC\View\HtmlView as BaseHtmlView; -use Joomla\CMS\Pagination\Pagination; +use Joomla\CMS\MVC\View\ListView; use Joomla\CMS\Toolbar\ToolbarHelper; use Joomla\Component\Actionlogs\Administrator\Helper\ActionlogsHelper; -use Joomla\Component\Actionlogs\Administrator\Model\ActionlogsModel; // phpcs:disable PSR1.Files.SideEffects \defined('_JEXEC') or die; @@ -29,48 +25,8 @@ * * @since 3.9.0 */ -class HtmlView extends BaseHtmlView +class HtmlView extends ListView { - /** - * An array of items. - * - * @var array - * @since 3.9.0 - */ - protected $items; - - /** - * The model state - * - * @var array - * @since 3.9.0 - */ - protected $state; - - /** - * The pagination object - * - * @var Pagination - * @since 3.9.0 - */ - protected $pagination; - - /** - * Form object for search filters - * - * @var Form - * @since 3.9.0 - */ - public $filterForm; - - /** - * The active search filters - * - * @var array - * @since 3.9.0 - */ - public $activeFilters; - /** * Setting if the IP column should be shown * @@ -88,35 +44,39 @@ class HtmlView extends BaseHtmlView protected $dateRelative = false; /** - * Method to display the view. + * Constructor * - * @param string $tpl A template file to load. [optional] + * @param array $config An optional associative array of configuration settings. * - * @return void + * @since __DEPLOY_VERSION__ + */ + public function __construct(array $config) + { + if (empty($config['option'])) { + $config['option'] = 'com_actionlogs'; + } + + $config['toolbar_title'] = 'COM_ACTIONLOGS_MANAGER_USERLOGS'; + $config['toolbar_icon'] = 'list-2 actionlog'; + + parent::__construct($config); + } + + /** + * Prepare view data * - * @since 3.9.0 + * @return void * - * @throws \Exception + * @since __DEPLOY_VERSION__ */ - public function display($tpl = null) + protected function initializeView() { - /** @var ActionlogsModel $model */ - $model = $this->getModel(); - $this->items = $model->getItems(); - $this->state = $model->getState(); - $this->pagination = $model->getPagination(); - $this->filterForm = $model->getFilterForm(); - $this->activeFilters = $model->getActiveFilters(); + parent::initializeView(); + $params = ComponentHelper::getParams('com_actionlogs'); $this->showIpColumn = (bool) $params->get('ip_logging', 0); $this->dateRelative = (bool) $params->get('date_relative', 1); - if (\count($errors = $model->getErrors())) { - throw new GenericDataException(implode("\n", $errors), 500); - } - - $this->addToolbar(); - // Load all actionlog plugins language files ActionlogsHelper::loadActionLogPluginsLanguage(); @@ -124,8 +84,6 @@ public function display($tpl = null) $this->filterForm ->addControlField('task', '') ->addControlField('boxchecked', '0'); - - parent::display($tpl); } /** @@ -138,6 +96,7 @@ public function display($tpl = null) protected function addToolbar() { ToolbarHelper::title(Text::_('COM_ACTIONLOGS_MANAGER_USERLOGS'), 'icon-list-2'); + $toolbar = $this->getDocument()->getToolbar(); $toolbar->standardButton('download', 'COM_ACTIONLOGS_EXPORT_CSV', 'actionlogs.exportSelectedLogs') diff --git a/administrator/components/com_banners/src/View/Banners/HtmlView.php b/administrator/components/com_banners/src/View/Banners/HtmlView.php index 372ec2d4bbd34..f5f7022170be1 100644 --- a/administrator/components/com_banners/src/View/Banners/HtmlView.php +++ b/administrator/components/com_banners/src/View/Banners/HtmlView.php @@ -10,17 +10,10 @@ namespace Joomla\Component\Banners\Administrator\View\Banners; -use Joomla\CMS\Form\Form; use Joomla\CMS\Helper\ContentHelper; use Joomla\CMS\Language\Multilanguage; -use Joomla\CMS\Language\Text; -use Joomla\CMS\MVC\View\GenericDataException; -use Joomla\CMS\MVC\View\HtmlView as BaseHtmlView; -use Joomla\CMS\Pagination\Pagination; -use Joomla\CMS\Toolbar\Button\DropdownButton; -use Joomla\CMS\Toolbar\ToolbarHelper; +use Joomla\CMS\MVC\View\ListView; use Joomla\Component\Banners\Administrator\Model\BannersModel; -use Joomla\Registry\Registry; // phpcs:disable PSR1.Files.SideEffects \defined('_JEXEC') or die; @@ -31,24 +24,8 @@ * * @since 1.6 */ -class HtmlView extends BaseHtmlView +class HtmlView extends ListView { - /** - * The search tools form - * - * @var Form - * @since 1.6 - */ - public $filterForm; - - /** - * The active search filters - * - * @var array - * @since 1.6 - */ - public $activeFilters = []; - /** * Category data * @@ -58,68 +35,48 @@ class HtmlView extends BaseHtmlView protected $categories = []; /** - * An array of items + * The help link for the view * - * @var array - * @since 1.6 + * @var string */ - protected $items = []; + protected $helpLink = 'Banners'; /** - * The pagination object + * Constructor * - * @var Pagination - * @since 1.6 - */ - protected $pagination; - - /** - * The model state + * @param array $config An optional associative array of configuration settings. * - * @var Registry - * @since 1.6 + * @since __DEPLOY_VERSION__ */ - protected $state; + public function __construct(array $config) + { + if (empty($config['option'])) { + $config['option'] = 'com_banners'; + } - /** - * Is this view an Empty State - * - * @var boolean - * @since 4.0.0 - */ - private $isEmptyState = false; + $config['toolbar_icon'] = 'bookmark banners'; + $config['supports_batch'] = true; + $config['category'] = 'com_banners'; + + parent::__construct($config); + } /** - * Method to display the view. - * - * @param string $tpl A template file to load. [optional] + * Prepare view data * * @return void * - * @since 1.6 - * @throws \Exception + * @since __DEPLOY_VERSION__ */ - public function display($tpl = null): void + protected function initializeView() { + parent::initializeView(); + /** @var BannersModel $model */ $model = $this->getModel(); - $this->categories = $model->getCategoryOrders(); - $this->items = $model->getItems(); - $this->pagination = $model->getPagination(); - $this->state = $model->getState(); - $this->filterForm = $model->getFilterForm(); - $this->activeFilters = $model->getActiveFilters(); - - if (!\count($this->items) && $this->isEmptyState = $model->getIsEmptyState()) { - $this->setLayout('emptystate'); - } - - // Check for errors. - if (\count($errors = $model->getErrors())) { - throw new GenericDataException(implode("\n", $errors), 500); - } - $this->addToolbar(); + $this->categories = $model->getCategoryOrders(); + $this->canDo = ContentHelper::getActions('com_banners', 'category', $this->state->get('filter.category_id')); // We do not need to filter by language when multilingual is disabled if (!Multilanguage::isEnabled()) { @@ -131,87 +88,5 @@ public function display($tpl = null): void $this->filterForm ->addControlField('task', '') ->addControlField('boxchecked', '0'); - - parent::display($tpl); - } - - /** - * Add the page title and toolbar. - * - * @return void - * - * @since 1.6 - */ - protected function addToolbar(): void - { - $canDo = ContentHelper::getActions('com_banners', 'category', $this->state->get('filter.category_id')); - $user = $this->getCurrentUser(); - $toolbar = $this->getDocument()->getToolbar(); - - ToolbarHelper::title(Text::_('COM_BANNERS_MANAGER_BANNERS'), 'bookmark banners'); - - if ($canDo->get('core.create') || \count($user->getAuthorisedCategories('com_banners', 'core.create')) > 0) { - $toolbar->addNew('banner.add'); - } - - if (!$this->isEmptyState && ($canDo->get('core.edit.state') || ($this->state->get('filter.published') == -2 && $canDo->get('core.delete')))) { - /** @var DropdownButton $dropdown */ - $dropdown = $toolbar->dropdownButton('status-group', 'JTOOLBAR_CHANGE_STATUS') - ->toggleSplit(false) - ->icon('icon-ellipsis-h') - ->buttonClass('btn btn-action') - ->listCheck(true); - - $childBar = $dropdown->getChildToolbar(); - - if ($canDo->get('core.edit.state')) { - if ($this->state->get('filter.published') != 2) { - $childBar->publish('banners.publish')->listCheck(true); - - $childBar->unpublish('banners.unpublish')->listCheck(true); - } - - if ($this->state->get('filter.published') != -1) { - if ($this->state->get('filter.published') != 2) { - $childBar->archive('banners.archive')->listCheck(true); - } elseif ($this->state->get('filter.published') == 2) { - $childBar->publish('publish')->task('banners.publish')->listCheck(true); - } - } - - $childBar->checkin('banners.checkin'); - - if ($this->state->get('filter.published') != -2) { - $childBar->trash('banners.trash')->listCheck(true); - } - } - - if ($this->state->get('filter.published') == -2 && $canDo->get('core.delete')) { - $toolbar->delete('banners.delete', 'JTOOLBAR_DELETE_FROM_TRASH') - ->message('JGLOBAL_CONFIRM_DELETE') - ->listCheck(true); - } - - // Add a batch button - if ( - $user->authorise('core.create', 'com_banners') - && $user->authorise('core.edit', 'com_banners') - && $user->authorise('core.edit.state', 'com_banners') - ) { - $childBar->popupButton('batch', 'JTOOLBAR_BATCH') - ->popupType('inline') - ->textHeader(Text::_('COM_BANNERS_BATCH_OPTIONS')) - ->url('#joomla-dialog-batch') - ->modalWidth('800px') - ->modalHeight('fit-content') - ->listCheck(true); - } - } - - if ($user->authorise('core.admin', 'com_banners') || $user->authorise('core.options', 'com_banners')) { - $toolbar->preferences('com_banners'); - } - - $toolbar->help('Banners'); } } diff --git a/administrator/components/com_contact/src/View/Contacts/HtmlView.php b/administrator/components/com_contact/src/View/Contacts/HtmlView.php index 7462847444b3f..779a6b522109f 100644 --- a/administrator/components/com_contact/src/View/Contacts/HtmlView.php +++ b/administrator/components/com_contact/src/View/Contacts/HtmlView.php @@ -13,12 +13,7 @@ use Joomla\CMS\Factory; use Joomla\CMS\Helper\ContentHelper; use Joomla\CMS\Language\Multilanguage; -use Joomla\CMS\Language\Text; -use Joomla\CMS\MVC\View\GenericDataException; -use Joomla\CMS\MVC\View\HtmlView as BaseHtmlView; -use Joomla\CMS\Toolbar\Button\DropdownButton; -use Joomla\CMS\Toolbar\ToolbarHelper; -use Joomla\Component\Contact\Administrator\Model\ContactsModel; +use Joomla\CMS\MVC\View\ListView; // phpcs:disable PSR1.Files.SideEffects \defined('_JEXEC') or die; @@ -29,88 +24,52 @@ * * @since 1.6 */ -class HtmlView extends BaseHtmlView +class HtmlView extends ListView { /** - * An array of items + * The help link for the view * - * @var array + * @var string */ - protected $items; + protected $helpLink = 'Contacts'; /** - * The pagination object + * Constructor * - * @var \Joomla\CMS\Pagination\Pagination + * @param array $config An optional associative array of configuration settings. */ - protected $pagination; - - /** - * The model state - * - * @var \Joomla\Registry\Registry - */ - protected $state; - - /** - * Form object for search filters - * - * @var \Joomla\CMS\Form\Form - */ - public $filterForm; + public function __construct(array $config) + { + if (empty($config['option'])) { + $config['option'] = 'com_contact'; + } - /** - * The active search filters - * - * @var array - */ - public $activeFilters; + $config['toolbar_icon'] = 'address-book contact'; + $config['supports_batch'] = true; - /** - * Is this view an Empty State - * - * @var boolean - * - * @since 4.0.0 - */ - private $isEmptyState = false; + parent::__construct($config); + } /** - * Display the view. - * - * @param string $tpl The name of the template file to parse; automatically searches through the template paths. + * Prepare view data * * @return void */ - public function display($tpl = null) + protected function initializeView() { - /** @var ContactsModel $model */ - $model = $this->getModel(); + parent::initializeView(); - $this->items = $model->getItems(); - $this->pagination = $model->getPagination(); - $this->state = $model->getState(); - $this->filterForm = $model->getFilterForm(); - $this->activeFilters = $model->getActiveFilters(); + $user = $this->getCurrentUser(); - if (!\count($this->items) && $this->isEmptyState = $model->getIsEmptyState()) { - $this->setLayout('emptystate'); - } + $this->canDo = ContentHelper::getActions('com_contact', 'category', $this->state->get('filter.category_id')); - // Check for errors. - if (\count($errors = $model->getErrors())) { - throw new GenericDataException(implode("\n", $errors), 500); + // Special case of we can create contact for specific categories show add button + if (\count($user->getAuthorisedCategories('com_contact', 'core.create')) > 0) { + $this->canDo->set('core.create', true); } - // Add form control fields - $this->filterForm - ->addControlField('task', '') - ->addControlField('boxchecked', '0'); - // We don't need toolbar in the modal window. if ($this->getLayout() !== 'modal') { - $this->addToolbar(); - // We do not need to filter by language when multilingual is disabled if (!Multilanguage::isEnabled()) { unset($this->activeFilters['language']); @@ -137,82 +96,9 @@ public function display($tpl = null) ->addControlField('forcedLanguage', $forcedLanguage); } - parent::display($tpl); - } - - /** - * Add the page title and toolbar. - * - * @return void - * - * @since 1.6 - */ - protected function addToolbar() - { - $canDo = ContentHelper::getActions('com_contact', 'category', $this->state->get('filter.category_id')); - $user = $this->getCurrentUser(); - - // Get the toolbar object instance - $toolbar = $this->getDocument()->getToolbar(); - - ToolbarHelper::title(Text::_('COM_CONTACT_MANAGER_CONTACTS'), 'address-book contact'); - - if ($canDo->get('core.create') || \count($user->getAuthorisedCategories('com_contact', 'core.create')) > 0) { - $toolbar->addNew('contact.add'); - } - - if (!$this->isEmptyState && $canDo->get('core.edit.state')) { - /** @var DropdownButton $dropdown */ - $dropdown = $toolbar->dropdownButton('status-group', 'JTOOLBAR_CHANGE_STATUS') - ->toggleSplit(false) - ->icon('icon-ellipsis-h') - ->buttonClass('btn btn-action') - ->listCheck(true); - - $childBar = $dropdown->getChildToolbar(); - - $childBar->publish('contacts.publish')->listCheck(true); - $childBar->unpublish('contacts.unpublish')->listCheck(true); - $childBar->standardButton('featured', 'JFEATURE', 'contacts.featured') - ->listCheck(true); - $childBar->standardButton('unfeatured', 'JUNFEATURE', 'contacts.unfeatured') - ->listCheck(true); - $childBar->archive('contacts.archive')->listCheck(true); - - if ($user->authorise('core.admin')) { - $childBar->checkin('contacts.checkin'); - } - - if ($this->state->get('filter.published') != -2) { - $childBar->trash('contacts.trash')->listCheck(true); - } - - // Add a batch button - if ( - $user->authorise('core.create', 'com_contact') - && $user->authorise('core.edit', 'com_contact') - && $user->authorise('core.edit.state', 'com_contact') - ) { - $childBar->popupButton('batch', 'JTOOLBAR_BATCH') - ->popupType('inline') - ->textHeader(Text::_('COM_CONTACT_BATCH_OPTIONS')) - ->url('#joomla-dialog-batch') - ->modalWidth('800px') - ->modalHeight('fit-content') - ->listCheck(true); - } - } - - if (!$this->isEmptyState && $this->state->get('filter.published') == -2 && $canDo->get('core.delete')) { - $toolbar->delete('contacts.delete', 'JTOOLBAR_DELETE_FROM_TRASH') - ->message('JGLOBAL_CONFIRM_DELETE') - ->listCheck(true); - } - - if ($user->authorise('core.admin', 'com_contact') || $user->authorise('core.options', 'com_contact')) { - $toolbar->preferences('com_contact'); - } - - $toolbar->help('Contacts'); + // Add form control fields + $this->filterForm + ->addControlField('task', '') + ->addControlField('boxchecked', '0'); } } diff --git a/administrator/components/com_modules/src/View/Modules/HtmlView.php b/administrator/components/com_modules/src/View/Modules/HtmlView.php index 7d86dda63a8c6..2538f6003ca1f 100644 --- a/administrator/components/com_modules/src/View/Modules/HtmlView.php +++ b/administrator/components/com_modules/src/View/Modules/HtmlView.php @@ -14,12 +14,8 @@ use Joomla\CMS\Helper\ContentHelper; use Joomla\CMS\Helper\ModuleHelper; use Joomla\CMS\Language\Multilanguage; -use Joomla\CMS\Language\Text; -use Joomla\CMS\MVC\View\GenericDataException; -use Joomla\CMS\MVC\View\HtmlView as BaseHtmlView; -use Joomla\CMS\Toolbar\Button\DropdownButton; -use Joomla\CMS\Toolbar\ToolbarHelper; -use Joomla\Component\Modules\Administrator\Model\ModulesModel; +use Joomla\CMS\MVC\Model\ListModel; +use Joomla\CMS\MVC\View\ListView; // phpcs:disable PSR1.Files.SideEffects \defined('_JEXEC') or die; @@ -30,79 +26,61 @@ * * @since 1.6 */ -class HtmlView extends BaseHtmlView +class HtmlView extends ListView { /** - * An array of items + * The client ID for the modules we're showing * - * @var array - */ - protected $items; - - /** - * The pagination object + * @var int * - * @var \Joomla\CMS\Pagination\Pagination + * @since __DEPLOY_VERSION__ */ - protected $pagination; + protected $clientId; /** - * The model state + * The help link for the view * - * @var \Joomla\Registry\Registry + * @var string */ - protected $state; + protected $helpLink = 'Modules'; /** - * Form object for search filters + * Constructor * - * @var \Joomla\CMS\Form\Form - * - * @since 4.0.0 + * @param array $config An optional associative array of configuration settings. */ - public $filterForm; + public function __construct(array $config) + { + if (empty($config['option'])) { + $config['option'] = 'com_modules'; + } - /** - * The active search filters - * - * @var array - * @since 4.0.0 - */ - public $activeFilters; + $config['toolbar_icon'] = 'cube module'; + $config['supports_batch'] = true; - /** - * Is this view an Empty State - * - * @var boolean - * @since 4.0.0 - */ - private $isEmptyState = false; + parent::__construct($config); + } /** - * Display the view - * - * @param string $tpl The name of the template file to parse; automatically searches through the template paths. + * Prepare view data * * @return void - * - * @since 1.6 */ - public function display($tpl = null) + protected function initializeView() { - /** @var ModulesModel $model */ + parent::initializeView(); + + /** + * @var ListModel + */ $model = $this->getModel(); - $this->items = $model->getItems(); - $this->pagination = $model->getPagination(); - $this->state = $model->getState(); $this->total = $model->getTotal(); - $this->filterForm = $model->getFilterForm(); - $this->activeFilters = $model->getActiveFilters(); - $this->clientId = $this->state->get('client_id'); + $this->clientId = (int) $this->state->get('client_id', 0); - if (!\count($this->items) && $this->isEmptyState = $model->getIsEmptyState()) { - $this->setLayout('emptystate'); - } + $this->canDo = ContentHelper::getActions('com_modules'); + + $this->toolbarTitle = $this->clientId == 1 ? 'COM_MODULES_MANAGER_MODULES_ADMIN' : 'COM_MODULES_MANAGER_MODULES_SITE'; /** * The code below make sure the remembered position will be available from filter dropdown even if there are no @@ -129,11 +107,6 @@ public function display($tpl = null) } } - // Check for errors. - if (\count($errors = $model->getErrors())) { - throw new GenericDataException(implode("\n", $errors), 500); - } - // We do not need the Language filter when modules are not filtered if ($this->clientId == 1 && !ModuleHelper::isAdminMultilang()) { unset($this->activeFilters['language']); @@ -142,8 +115,6 @@ public function display($tpl = null) // We don't need the toolbar in the modal window. if ($this->getLayout() !== 'modal') { - $this->addToolbar(); - // We do not need to filter by language when multilingual is disabled if (!Multilanguage::isEnabled()) { unset($this->activeFilters['language']); @@ -164,8 +135,6 @@ public function display($tpl = null) $this->filterForm ->addControlField('task', '') ->addControlField('boxchecked', '0'); - - parent::display($tpl); } /** @@ -177,78 +146,43 @@ public function display($tpl = null) */ protected function addToolbar() { - $state = $this->state; - $canDo = ContentHelper::getActions('com_modules'); + $canDo = $this->canDo; $user = $this->getCurrentUser(); - // Get the toolbar object instance - $toolbar = $this->getDocument()->getToolbar(); + $canCreate = $canDo->get('core.create'); - if ($state->get('client_id') == 1) { - ToolbarHelper::title(Text::_('COM_MODULES_MANAGER_MODULES_ADMIN'), 'cube module'); - } else { - ToolbarHelper::title(Text::_('COM_MODULES_MANAGER_MODULES_SITE'), 'cube module'); + if ($canCreate) { + $this->getDocument()->getToolbar()->standardButton('new', 'JTOOLBAR_NEW') + ->onclick("location.href='index.php?option=com_modules&view=select&client_id=" . $this->clientId . "'"); } - if ($canDo->get('core.create')) { - $toolbar->standardButton('new', 'JTOOLBAR_NEW') - ->onclick("location.href='index.php?option=com_modules&view=select&client_id=" . $this->state->get('client_id', 0) . "'"); - } + // Prevent showing default add button + $canDo->set('core.create', false); - if (!$this->isEmptyState && ($canDo->get('core.edit.state') || $this->getCurrentUser()->authorise('core.admin'))) { - /** @var DropdownButton $dropdown */ - $dropdown = $toolbar->dropdownButton('status-group', 'JTOOLBAR_CHANGE_STATUS') - ->toggleSplit(false) - ->icon('icon-ellipsis-h') - ->buttonClass('btn btn-action') - ->listCheck(true); + parent::addToolbar(); - $childBar = $dropdown->getChildToolbar(); + $canDo->set('core.create', $canCreate); - if ($canDo->get('core.edit.state')) { - $childBar->publish('modules.publish')->listCheck(true); + // We add the duplicate button if there is the default dropdown + if ($canCreate) { - $childBar->unpublish('modules.unpublish')->listCheck(true); - } + /** + * @var \Joomla\CMS\Toolbar\Toolbar $toolbar + */ + $toolbar = $this->getDocument()->getToolbar(); - if ($this->getCurrentUser()->authorise('core.admin')) { - $childBar->checkin('modules.checkin')->listCheck(true); - } + $buttons = $toolbar->getItems(); - if ($canDo->get('core.edit.state') && $this->state->get('filter.published') != -2) { - $childBar->trash('modules.trash')->listCheck(true); - } + foreach ($buttons as $button) { + if ($button->getName() === 'status-group') { + $childBar = $button->getChildToolbar(); - // Add a batch button - if ( - $user->authorise('core.create', 'com_modules') && $user->authorise('core.edit', 'com_modules') - && $user->authorise('core.edit.state', 'com_modules') - ) { - $childBar->popupButton('batch', 'JTOOLBAR_BATCH') - ->popupType('inline') - ->textHeader(Text::_('COM_MODULES_BATCH_OPTIONS')) - ->url('#joomla-dialog-batch') - ->modalWidth('800px') - ->modalHeight('fit-content') - ->listCheck(true); - } + $childBar->standardButton('copy', 'JTOOLBAR_DUPLICATE', 'modules.duplicate') + ->listCheck(true); - if ($canDo->get('core.create')) { - $childBar->standardButton('copy', 'JTOOLBAR_DUPLICATE', 'modules.duplicate') - ->listCheck(true); + break; + } } } - - if (!$this->isEmptyState && ($state->get('filter.state') == -2 && $canDo->get('core.delete'))) { - $toolbar->delete('modules.delete', 'JTOOLBAR_DELETE_FROM_TRASH') - ->message('JGLOBAL_CONFIRM_DELETE') - ->listCheck(true); - } - - if ($canDo->get('core.admin')) { - $toolbar->preferences('com_modules'); - } - - $toolbar->help('Modules'); } } diff --git a/libraries/src/MVC/View/ListView.php b/libraries/src/MVC/View/ListView.php index e36f955f986dc..bc7ed2a94c564 100644 --- a/libraries/src/MVC/View/ListView.php +++ b/libraries/src/MVC/View/ListView.php @@ -12,7 +12,6 @@ use Doctrine\Inflector\InflectorFactory; use Joomla\CMS\HTML\HTMLHelper; use Joomla\CMS\Language\Text; -use Joomla\CMS\Layout\FileLayout; use Joomla\CMS\Toolbar\ToolbarHelper; use Joomla\Registry\Registry; @@ -34,7 +33,7 @@ class ListView extends HtmlView * * @var array */ - protected $items; + protected $items = []; /** * The pagination object @@ -69,7 +68,7 @@ class ListView extends HtmlView * * @var array */ - public $activeFilters; + public $activeFilters = []; /** * The sidebar markup @@ -92,6 +91,13 @@ class ListView extends HtmlView */ protected $toolbarIcon; + /** + * The flag which determine whether we want to show archive button + * + * @var boolean + */ + protected $supportsArchive = false; + /** * The flag which determine whether we want to show batch button * @@ -99,6 +105,15 @@ class ListView extends HtmlView */ protected $supportsBatch = true; + /** + * Holds the extension for categories, if available + * + * @var string + * + * @since __DEPLOY_VERSION__ + */ + protected $categorySection; + /** * The help link for the view * @@ -106,6 +121,15 @@ class ListView extends HtmlView */ protected $helpLink; + /** + * Is this view an Empty State + * + * @var boolean + * + * @since __DEPLOY_VERSION__ + */ + private $isEmptyState = false; + /** * Constructor * @@ -132,6 +156,10 @@ public function __construct(array $config) $this->supportsBatch = $config['supports_batch']; } + if (isset($config['category'])) { + $this->categorySection = $config['category']; + } + if (isset($config['help_link'])) { $this->helpLink = $config['help_link']; } @@ -155,13 +183,23 @@ public function display($tpl = null) // Prepare view data $this->initializeView(); + $model = $this->getModel(); + + $errors = $model->getErrors(); + // Check for errors. - if (\count($errors = $this->get('Errors'))) { + if (!empty($errors)) { throw new GenericDataException(implode("\n", $errors), 500); } - // Build toolbar - $this->addToolbar(); + if (!\count($this->items) && \is_callable([$model, 'IsEmptyState']) && $this->isEmptyState = $model->getIsEmptyState()) { + $this->setLayout('emptystate'); + } + + // We don't need toolbar in the modal window. + if ($this->getLayout() !== 'modal') { + $this->addToolbar(); + } parent::display($tpl); } @@ -187,11 +225,13 @@ protected function initializeView() $this->sidebar = HTMLHelper::_('sidebar.render'); } - $this->items = $this->get('Items'); - $this->pagination = $this->get('Pagination'); - $this->state = $this->get('State'); - $this->filterForm = $this->get('FilterForm'); - $this->activeFilters = $this->get('ActiveFilters'); + $model = $this->getModel(); + + $this->items = $model->getItems(); + $this->pagination = $model->getPagination(); + $this->state = $model->getState(); + $this->filterForm = $model->getFilterForm(); + $this->activeFilters = $model->getActiveFilters(); } /** @@ -206,68 +246,86 @@ protected function addToolbar() $canDo = $this->canDo; $user = $this->getCurrentUser(); - // Get the toolbar object instance - $bar = $this->getDocument()->getToolbar(); + /** + * @var Toolbar $toolbar + */ + $toolbar = $this->getDocument()->getToolbar(); $viewName = $this->getName(); $singularViewName = InflectorFactory::create()->build()->singularize($viewName); ToolbarHelper::title(Text::_($this->toolbarTitle), $this->toolbarIcon); - if ($canDo->get('core.create')) { - ToolbarHelper::addNew($singularViewName . '.add'); + // @todo here we should add category support with some parameters + if ($canDo->get('core.create') || (isset($this->categorySection) && \count($user->getAuthorisedCategories($this->categorySection, 'core.create')) > 0)) { + $toolbar->addNew($singularViewName . '.add'); } - if (($canDo->get('core.edit')) || ($canDo->get('core.edit.own'))) { - ToolbarHelper::editList($singularViewName . '.edit'); - } + if (!$this->isEmptyState && $canDo->get('core.edit.state')) { + /** @var DropdownButton $dropdown */ + $dropdown = $toolbar->dropdownButton('status-group', 'JTOOLBAR_CHANGE_STATUS') + ->toggleSplit(false) + ->icon('icon-ellipsis-h') + ->buttonClass('btn btn-action') + ->listCheck(true); - if ($canDo->get('core.edit.state')) { - ToolbarHelper::publish($viewName . '.publish', 'JTOOLBAR_PUBLISH', true); - ToolbarHelper::unpublish($viewName . '.unpublish', 'JTOOLBAR_UNPUBLISH', true); + $childBar = $dropdown->getChildToolbar(); + + $childBar->publish($viewName . '.publish')->listCheck(true); + $childBar->unpublish($viewName . '.unpublish')->listCheck(true); if (isset($this->items[0]->featured)) { - ToolbarHelper::custom($viewName . '.featured', 'featured', '', 'JFEATURE', true); - ToolbarHelper::custom($viewName . '.unfeatured', 'unfeatured', '', 'JUNFEATURE', true); + $childBar->standardButton('featured', 'JFEATURE', $viewName . '.featured')->listCheck(true); + $childBar->standardButton('unfeatured', 'JUNFEATURE', $viewName . '.unfeatured')->listCheck(true); } - ToolbarHelper::archiveList($viewName . '.archive'); - ToolbarHelper::checkin($viewName . '.checkin'); - } + if ($this->supportsArchive) { + $childBar->archive($viewName . '.archive')->listCheck(true); + } - // Add a batch button - if ( - $this->supportsBatch && $user->authorise('core.create', $this->option) - && $user->authorise('core.edit', $this->option) - && $user->authorise('core.edit.state', $this->option) - ) { - $title = Text::_('JTOOLBAR_BATCH'); + if ($user->authorise('core.admin')) { + $childBar->checkin($viewName . '.checkin'); + } - // Instantiate a new LayoutFile instance and render the popup button - $layout = new FileLayout('joomla.toolbar.popup'); + if ($this->state->get('filter.published') != -2) { + $childBar->trash($viewName . '.trash')->listCheck(true); + } - $dhtml = $layout->render(['title' => $title]); - $bar->appendButton('Custom', $dhtml, 'batch'); + // Add a batch button + if ( + $this->supportsBatch && $user->authorise('core.create', $this->option) + && $user->authorise('core.create', $this->option) + && $user->authorise('core.edit', $this->option) + ) { + $childBar->popupButton('batch', 'JTOOLBAR_BATCH') + ->popupType('inline') + ->textHeader(Text::_($this->option . '_BATCH_OPTIONS')) + ->url('#joomla-dialog-batch') + ->modalWidth('800px') + ->modalHeight('fit-content') + ->listCheck(true); + } } if ( - $canDo->get('core.delete') && - ( - $this->state->get('filter.state') == -2 || - $this->state->get('filter.published') == -2 + !$this->isEmptyState + && $canDo->get('core.delete') + && ( + $this->state->get('filter.state') == -2 + || $this->state->get('filter.published') == -2 ) ) { - ToolbarHelper::deleteList('JGLOBAL_CONFIRM_DELETE', $viewName . '.delete', 'JTOOLBAR_DELETE_FROM_TRASH'); - } elseif ($canDo->get('core.edit.state')) { - ToolbarHelper::trash($viewName . '.trash'); + $toolbar->delete($viewName . '.delete', 'JTOOLBAR_DELETE_FROM_TRASH') + ->message('JGLOBAL_CONFIRM_DELETE') + ->listCheck(true); } if ($user->authorise('core.admin', $this->option) || $user->authorise('core.options', $this->option)) { - ToolbarHelper::preferences($this->option); + $toolbar->preferences($this->option); } if ($this->helpLink) { - ToolbarHelper::help($this->helpLink); + $toolbar->help($this->helpLink); } } } diff --git a/phpstan-baseline.neon b/phpstan-baseline.neon index a60bae831b7cb..1b496ee56a201 100644 --- a/phpstan-baseline.neon +++ b/phpstan-baseline.neon @@ -79,17 +79,6 @@ parameters: count: 1 path: administrator/components/com_actionlogs/src/Plugin/ActionLogPlugin.php - - - message: ''' - #^Call to deprecated method getErrors\(\) of class Joomla\\CMS\\MVC\\Model\\BaseModel\: - 3\.1\.4 will be removed in 7\.0 - Will be removed without replacement - Catch thrown Exceptions instead of getErrors$# - ''' - identifier: method.deprecated - count: 1 - path: administrator/components/com_actionlogs/src/View/Actionlogs/HtmlView.php - - message: '#^Access to property \$dateRelative on an unknown class HtmlView\.$#' identifier: class.notFound @@ -613,17 +602,6 @@ parameters: count: 1 path: administrator/components/com_banners/src/View/Banner/HtmlView.php - - - message: ''' - #^Call to deprecated method getErrors\(\) of class Joomla\\CMS\\MVC\\Model\\BaseModel\: - 3\.1\.4 will be removed in 7\.0 - Will be removed without replacement - Catch thrown Exceptions instead of getErrors$# - ''' - identifier: method.deprecated - count: 1 - path: administrator/components/com_banners/src/View/Banners/HtmlView.php - - message: ''' #^Call to deprecated method getErrors\(\) of class Joomla\\CMS\\MVC\\Model\\BaseModel\: @@ -1354,17 +1332,6 @@ parameters: count: 1 path: administrator/components/com_contact/src/View/Contact/HtmlView.php - - - message: ''' - #^Call to deprecated method getErrors\(\) of class Joomla\\CMS\\MVC\\Model\\BaseModel\: - 3\.1\.4 will be removed in 7\.0 - Will be removed without replacement - Catch thrown Exceptions instead of getErrors$# - ''' - identifier: method.deprecated - count: 1 - path: administrator/components/com_contact/src/View/Contacts/HtmlView.php - - message: '#^Access to an undefined property Joomla\\Component\\Contact\\Administrator\\View\\Contact\\HtmlView\:\:\$useCoreUI\.$#' identifier: property.notFound @@ -4775,29 +4742,12 @@ parameters: count: 1 path: administrator/components/com_modules/src/View/Module/HtmlView.php - - - message: '#^Access to an undefined property Joomla\\Component\\Modules\\Administrator\\View\\Modules\\HtmlView\:\:\$clientId\.$#' - identifier: property.notFound - count: 1 - path: administrator/components/com_modules/src/View/Modules/HtmlView.php - - message: '#^Access to an undefined property Joomla\\Component\\Modules\\Administrator\\View\\Modules\\HtmlView\:\:\$total\.$#' identifier: property.notFound count: 1 path: administrator/components/com_modules/src/View/Modules/HtmlView.php - - - message: ''' - #^Call to deprecated method getErrors\(\) of class Joomla\\CMS\\MVC\\Model\\BaseModel\: - 3\.1\.4 will be removed in 7\.0 - Will be removed without replacement - Catch thrown Exceptions instead of getErrors$# - ''' - identifier: method.deprecated - count: 1 - path: administrator/components/com_modules/src/View/Modules/HtmlView.php - - message: ''' #^Call to deprecated method getErrors\(\) of class Joomla\\CMS\\MVC\\Model\\BaseModel\: @@ -4839,12 +4789,6 @@ parameters: count: 1 path: administrator/components/com_modules/tmpl/modules/default.php - - - message: '#^Access to an undefined property Joomla\\Component\\Modules\\Administrator\\View\\Modules\\HtmlView\:\:\$clientId\.$#' - identifier: property.notFound - count: 3 - path: administrator/components/com_modules/tmpl/modules/emptystate.php - - message: '#^Access to an undefined property Joomla\\Component\\Modules\\Administrator\\View\\Modules\\HtmlView\:\:\$total\.$#' identifier: property.notFound @@ -14024,13 +13968,13 @@ parameters: - message: ''' - #^Call to deprecated method get\(\) of class Joomla\\CMS\\MVC\\View\\AbstractView\: - 5\.3\.0 will be removed in 7\.0\. - Retrieve the model with \$model \= \$this\-\>getModel\(\); and call the methods - to the model directly, e\.g\. \$model\-\>getItems\(\) instead of \$this\-\>get\('Items'\)\.$# + #^Call to deprecated method getErrors\(\) of class Joomla\\CMS\\MVC\\Model\\BaseModel\: + 3\.1\.4 will be removed in 7\.0 + Will be removed without replacement + Catch thrown Exceptions instead of getErrors$# ''' identifier: method.deprecated - count: 6 + count: 1 path: libraries/src/MVC/View/ListView.php -