Hey I am making my first module in Joomla!.
I want to create a new folder in Joomla!'s media manager when someone installs my module. I have been duck-duck-go-ing around and found some information. But I just can't get it to work. Probably because the information might be for older Joomla! versions. Or I might've implemented it wrong.
Anyway I came up with the following:
mod_mymodule.xml
<extension type="module" version="3.8.1" client="site" method="upgrade">
<files>
<scriptfile>install.componentname.php</scriptfile>
</files>
</extension>
install.createmap.php
<?php
$destination = JPATH_SITE."/images/mynewmap";
JFolder::create($destination);
?>
Can anyone explain me how to add a folder to the media manager (root/images) on installing a module in Joomla 3?
You need a script.php file which executes your install tasks:
https://docs.joomla.org/J3.x:Creating_a_simple_module/Adding_an_install-uninstall-update_script_file
Here is the example content the script.php:
<?php
// No direct access to this file
defined('_JEXEC') or die;
class mod_helloWorldInstallerScript
{
function install($parent)
{
echo '<p>The module has been installed</p>';
}
function uninstall($parent)
{
echo '<p>The module has been uninstalled</p>';
}
function update($parent)
{
echo '<p>The module has been updated to version' . $parent->get('manifest')->version . '</p>';
}
function preflight($type, $parent)
{
echo '<p>Anything here happens before the installation/update/uninstallation of the module</p>';
}
function postflight($type, $parent)
{
echo '<p>Anything here happens after the installation/update/uninstallation of the module</p>';
}
}
It contains a class with some methods so you can create the necessary folder structure. You want to extend the postflight method.