I’m creating a custom module. when i try to install it it doesn’t respond after clicking the installation button.
i receive 500 internal server error.
directory structure is
Xibo/shared/cms/custom/
i have placed the json file in Xibo/shared/cms/custom/MyModule.json
code in the MyModule.json is following
{
“title”: “My Custom Module”,
“author”: “Saqib Ali”,
“description”: “A module for testing”,
“name”: “MyModule”,
“class”: “Xibo\Custom\MyModule\MyModule”
}
my class file is in Xibo/cms/custom/MyModule/MyModule.php
code in the class file is following
<?php
namespace Xibo\Custom\MyModule;
/**
* Install or Update this module
* @param ModuleFactory $moduleFactory
*/
use Respect\Validation\Validator as v;
use Xibo\Exception\InvalidArgumentException;
use Xibo\Factory\ModuleFactory;
class MyModule extends ModuleWidget {
public function installOrUpdate($moduleFactory)
{
if ($this->module == null) {
// Install
$module = $moduleFactory->createEmpty();
$module->name = 'My Module';
$module->type = 'MyModule';
$module->class = 'Xibo\Custom\MyModule\MyModule';
$module->description = 'A module for displaying my information.';
$module->imageUri = 'Xibo/Custom/MyModule/';
$module->enabled = 1;
$module->previewEnabled = 1;
$module->assignable = 1;
$module->regionSpecific = 1;
$module->renderAs = 'html';
$module->schemaVersion = $this->codeSchemaVersion;
$module->defaultDuration = 60;
$module->settings = [];
$module->viewPath = '../custom/MyModule';
// Set the newly created module and then call install
$this->setModule($module);
$this->installModule();
}
// Install and additional module files that are required.
$this->installFiles();
}
/**
* Install Files
*/
public function installFiles()
{
// Use JQuery and some Xibo resources
$this->mediaFactory->createModuleSystemFile(PROJECT_ROOT . '/modules/vendor/jquery-1.11.1.min.js')->save();
}
/**
* Form for updating the module settings
*/
public function settingsForm()
{
// Return the name of the TWIG file to render the settings form
return 'MyModule-form-settings';
}
/** @inheritdoc */
public function isValid()
{
if ($this->getUseDuration() == 1 && $this->getDuration() == 0)
throw new InvalidArgumentException(__('Please enter a duration'), 'duration');
if (!v::url()->notEmpty()->validate(urldecode($this->getOption('uri'))))
throw new InvalidArgumentException(__('Please enter a link'), 'uri');
return self::$STATUS_VALID;
}
public function GetResource($displayId = 0)
{
$this
->initialiseGetResource()
->appendViewPortWidth($this->region->width)
->appendJavaScriptFile('vendor/jquery-1.11.1.min.js')
->appendFontCss())
->appendBody('<h1>My HTML</h1>')
->appendJavaScript('$(document).ready(function() { $("h1").html("My Altered HTML"); } ');
return $this->finaliseGetResource();
}
}
?>
Please i need guide where i have done wrong. Any help is appreciated.
Thanks