1

I have created a custom module and I want to change the module chrome to "none". This can be achieved in the back end, but I would like it as the default behaviour in case others use the module. I want it to be as simple as possible to work out of the box.

Is there a way to do this automatically? The XML file does not include this option so I cannot do it in there.

  • Hi - your question is a bit unclear, or you might be confused about how things work. With "created a module" you meant to say that you developed a custom one, or just created one of the available ones in the backend. When you say programatically- what you have in mind - and how programatically would be more user friendly than the backend select option? Can you specify/describe what your actual problem is that would be solved programatically? – FFrewin Jun 24 '17 at 4:59
  • @FFrewin thanks for the feedback I updated the question. My module works in the admin end, and works in the cpanel position. Ideally I would like to set cpanel as the position and module chrome to none automatically. I've never seen a module appear with a module position, but I assume there is a way to do this. Perhaps in the post processing part of install? – Eoin Jun 24 '17 at 7:29
1

Updated Answer:

After your explanations I see what you are after.
Indeed you can do this during the installation of your module. Since the module is intented for the backend and you only going to need 1 instance of it, setting the module chrome during the installation does make some sense.

In your module's install.php you can update the module that is created during installation with a postflight function:

function postflight($type, $parent)
{
    // check if it's the first time the module is installed.
    if($type == 'install') 
    {
        $db = JFactory::getDBO();
        $module_name = 'your_module_name';

        // get module id that is created during installation 
        $query = 'SELECT `id`' .
            ' FROM `#__modules`' .
            ' WHERE module = ' . $db->quote($module_name);
        $db->setQuery($query);

        try
        {
            $moduleid = $db->loadResult();
        }
        catch (Exception $e)
        {
            $moduleid = '';
        }

        // Do we have a module?
        if (!empty($moduleid) )
        {
            // Get Modules' JTable
            $module = JTable::getInstance('module');

            // Load the module instance by id
            $module->load($moduleid);
            $params = array(
                'style' => 'System-none',
                'cache' => 0
            );

            // Set Module's properties
            $module->set('title', (string) 'This is my title');
            $module->set('position', (string) 'New Position');
            $module->set('params', json_encode($params));

            // Store in the database
            $module->store();
        }
    }
}

Here you can find more info about including an installation script with your module:
Creating Simple Module/ Adding Install-unintall-update script.

Initial Answer:

As said in my comment above, it's not clear what you are asking or your actual problem is. So I am going to make a guess that you have developed a module for which you would prefer to not showing anything around it when it's installed and set to show on a module position, so you are looking for a piece of code inside your module, that would somehow do this? (is this what you are talking about ???).

Module Chrome though, isn't something that is controlled on the module level, rather than it is a Template Feature. It defines a "layout"/html markup of a module position on a template, it happens outside of the module and it's not something that any module instance knows anything about it or care. Module Chrome isn't something that a module developer would have to think.

Programatically, it can be set to a default choice, for each module position, but this is done by the template when module positions are defined in it.

This is how it's done:

<jdoc:include type="modules" name="position-1" style="none" />
<jdoc:include type="modules" name="position-2" style="xhtml" />

Something that of course can be overriden by the end-user when creating and assigning any module on any position.

  • Thanks, so it looks like this is not possible. I think for any template it would be fine but modules are supposed to work for any template. And this is an admin one, so ideally I am thinking about Isis. I guess I would need to update Isis, but then how do I do that for each and every install? And I don't want to do it for all items in the cpanel position just this one. – Eoin Jun 24 '17 at 7:33
  • @Eoin - I updated my answer. Now it does make sense your question. – FFrewin Jun 24 '17 at 11:47
  • yes it makes sense (for someone who knows nothing) but nothing appear to occur in the back end the module is still installed as usual with no position and the standard module chrome. – Eoin Jun 24 '17 at 13:35
  • @Eoin I don't know what you have done, the above is a draft postflight function which you have to adjust to your module and implement inside your install.php mod_yourModuleInstallerScript Class. At first try to echo something from inside the postflight function and see if it gets printed after your installation. Do also note that with the $type condition check, the code below it will run only on first installation and not on update. – FFrewin Jun 24 '17 at 19:26
  • 1
    @Eoin - updated my question - including a link to J! Documentation about adding install script to a module. – FFrewin Jun 25 '17 at 8:40

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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