2

In the xml file for a module, I call a custom field class:

<config>
    <fields name="params">
        <fieldset name="basic" addfieldprefix="Myextension\Name\Administrator\Field">
            <field name="category_id" type="categorylist" default="0"
                   none="MOD_MYMODULE_PARAM_CATEGORYLIST_NONE"
                   description="MOD_MYMODULE_PARAM_CATEGORYLIST_NONE_DESC"
                   label="MOD_MYMODULE_PARAM_CATEGORYLIST_NONE" multiple="true" size="5">
                <option value="0">MOD_MYMODULE_PARAM_CATEGORYLIST_NONE</option>
            </field>
         </fieldset>
    </fields>
</config>

In the file CategorylistField, I call HTMLHelper:

class CategorylistField extends ListField
{
    protected $type = 'CategoryList';

    protected function getInput(): string
    {
        return HTMLHelper::_('myextensionhtml.categorylist', $options, $this->element, $attribs, $this->value);
    }
}

When I edit the module, I have an error:

500 JHtml myextensionhtml not found on JROOT\libraries\src\HTML\HTMLHelper.php:156

In my component, the call of HTMLHelper::_('myextensionhtml.categorylist' works, why doesn't it work in the module?

1 Answer 1

2

You need to register the HTML services with the service registry. If your component uses the same convention as Joomla core, then the services are registered during the boot up process of the component. In that case, you can boot the component manually before using HTML services:

// Boot the component.
\Joomla\CMS\Factory::getApplication()->bootComponent('com_kunena');

 return HTMLHelper::_('myextensionhtml.categorylist', $options, $this->element, $attribs, $this->value);

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.