diff --git a/administrator/components/com_modules/Extension/ModulesComponent.php b/administrator/components/com_modules/Extension/ModulesComponent.php new file mode 100644 index 0000000000000..a1bdc82ff21ce --- /dev/null +++ b/administrator/components/com_modules/Extension/ModulesComponent.php @@ -0,0 +1,46 @@ +getRegistry()->register('modules', new Modules); + } +} diff --git a/administrator/components/com_modules/helpers/html/modules.php b/administrator/components/com_modules/Service/HTML/Modules.php similarity index 73% rename from administrator/components/com_modules/helpers/html/modules.php rename to administrator/components/com_modules/Service/HTML/Modules.php index 1c506d2976a31..3310715472a49 100644 --- a/administrator/components/com_modules/helpers/html/modules.php +++ b/administrator/components/com_modules/Service/HTML/Modules.php @@ -7,17 +7,23 @@ * @license GNU General Public License version 2 or later; see LICENSE.txt */ +namespace Joomla\Component\Modules\Administrator\Service\HTML; + defined('_JEXEC') or die; +use Joomla\CMS\Factory; +use Joomla\CMS\HTML\HTMLHelper; +use Joomla\CMS\Language\Text; +use Joomla\Component\Templates\Administrator\Helper\TemplatesHelper; use Joomla\Utilities\ArrayHelper; use Joomla\Component\Modules\Administrator\Helper\ModulesHelper; /** - * JHtml module helper class. + * HTMLHelper module helper class. * * @since 1.6 */ -abstract class JHtmlModules +class Modules { /** * Builds an array of template options @@ -27,14 +33,14 @@ abstract class JHtmlModules * * @return array */ - public static function templates($clientId = 0, $state = '') + public function templates($clientId = 0, $state = '') { $options = array(); $templates = ModulesHelper::getTemplates($clientId, $state); foreach ($templates as $template) { - $options[] = JHtml::_('select.option', $template->element, $template->name); + $options[] = HTMLHelper::_('select.option', $template->element, $template->name); } return $options; @@ -45,11 +51,11 @@ public static function templates($clientId = 0, $state = '') * * @return array */ - public static function types() + public function types() { $options = array(); - $options[] = JHtml::_('select.option', 'user', 'COM_MODULES_OPTION_POSITION_USER_DEFINED'); - $options[] = JHtml::_('select.option', 'template', 'COM_MODULES_OPTION_POSITION_TEMPLATE_DEFINED'); + $options[] = HTMLHelper::_('select.option', 'user', 'COM_MODULES_OPTION_POSITION_USER_DEFINED'); + $options[] = HTMLHelper::_('select.option', 'template', 'COM_MODULES_OPTION_POSITION_TEMPLATE_DEFINED'); return $options; } @@ -59,11 +65,11 @@ public static function types() * * @return array */ - public static function templateStates() + public function templateStates() { $options = array(); - $options[] = JHtml::_('select.option', '1', 'JENABLED'); - $options[] = JHtml::_('select.option', '0', 'JDISABLED'); + $options[] = HTMLHelper::_('select.option', '1', 'JENABLED'); + $options[] = HTMLHelper::_('select.option', '0', 'JDISABLED'); return $options; } @@ -78,10 +84,10 @@ public static function templateStates() * * @return string The Html code * - * @see JHtmlJGrid::state + * @see HTMLHelperJGrid::state * @since 1.7.1 */ - public static function state($value, $i, $enabled = true, $checkbox = 'cb') + public function state($value, $i, $enabled = true, $checkbox = 'cb') { $states = array( 1 => array( @@ -122,7 +128,7 @@ public static function state($value, $i, $enabled = true, $checkbox = 'cb') ), ); - return JHtml::_('jgrid.state', $states, $value, $i, 'modules.', $enabled, true, $checkbox); + return HTMLHelper::_('jgrid.state', $states, $value, $i, 'modules.', $enabled, true, $checkbox); } /** @@ -136,9 +142,9 @@ public static function state($value, $i, $enabled = true, $checkbox = 'cb') * * @since 2.5 */ - public static function positions($clientId, $state = 1, $selectedPosition = '') + public function positions($clientId, $state = 1, $selectedPosition = '') { - JLoader::register('TemplatesHelper', JPATH_ADMINISTRATOR . '/components/com_templates/helpers/templates.php'); + \JLoader::register('TemplatesHelper', JPATH_ADMINISTRATOR . '/components/com_templates/helpers/templates.php'); $templates = array_keys(ModulesHelper::getTemplates($clientId, $state)); $templateGroups = array(); @@ -176,7 +182,7 @@ public static function positions($clientId, $state = 1, $selectedPosition = '') } // Add custom position to options - $customGroupText = JText::_('COM_MODULES_CUSTOM_POSITION'); + $customGroupText = Text::_('COM_MODULES_CUSTOM_POSITION'); $editPositions = true; $customPositions = ModulesHelper::getPositions($clientId, $editPositions); @@ -190,15 +196,15 @@ public static function positions($clientId, $state = 1, $selectedPosition = '') * * @return void */ - public static function batchOptions() + public function batchOptions() { // Create the copy/move options. $options = array( - JHtml::_('select.option', 'c', JText::_('JLIB_HTML_BATCH_COPY')), - JHtml::_('select.option', 'm', JText::_('JLIB_HTML_BATCH_MOVE')) + HTMLHelper::_('select.option', 'c', Text::_('JLIB_HTML_BATCH_COPY')), + HTMLHelper::_('select.option', 'm', Text::_('JLIB_HTML_BATCH_MOVE')) ); - echo JHtml::_('select.radiolist', $options, 'batch[move_copy]', '', 'value', 'text', 'm'); + echo HTMLHelper::_('select.radiolist', $options, 'batch[move_copy]', '', 'value', 'text', 'm'); } /** @@ -210,9 +216,9 @@ public static function batchOptions() * * @since 2.5 */ - public static function positionList($clientId = 0) + public function positionList($clientId = 0) { - $db = JFactory::getDbo(); + $db = Factory::getDbo(); $query = $db->getQuery(true) ->select('DISTINCT(position) as value') ->select('position as text') @@ -227,9 +233,9 @@ public static function positionList($clientId = 0) { $options = $db->loadObjectList(); } - catch (RuntimeException $e) + catch (\RuntimeException $e) { - JFactory::getApplication()->enqueueMessage($e->getMessage(), 'error'); + Factory::getApplication()->enqueueMessage($e->getMessage(), 'error'); } // Pop the first item off the array if it's blank diff --git a/administrator/components/com_modules/helpers/modules.php b/administrator/components/com_modules/helpers/modules.php index 92ae54d90b2d7..f80a5ee3361cf 100644 --- a/administrator/components/com_modules/helpers/modules.php +++ b/administrator/components/com_modules/helpers/modules.php @@ -12,7 +12,9 @@ /** * Modules component helper. * - * @since 1.6 + * @since 1.6 + * + * @deprecated 5.0 Use \Joomla\Component\Modules\Administrator\Helper\ModulesHelper instead */ abstract class ModulesHelper extends \Joomla\Component\Modules\Administrator\Helper\ModulesHelper { diff --git a/administrator/components/com_modules/services/provider.php b/administrator/components/com_modules/services/provider.php index 62f0535790ae0..a1dee3e0c8b26 100644 --- a/administrator/components/com_modules/services/provider.php +++ b/administrator/components/com_modules/services/provider.php @@ -14,7 +14,9 @@ use Joomla\CMS\Extension\MVCComponent; use Joomla\CMS\Extension\Service\Provider\DispatcherFactory; use Joomla\CMS\Extension\Service\Provider\MVCFactoryFactory; +use Joomla\CMS\HTML\Registry; use Joomla\CMS\MVC\Factory\MVCFactoryFactoryInterface; +use Joomla\Component\Modules\Administrator\Extension\ModulesComponent; use Joomla\DI\Container; use Joomla\DI\ServiceProviderInterface; @@ -43,9 +45,10 @@ public function register(Container $container) ComponentInterface::class, function (Container $container) { - $component = new MVCComponent($container->get(DispatcherFactoryInterface::class)); + $component = new ModulesComponent($container->get(DispatcherFactoryInterface::class)); $component->setMvcFactoryFactory($container->get(MVCFactoryFactoryInterface::class)); + $component->setRegistry($container->get(Registry::class)); return $component; } diff --git a/components/com_modules/dispatcher.php b/components/com_modules/Dispatcher/Dispatcher.php similarity index 71% rename from components/com_modules/dispatcher.php rename to components/com_modules/Dispatcher/Dispatcher.php index c51d368607240..ab3e42f616f00 100644 --- a/components/com_modules/dispatcher.php +++ b/components/com_modules/Dispatcher/Dispatcher.php @@ -1,33 +1,26 @@ input->get('view') === 'modules' && $this->input->get('layout') === 'modal') + if ($this->input->get('view') === 'modules' + && $this->input->get('layout') === 'modal' + && !$this->app->getIdentity()->authorise('core.create', 'com_modules')) { - if (!$this->app->getIdentity()->authorise('core.create', 'com_modules')) - { - $this->app->enqueueMessage(JText::_('JERROR_ALERTNOAUTHOR'), 'warning'); - - return; - } + throw new NotAllowed; } parent::dispatch();