?
avatar nedjic
nedjic
17 Nov 2018

Steps to reproduce the issue

jimport('joomla.application.module.helper');
$module = JModuleHelper::getModule('module_name');
echo $module;

Expected result

{"id":"93","title":"contact","module":"mod_module_name","position":"position-7".........

Actual result

null

System information (as much as possible)

Joomla 3.9, Apache/2.4.34 (Unix), mySQL 8.0.12

Additional comments

avatar nedjic nedjic - open - 17 Nov 2018
avatar joomla-cms-bot joomla-cms-bot - change - 17 Nov 2018
Labels Added: ?
avatar joomla-cms-bot joomla-cms-bot - labeled - 17 Nov 2018
avatar SharkyKZ
SharkyKZ - comment - 17 Nov 2018

The name should include mod_ prefix: JModuleHelper::getModule('mod_module_name').

avatar nedjic
nedjic - comment - 17 Nov 2018

The name should include mod_ prefix: JModuleHelper::getModule('mod_module_name').

I try that also and then I got fallowing result:
{"id":"0","title":"","module":"mod_module_name","position":"".........

In Joomla 3.7.3 everything was working with "mod_" or without prefix.

avatar SharkyKZ
SharkyKZ - comment - 17 Nov 2018

Just tried with prefix and without. Works both ways in 3.9.0. But in case no module with specified type is published (looking at 0 ID in your result), you must use the prefix to get a new module object. The same is true in 3.7.3.

avatar nedjic
nedjic - comment - 18 Nov 2018

Actually, it is a bug, but it's not related to a version of Joomla. This bug is related to module settings, exactly with module assignment.
If you select to show module on "All pages" or if you select to show module on "On all pages except those selected" everything work as it should, but if you select to show module on "Only on the pages selected", then you will get strange behaver as I mention above.
Depending on the Joomla version you got different strange behaver. On ver. 3.9 you got an output as I wrote above ({"id":"0","title":"","module":"mod_module_name","position":"".........), but for example in ver. 3.8 you got this message. "Module mod_module_name is not published, you do not have access to it, or it's not assigned to the current menu item."

avatar ReLater
ReLater - comment - 18 Nov 2018

Could you please provide a clear step-by-step instruction for a situation where it works and a situation where it doesn't work but should work inclusive code snippets for rendering the modules.

An echo like in your first post never rendered a module.

  • Create a module of type xyz
  • Do this
  • Do that
avatar Quy Quy - change - 20 Dec 2018
Status New Closed - Unconfirmed Report
Closed_Date 0000-00-00 00:00:00 2018-12-20 03:33:10
Closed_By Quy
avatar joomla-cms-bot joomla-cms-bot - change - 20 Dec 2018
Status Closed - Unconfirmed Report Closed
Closed_By Quy joomla-cms-bot
avatar joomla-cms-bot joomla-cms-bot - close - 20 Dec 2018
avatar joomla-cms-bot
joomla-cms-bot - comment - 20 Dec 2018

Set to "closed" on behalf of @Quy by The JTracker Application at issues.joomla.org/joomla-cms/23105

avatar Quy
Quy - comment - 20 Dec 2018

This can be reopened when the requested information is provided.


This comment was created with the J!Tracker Application at issues.joomla.org/tracker/joomla-cms/23105.

avatar joomlabeat
joomlabeat - comment - 17 Jul 2020

I am trying to render a mod_login module - on the fly - through a plugin. So far, there is no existing mod_login instance in the website. I am just trying to create a new object through php.

$module = JModuleHelper::getModule('mod_login', '');
$moduleParams = new JRegistry($module->params);		
$moduleParams->set('style', "System-html5");
$module->showtitle = "1";
$module->title = $title;
$renderer = $doc->loadRenderer('module');
$modHtml = $renderer->render($module, array('params'=> $moduleParams));

On my MAMP localhost php72, it works. On the online server (Litespeed - php72) it doesn't. I have to create a login module and specifically select that one in order to render it: $module = JModuleHelper::getModule('mod_login', 'My Login');

Joomla 3.9.19 in both systems.

I can't figure out why

avatar jbrailas
jbrailas - comment - 11 Aug 2022

Why did you close this issue??
I've spent four hours trying to figure out what mistake I made and then I read that there is a bug!
I had my custom module "Only on the pages selected". Thankfully there is a workaround as mentioned by nedjic

avatar ReLater
ReLater - comment - 11 Aug 2022

@jbrailas

Why did you close this issue??

Meanwhile we're on Joomla 3.10 and I still can not confirm the issue. i don't see a "bug". Just expected bahavior from my point of view.

  • Create 1 module of type mod_login.
  • It's important to have just 1 because ModuleHelper::getModule('mod_login') returns just 1 if there are several.
  • No position set in my case.
  • In index.php of the template.
defined('_JEXEC') or die;

use Joomla\CMS\Helper\ModuleHelper;

$module = ModuleHelper::getModule('mod_login');
echo ' Debug module: <pre>' . print_r($module, true) . '</pre>';exit;
  • Opening Home (frontend) in Browser.

1) Module Assignment: No pages

  • Debug output:
stdClass Object
(
    [id] => 0
    [title] => 
    [module] => mod_login
    [position] => 
    [content] => 
    [showtitle] => 0
    [control] => 
    [params] => 
)

=> Expected. Not assigned. Therfore just an empty dummy.

2) Module Assignment: On all pages

stdClass Object
(
    [id] => 44
    [title] => Login
    [module] => mod_login
    [position] => 
    [content] => 
    [showtitle] => 1
    [params] => {"pretext":"","posttext":"","login":"280","logout":"280" ...}
    [menuid] => 0
    [name] => login
    [style] => 
)

=> Expected. Assigned. Therfore the full module data.

3) Module Assignment: Only on selected ... and assign Home menu.

  • Like 2) => Expected

4) Module Assignment: Only on selected ... and DO NOT assign Home menu but some other.

  • Like 1) => Expected

5) Module Assignment: On all except selected ... and DO NOT assign Home menu but some other.

  • Like 2) => Expected

6) Module Assignment: On all except selected ... and assign Home menu.

  • Like 1) => Expected

7) Trash and delete all modules of type "Login".

  • Like 1) => Expected

And in all cases (even if the module has been deleted)

An additional:

echo ModuleHelper::renderModule($module);

populates the $module->content with the login form and outputs something like:

grafik

Add a Comment

Login with GitHub to post a comment