diff --git a/administrator/components/com_content/helpers/html/contentadministrator.php b/administrator/components/com_content/Service/HTML/AdministratorService.php similarity index 71% rename from administrator/components/com_content/helpers/html/contentadministrator.php rename to administrator/components/com_content/Service/HTML/AdministratorService.php index bafc3998da6e5..588c9e746c608 100644 --- a/administrator/components/com_content/helpers/html/contentadministrator.php +++ b/administrator/components/com_content/Service/HTML/AdministratorService.php @@ -7,19 +7,26 @@ * @license GNU General Public License version 2 or later; see LICENSE.txt */ +namespace Joomla\Component\Content\Administrator\Service\HTML; + defined('_JEXEC') or die; +use Joomla\CMS\Factory; +use Joomla\CMS\HTML\HTMLHelper; +use Joomla\CMS\Language\Associations; +use Joomla\CMS\Language\Text; +use Joomla\CMS\Layout\LayoutHelper; +use Joomla\CMS\Router\Route; use Joomla\Utilities\ArrayHelper; -JLoader::register('ContentHelper', JPATH_ADMINISTRATOR . '/components/com_content/helpers/content.php'); - /** * Content HTML helper * * @since 3.0 */ -abstract class JHtmlContentAdministrator +class AdministratorService { + /** * Render the list of associated items * @@ -27,15 +34,15 @@ abstract class JHtmlContentAdministrator * * @return string The language HTML * - * @throws Exception + * @throws \Exception */ - public static function association($articleid) + public function association($articleid) { // Defaults $html = ''; // Get the associations - if ($associations = JLanguageAssociations::getAssociations('com_content', '#__content', 'com_content.item', $articleid)) + if ($associations = Associations::getAssociations('com_content', '#__content', 'com_content.item', $articleid)) { foreach ($associations as $tag => $associated) { @@ -43,7 +50,7 @@ public static function association($articleid) } // Get the associated menu items - $db = JFactory::getDbo(); + $db = Factory::getDbo(); $query = $db->getQuery(true) ->select('c.*') ->select('l.sef as lang_sef') @@ -62,9 +69,9 @@ public static function association($articleid) { $items = $db->loadObjectList('id'); } - catch (RuntimeException $e) + catch (\RuntimeException $e) { - throw new Exception($e->getMessage(), 500, $e); + throw new \Exception($e->getMessage(), 500, $e); } if ($items) @@ -72,8 +79,8 @@ public static function association($articleid) foreach ($items as &$item) { $text = $item->lang_sef ? strtoupper($item->lang_sef) : 'XX'; - $url = JRoute::_('index.php?option=com_content&task=article.edit&id=' . (int) $item->id); - $tooltip = htmlspecialchars($item->title, ENT_QUOTES, 'UTF-8') . '
' . JText::sprintf('JCATEGORY_SPRINTF', $item->category_title); + $url = Route::_('index.php?option=com_content&task=article.edit&id=' . (int) $item->id); + $tooltip = htmlspecialchars($item->title, ENT_QUOTES, 'UTF-8') . '
' . Text::sprintf('JCATEGORY_SPRINTF', $item->category_title); $classes = 'hasPopover badge badge-secondary'; $item->link = ''; } else { $html = ''; + . HTMLHelper::_('tooltipText', $state[2]) . '">'; } return $html; diff --git a/administrator/components/com_content/Service/HTML/Icon.php b/administrator/components/com_content/Service/HTML/Icon.php new file mode 100644 index 0000000000000..86ec71ed23cb0 --- /dev/null +++ b/administrator/components/com_content/Service/HTML/Icon.php @@ -0,0 +1,248 @@ +application = $application; + } + + /** + * Method to generate a link to the create item page for the given category + * + * @param object $category The category information + * @param Registry $params The item parameters + * @param array $attribs Optional attributes for the link + * @param boolean $legacy True to use legacy images, false to use icomoon based graphic + * + * @return string The HTML markup for the create item link + * + * @since __DEPLOY_VERSION__ + */ + public function create($category, $params, $attribs = array(), $legacy = false) + { + $uri = Uri::getInstance(); + + $url = 'index.php?option=com_content&task=article.add&return=' . base64_encode($uri) . '&a_id=0&catid=' . $category->id; + + $text = LayoutHelper::render('joomla.content.icons.create', array('params' => $params, 'legacy' => $legacy)); + + // Add the button classes to the attribs array + if (isset($attribs['class'])) + { + $attribs['class'] .= ' btn btn-primary'; + } + else + { + $attribs['class'] = 'btn btn-primary'; + } + + $button = HTMLHelper::_('link', Route::_($url), $text, $attribs); + + $output = '' . $button . ''; + + return $output; + } + + /** + * Method to generate a link to the email item page for the given article + * + * @param object $article The article information + * @param Registry $params The item parameters + * @param array $attribs Optional attributes for the link + * @param boolean $legacy True to use legacy images, false to use icomoon based graphic + * + * @return string The HTML markup for the email item link + * + * @since __DEPLOY_VERSION__ + */ + public function email($article, $params, $attribs = array(), $legacy = false) + { + \JLoader::register('MailtoHelper', JPATH_SITE . '/components/com_mailto/helpers/mailto.php'); + + $uri = Uri::getInstance(); + $base = $uri->toString(array('scheme', 'host', 'port')); + $template = $this->application->getTemplate(); + $link = $base . Route::_(\ContentHelperRoute::getArticleRoute($article->slug, $article->catid, $article->language), false); + $url = 'index.php?option=com_mailto&tmpl=component&template=' . $template . '&link=' . \MailtoHelper::addLink($link); + + $status = 'width=400,height=350,menubar=yes,resizable=yes'; + + $text = LayoutHelper::render('joomla.content.icons.email', array('params' => $params, 'legacy' => $legacy)); + + $attribs['title'] = Text::_('JGLOBAL_EMAIL_TITLE'); + $attribs['onclick'] = "window.open(this.href,'win2','" . $status . "'); return false;"; + $attribs['rel'] = 'nofollow'; + $attribs['class'] = 'dropdown-item'; + + return HTMLHelper::_('link', Route::_($url), $text, $attribs); + } + + /** + * Display an edit icon for the article. + * + * This icon will not display in a popup window, nor if the article is trashed. + * Edit access checks must be performed in the calling code. + * + * @param object $article The article information + * @param Registry $params The item parameters + * @param array $attribs Optional attributes for the link + * @param boolean $legacy True to use legacy images, false to use icomoon based graphic + * + * @return string The HTML for the article edit icon. + * + * @since __DEPLOY_VERSION__ + */ + public function edit($article, $params, $attribs = array(), $legacy = false) + { + $user = JFactory::getUser(); + $uri = JUri::getInstance(); + + // Ignore if in a popup window. + if ($params && $params->get('popup')) + { + return; + } + + // Ignore if the state is negative (trashed). + if ($article->state < 0) + { + return; + } + + // Set the link class + $attribs['class'] = 'dropdown-item'; + + // Show checked_out icon if the article is checked out by a different user + if (property_exists($article, 'checked_out') + && property_exists($article, 'checked_out_time') + && $article->checked_out > 0 + && $article->checked_out != $user->get('id')) + { + $checkoutUser = JFactory::getUser($article->checked_out); + $date = HTMLHelper::_('date', $article->checked_out_time); + $tooltip = Text::_('JLIB_HTML_CHECKED_OUT') . ' :: ' . Text::sprintf('COM_CONTENT_CHECKED_OUT_BY', $checkoutUser->name) + . '
' . $date; + + $text = LayoutHelper::render('joomla.content.icons.edit_lock', array('tooltip' => $tooltip, 'legacy' => $legacy)); + + $output = HTMLHelper::_('link', '#', $text, $attribs); + + return $output; + } + + $contentUrl = \ContentHelperRoute::getArticleRoute($article->slug, $article->catid, $article->language); + $url = $contentUrl . '&task=article.edit&a_id=' . $article->id . '&return=' . base64_encode($uri); + + if ($article->state == 0) + { + $overlib = Text::_('JUNPUBLISHED'); + } + else + { + $overlib = Text::_('JPUBLISHED'); + } + + $date = HTMLHelper::_('date', $article->created); + $author = $article->created_by_alias ?: $article->author; + + $overlib .= '<br>'; + $overlib .= $date; + $overlib .= '<br>'; + $overlib .= Text::sprintf('COM_CONTENT_WRITTEN_BY', htmlspecialchars($author, ENT_COMPAT, 'UTF-8')); + + $text = LayoutHelper::render('joomla.content.icons.edit', array('article' => $article, 'overlib' => $overlib, 'legacy' => $legacy)); + + $attribs['title'] = Text::_('JGLOBAL_EDIT_TITLE'); + $output = HTMLHelper::_('link', Route::_($url), $text, $attribs); + + return $output; + } + + /** + * Method to generate a popup link to print an article + * + * @param object $article The article information + * @param Registry $params The item parameters + * @param array $attribs Optional attributes for the link + * @param boolean $legacy True to use legacy images, false to use icomoon based graphic + * + * @return string The HTML markup for the popup link + * + * @since __DEPLOY_VERSION__ + */ + public function print_popup($article, $params, $attribs = array(), $legacy = false) + { + $url = \ContentHelperRoute::getArticleRoute($article->slug, $article->catid, $article->language); + $url .= '&tmpl=component&print=1&layout=default'; + + $status = 'status=no,toolbar=no,scrollbars=yes,titlebar=no,menubar=no,resizable=yes,width=640,height=480,directories=no,location=no'; + + $text = LayoutHelper::render('joomla.content.icons.print_popup', array('params' => $params, 'legacy' => $legacy)); + + $attribs['title'] = Text::sprintf('JGLOBAL_PRINT_TITLE', htmlspecialchars($article->title, ENT_QUOTES, 'UTF-8')); + $attribs['onclick'] = "window.open(this.href,'win2','" . $status . "'); return false;"; + $attribs['rel'] = 'nofollow'; + $attribs['class'] = 'dropdown-item'; + + return HTMLHelper::_('link', Route::_($url), $text, $attribs); + } + + /** + * Method to generate a link to print an article + * + * @param object $article Not used, @deprecated for 4.0 + * @param Registry $params The item parameters + * @param array $attribs Not used, @deprecated for 4.0 + * @param boolean $legacy True to use legacy images, false to use icomoon based graphic + * + * @return string The HTML markup for the popup link + * + * @since __DEPLOY_VERSION__ + */ + public function print_screen($article, $params, $attribs = array(), $legacy = false) + { + $text = LayoutHelper::render('joomla.content.icons.print_screen', array('params' => $params, 'legacy' => $legacy)); + + return '' . $text . ''; + } +} diff --git a/administrator/components/com_content/services/provider.php b/administrator/components/com_content/services/provider.php index 486c4ff12761e..37012ebd9796b 100644 --- a/administrator/components/com_content/services/provider.php +++ b/administrator/components/com_content/services/provider.php @@ -10,13 +10,17 @@ defined('_JEXEC') or die; use Joomla\CMS\Association\AssociationExtensionInterface; +use Joomla\CMS\Application\SiteApplication; use Joomla\CMS\Categories\Categories; use Joomla\CMS\Dispatcher\DispatcherFactory; use Joomla\CMS\Dispatcher\DispatcherFactoryInterface; use Joomla\CMS\Extension\Service\Provider\Component; +use Joomla\CMS\HTML\Registry; use Joomla\CMS\MVC\Factory\MVCFactoryFactory; use Joomla\CMS\MVC\Factory\MVCFactoryFactoryInterface; use Joomla\Component\Content\Administrator\Helper\AssociationsHelper; +use Joomla\Component\Content\Administrator\Service\HTML\AdministratorService; +use Joomla\Component\Content\Administrator\Service\HTML\Icon; use Joomla\Component\Content\Site\Service\Category; use Joomla\DI\Container; use Joomla\DI\ServiceProviderInterface; @@ -39,6 +43,16 @@ */ public function register(Container $container) { + /** + * @var Registry $registry + */ + $registry = $container->get(Registry::class); + $registry->register('contentadministrator', new AdministratorService); + $registry->register('contenticon', new Icon($container->get(SiteApplication::class))); + + // The layout joomla.content.icons does need a general icon service + $registry->register('icon', $registry->getService('contenticon')); + $container->set(Categories::class, ['' => new Category]); $container->set(AssociationExtensionInterface::class, new AssociationsHelper); diff --git a/administrator/components/com_content/tmpl/article/edit.php b/administrator/components/com_content/tmpl/article/edit.php index 21a66cb7ef731..79d11bb1416dc 100644 --- a/administrator/components/com_content/tmpl/article/edit.php +++ b/administrator/components/com_content/tmpl/article/edit.php @@ -11,9 +11,6 @@ use Joomla\Registry\Registry; -// Include the component HTML helpers. -JHtml::addIncludePath(JPATH_COMPONENT . '/helpers/html'); - JHtml::_('behavior.formvalidator'); JHtml::_('behavior.keepalive'); JHtml::_('formbehavior.chosen', '#jform_catid', null, array('disable_search_threshold' => 0 )); diff --git a/administrator/components/com_content/tmpl/articles/default.php b/administrator/components/com_content/tmpl/articles/default.php index 72eaef5f2b445..ebd22579a6b23 100644 --- a/administrator/components/com_content/tmpl/articles/default.php +++ b/administrator/components/com_content/tmpl/articles/default.php @@ -12,8 +12,6 @@ use Joomla\CMS\Button\ActionButton; use Joomla\CMS\Button\PublishedButton; -JHtml::addIncludePath(JPATH_COMPONENT . '/helpers/html'); - JHtml::_('behavior.multiselect'); JHtml::_('formbehavior.chosen', '.multipleTags', null, array('placeholder_text_multiple' => JText::_('JOPTION_SELECT_TAG'))); JHtml::_('formbehavior.chosen', '.multipleCategories', null, array('placeholder_text_multiple' => JText::_('JOPTION_SELECT_CATEGORY'))); diff --git a/administrator/components/com_content/tmpl/articles/modal.php b/administrator/components/com_content/tmpl/articles/modal.php index 4dc3ec05c1d9d..76b7be859ec7d 100644 --- a/administrator/components/com_content/tmpl/articles/modal.php +++ b/administrator/components/com_content/tmpl/articles/modal.php @@ -18,9 +18,6 @@ JLoader::register('ContentHelperRoute', JPATH_ROOT . '/components/com_content/helpers/route.php'); -// Include the component HTML helpers. -JHtml::addIncludePath(JPATH_COMPONENT . '/helpers/html'); - JHtml::_('behavior.core'); JHtml::_('script', 'com_content/admin-articles-modal.min.js', array('version' => 'auto', 'relative' => true)); JHtml::_('bootstrap.popover', '.hasPopover', array('placement' => 'bottom')); diff --git a/administrator/components/com_content/tmpl/featured/default.php b/administrator/components/com_content/tmpl/featured/default.php index 42db746086992..467aede1e5211 100644 --- a/administrator/components/com_content/tmpl/featured/default.php +++ b/administrator/components/com_content/tmpl/featured/default.php @@ -9,8 +9,6 @@ defined('_JEXEC') or die; -JHtml::addIncludePath(JPATH_COMPONENT . '/helpers/html'); - JHtml::_('behavior.multiselect'); JHtml::_('formbehavior.chosen', '.multipleAccessLevels', null, array('placeholder_text_multiple' => JText::_('JOPTION_SELECT_ACCESS'))); JHtml::_('formbehavior.chosen', '.multipleAuthors', null, array('placeholder_text_multiple' => JText::_('JOPTION_SELECT_AUTHOR'))); diff --git a/components/com_content/helpers/icon.php b/components/com_content/helpers/icon.php index 117c0679c74c6..d1157d399981d 100644 --- a/components/com_content/helpers/icon.php +++ b/components/com_content/helpers/icon.php @@ -27,30 +27,12 @@ abstract class JHtmlIcon * @param boolean $legacy True to use legacy images, false to use icomoon based graphic * * @return string The HTML markup for the create item link + * + * @deprecated 5.0 Use the class \Joomla\Component\Content\Site\Service\HTML\Icon instead */ public static function create($category, $params, $attribs = array(), $legacy = false) { - $uri = JUri::getInstance(); - - $url = 'index.php?option=com_content&task=article.add&return=' . base64_encode($uri) . '&a_id=0&catid=' . $category->id; - - $text = JLayoutHelper::render('joomla.content.icons.create', array('params' => $params, 'legacy' => $legacy)); - - // Add the button classes to the attribs array - if (isset($attribs['class'])) - { - $attribs['class'] .= ' btn btn-primary'; - } - else - { - $attribs['class'] = 'btn btn-primary'; - } - - $button = JHtml::_('link', JRoute::_($url), $text, $attribs); - - $output = '' . $button . ''; - - return $output; + return self::getIcon()->create($category, $params, $attribs, $legacy); } /** @@ -62,27 +44,12 @@ public static function create($category, $params, $attribs = array(), $legacy = * @param boolean $legacy True to use legacy images, false to use icomoon based graphic * * @return string The HTML markup for the email item link + * + * @deprecated 5.0 Use the class \Joomla\Component\Content\Site\Service\HTML\Icon instead */ public static function email($article, $params, $attribs = array(), $legacy = false) { - JLoader::register('MailtoHelper', JPATH_SITE . '/components/com_mailto/helpers/mailto.php'); - - $uri = JUri::getInstance(); - $base = $uri->toString(array('scheme', 'host', 'port')); - $template = JFactory::getApplication()->getTemplate(); - $link = $base . JRoute::_(ContentHelperRoute::getArticleRoute($article->slug, $article->catid, $article->language), false); - $url = 'index.php?option=com_mailto&tmpl=component&template=' . $template . '&link=' . MailtoHelper::addLink($link); - - $status = 'width=400,height=350,menubar=yes,resizable=yes'; - - $text = JLayoutHelper::render('joomla.content.icons.email', array('params' => $params, 'legacy' => $legacy)); - - $attribs['title'] = JText::_('JGLOBAL_EMAIL_TITLE'); - $attribs['onclick'] = "window.open(this.href,'win2','" . $status . "'); return false;"; - $attribs['rel'] = 'nofollow'; - $attribs['class'] = 'dropdown-item'; - - return JHtml::_('link', JRoute::_($url), $text, $attribs); + return self::getIcon()->email($article, $params, $attribs, $legacy); } /** @@ -99,71 +66,12 @@ public static function email($article, $params, $attribs = array(), $legacy = fa * @return string The HTML for the article edit icon. * * @since 1.6 + * + * @deprecated 5.0 Use the class \Joomla\Component\Content\Site\Service\HTML\Icon instead */ public static function edit($article, $params, $attribs = array(), $legacy = false) { - $user = JFactory::getUser(); - $uri = JUri::getInstance(); - - // Ignore if in a popup window. - if ($params && $params->get('popup')) - { - return; - } - - // Ignore if the state is negative (trashed). - if ($article->state < 0) - { - return; - } - - // Set the link class - $attribs['class'] = 'dropdown-item'; - - // Show checked_out icon if the article is checked out by a different user - if (property_exists($article, 'checked_out') - && property_exists($article, 'checked_out_time') - && $article->checked_out > 0 - && $article->checked_out != $user->get('id')) - { - $checkoutUser = JFactory::getUser($article->checked_out); - $date = JHtml::_('date', $article->checked_out_time); - $tooltip = JText::_('JLIB_HTML_CHECKED_OUT') . ' :: ' . JText::sprintf('COM_CONTENT_CHECKED_OUT_BY', $checkoutUser->name) - . '
' . $date; - - $text = JLayoutHelper::render('joomla.content.icons.edit_lock', array('tooltip' => $tooltip, 'legacy' => $legacy)); - - $output = JHtml::_('link', '#', $text, $attribs); - - return $output; - } - - $contentUrl = ContentHelperRoute::getArticleRoute($article->slug, $article->catid, $article->language); - $url = $contentUrl . '&task=article.edit&a_id=' . $article->id . '&return=' . base64_encode($uri); - - if ($article->state == 0) - { - $overlib = JText::_('JUNPUBLISHED'); - } - else - { - $overlib = JText::_('JPUBLISHED'); - } - - $date = JHtml::_('date', $article->created); - $author = $article->created_by_alias ?: $article->author; - - $overlib .= '<br>'; - $overlib .= $date; - $overlib .= '<br>'; - $overlib .= JText::sprintf('COM_CONTENT_WRITTEN_BY', htmlspecialchars($author, ENT_COMPAT, 'UTF-8')); - - $text = JLayoutHelper::render('joomla.content.icons.edit', array('article' => $article, 'overlib' => $overlib, 'legacy' => $legacy)); - - $attribs['title'] = JText::_('JGLOBAL_EDIT_TITLE'); - $output = JHtml::_('link', JRoute::_($url), $text, $attribs); - - return $output; + return self::getIcon()->edit($article, $params, $attribs, $legacy); } /** @@ -175,22 +83,12 @@ public static function edit($article, $params, $attribs = array(), $legacy = fal * @param boolean $legacy True to use legacy images, false to use icomoon based graphic * * @return string The HTML markup for the popup link + * + * @deprecated 5.0 Use the class \Joomla\Component\Content\Site\Service\HTML\Icon instead */ public static function print_popup($article, $params, $attribs = array(), $legacy = false) { - $url = ContentHelperRoute::getArticleRoute($article->slug, $article->catid, $article->language); - $url .= '&tmpl=component&print=1&layout=default'; - - $status = 'status=no,toolbar=no,scrollbars=yes,titlebar=no,menubar=no,resizable=yes,width=640,height=480,directories=no,location=no'; - - $text = JLayoutHelper::render('joomla.content.icons.print_popup', array('params' => $params, 'legacy' => $legacy)); - - $attribs['title'] = JText::sprintf('JGLOBAL_PRINT_TITLE', htmlspecialchars($article->title, ENT_QUOTES, 'UTF-8')); - $attribs['onclick'] = "window.open(this.href,'win2','" . $status . "'); return false;"; - $attribs['rel'] = 'nofollow'; - $attribs['class'] = 'dropdown-item'; - - return JHtml::_('link', JRoute::_($url), $text, $attribs); + return self::getIcon()->print_popup($article, $params, $attribs, $legacy); } /** @@ -202,11 +100,21 @@ public static function print_popup($article, $params, $attribs = array(), $legac * @param boolean $legacy True to use legacy images, false to use icomoon based graphic * * @return string The HTML markup for the popup link + * + * @deprecated 5.0 Use the class \Joomla\Component\Content\Site\Service\HTML\Icon instead */ public static function print_screen($article, $params, $attribs = array(), $legacy = false) { - $text = JLayoutHelper::render('joomla.content.icons.print_screen', array('params' => $params, 'legacy' => $legacy)); + return self::getIcon()->print_screen($article, $params, $attribs, $legacy); + } - return '' . $text . ''; + /** + * Creates an icon instance. + * + * @return \Joomla\Component\Content\Site\Service\HTML\Icon + */ + private static function getIcon() + { + return (new \Joomla\Component\Content\Site\Service\HTML\Icon(Joomla\CMS\Factory::getApplication())); } } diff --git a/components/com_content/tmpl/article/default.php b/components/com_content/tmpl/article/default.php index ad02519dc3a86..2b146cfb00a6e 100644 --- a/components/com_content/tmpl/article/default.php +++ b/components/com_content/tmpl/article/default.php @@ -9,8 +9,6 @@ defined('_JEXEC') or die; -JHtml::addIncludePath(JPATH_COMPONENT . '/helpers'); - // Create shortcuts to some parameters. $params = $this->item->params; $images = json_decode($this->item->images); @@ -43,7 +41,7 @@ print) : ?>
- item, $params); ?> + item, $params); ?>
@@ -72,7 +70,7 @@
- item, $params); ?> + item, $params); ?>
diff --git a/components/com_content/tmpl/category/default_articles.php b/components/com_content/tmpl/category/default_articles.php index c9fb69d3514cb..bd233d697c78b 100644 --- a/components/com_content/tmpl/category/default_articles.php +++ b/components/com_content/tmpl/category/default_articles.php @@ -254,7 +254,7 @@ params->get('access-edit')) : ?> - + @@ -266,7 +266,7 @@ category->getParams()->get('access-create')) : ?> - category, $this->category->params); ?> + category, $this->category->params); ?> diff --git a/libraries/src/Factory.php b/libraries/src/Factory.php index 17d167ad5387d..d09b458145500 100644 --- a/libraries/src/Factory.php +++ b/libraries/src/Factory.php @@ -510,6 +510,7 @@ protected static function createContainer(): Container ->registerServiceProvider(new \Joomla\CMS\Service\Provider\Logger) ->registerServiceProvider(new \Joomla\CMS\Service\Provider\Menu) ->registerServiceProvider(new \Joomla\CMS\Service\Provider\Pathway) + ->registerServiceProvider(new \Joomla\CMS\Service\Provider\HTMLRegistry) ->registerServiceProvider(new \Joomla\CMS\Service\Provider\Session) ->registerServiceProvider(new \Joomla\CMS\Service\Provider\Toolbar); diff --git a/libraries/src/HTML/HTMLHelper.php b/libraries/src/HTML/HTMLHelper.php index 28becb2a0b4d9..7ca51a0d72ea9 100644 --- a/libraries/src/HTML/HTMLHelper.php +++ b/libraries/src/HTML/HTMLHelper.php @@ -289,7 +289,7 @@ public static function getServiceRegistry(): Registry { if (!static::$serviceRegistry) { - static::$serviceRegistry = new Registry; + static::$serviceRegistry = Factory::getContainer()->get(Registry::class); } return static::$serviceRegistry; diff --git a/libraries/src/Service/Provider/HTMLRegistry.php b/libraries/src/Service/Provider/HTMLRegistry.php new file mode 100644 index 0000000000000..fcfad63ad8bbe --- /dev/null +++ b/libraries/src/Service/Provider/HTMLRegistry.php @@ -0,0 +1,44 @@ +share( + Registry::class, + function (Container $container) + { + return new Registry; + }, + true + ); + } +} diff --git a/tests/unit/core/mock/application/cms.php b/tests/unit/core/mock/application/cms.php index 1033ed6e905c8..5385e609ee8f3 100644 --- a/tests/unit/core/mock/application/cms.php +++ b/tests/unit/core/mock/application/cms.php @@ -36,6 +36,7 @@ public static function getMethods() 'getUserState', 'getUserStateFromRequest', 'setUserState', + 'getContainer', ); return array_merge($methods, parent::getMethods()); diff --git a/tests/unit/suites/libraries/cms/component/router/JComponentRouterViewTest.php b/tests/unit/suites/libraries/cms/component/router/JComponentRouterViewTest.php index 442a9c3f4efc4..8aa5f13d9d212 100644 --- a/tests/unit/suites/libraries/cms/component/router/JComponentRouterViewTest.php +++ b/tests/unit/suites/libraries/cms/component/router/JComponentRouterViewTest.php @@ -41,6 +41,7 @@ protected function setUp() parent::setUp(); $app = $this->getMockCmsApp(); + $app->method('getContainer')->willReturn(\Joomla\CMS\Factory::getContainer()); JFactory::$application = $app; JFactory::$session = $this->getMockSession(); diff --git a/tests/unit/suites/libraries/cms/component/router/rules/JComponentRouterRulesMenuTest.php b/tests/unit/suites/libraries/cms/component/router/rules/JComponentRouterRulesMenuTest.php index 384ed6e383be9..024265fca3937 100644 --- a/tests/unit/suites/libraries/cms/component/router/rules/JComponentRouterRulesMenuTest.php +++ b/tests/unit/suites/libraries/cms/component/router/rules/JComponentRouterRulesMenuTest.php @@ -45,6 +45,7 @@ protected function setUp() JFactory::$session = $this->getMockSession(); $app = $this->getMockCmsApp(); + $app->method('getContainer')->willReturn(\Joomla\CMS\Factory::getContainer()); JFactory::$application = $app; $router = new JComponentRouterViewInspector($app, $app->getMenu()); $router->set('name', 'content'); diff --git a/tests/unit/suites/libraries/cms/component/router/rules/JComponentRouterRulesStandardTest.php b/tests/unit/suites/libraries/cms/component/router/rules/JComponentRouterRulesStandardTest.php index 99435062bf925..df3dc17f22fd6 100644 --- a/tests/unit/suites/libraries/cms/component/router/rules/JComponentRouterRulesStandardTest.php +++ b/tests/unit/suites/libraries/cms/component/router/rules/JComponentRouterRulesStandardTest.php @@ -64,6 +64,7 @@ protected function setUp() JFactory::$session = $this->getMockSession(); $app = $this->getMockCmsApp(); + $app->method('getContainer')->willReturn(\Joomla\CMS\Factory::getContainer()); JFactory::$application = $app; $router = new ContentRouterStandardRuleOnly($app, new JMenuSite(array('app' => $app, 'language' => self::getMockLanguage())), $noIds);