1
votes

I have created Joomla module and added a custom field type at the parameter configuration in the backend, using the .xml file like this:

<fields name="params">
    <fieldset
        addfieldpath="/modules/<module_name>/fields" name="basic">
            <field  name="articles" type="articles" label="label" />

.
.
.
</fields>

That is working pretty fine but there is on question left over: How can I access the module's id inside the custom field class, when invoked to create the fields html?

Thanks in ahead!

UPDATE

I digged a bit deeper in that found the JModuleHelper::getModule($type, $name) method, which returns either the first module of the given $type if no $name is specified, or the module of the given $type having the $name, but since it is possible to create Modules with the same name, this approach is kind of ugly.

1
$app = JFactory::getApplication(); $module_id = $app->input->getInt('id');Priya Bose

1 Answers

1
votes

The solution is hidden in the URL and in case of Joomla, in JInput. Complete and more verbose explanation is here (a the bottom), but in short:

URL of a modules edit screen:

index.php?option=com_modules&view=module&layout=edit&id=87

Would be too easy to just use this…