Reputation: 31
I'm developing a LimeSurvey plugin that extends PluginBase and organizes code into a structured namespace. The plugin installs fine and doesn't break limesurvey when the conditional if (!class_exists(...)) statement is used before subclass initialization. However, when I attempt to modify the settings of the plugin in the LimeSurvey admin panel, I get a popup error saying "Can't load the plugin."
I have TemplatePlugin extends PluginCore:
<?php
namespace MyPlugin;
use MyPlugin\Services\PluginCore;
if (!class_exists('MyPlugin\\TemplatePlugin')) {
class TemplatePlugin extends PluginCore {
}
}
And the PluginCore class:
namespace MyPlugin\Services;
use LimeSurvey\PluginManager\PluginBase;
class PluginCore extends PluginBase {
protected $storage = 'DbStorage';
static protected $description = 'Webhook for Limesurvey: send a curl POST after every response submission.';
static protected $name = 'Hook';
protected $surveyId;
public function init()
{
$this->subscribe('beforeSurveySettings');
}
// Globale settings
protected $settings = array(
'bUse' => array(
'type' => 'select',
'options' => array(
0 => 'No',
1 => 'Yes'
),
'default' => 1,
'label' => 'Send a hook for every survey by default?',
'help' => 'Overwritable in each Survey setting'
),
);
/**
* Add setting on survey level: send hook only for certain surveys / url setting per survey / auth code per survey / send user token / send question response
*/
public function beforeSurveySettings()
{
$oEvent = $this->event;
$settings = array(
'bUse' => array(
'type' => 'select',
'label' => 'Send a hook for this survey',
'options' => array(
0 => 'No',
1 => 'Yes',
2 => 'Use site settings (default)'
),
'default' => 2,
'help' => 'Leave default to use global setting',
'current' => $this->get('bUse', 'Survey', $oEvent->get('survey'))
),
);
$oEvent->set("surveysettings.{$this->id}", array(
'name' => get_class($this),
'settings' => $settings
));
}
Any insights into potential issues with my class structure, namespace usage, or settings implementation would be greatly appreciated!
I have used the same syntax for previous plugins not including the namespace structure, where they have worked fine, but this plugin is very large and requires a more structured layout.
I have experimented with different folders, namespaces and locations, and generally been trying to debug the issue to the best of my abilities.
Upvotes: 3
Views: 26
Reputation: 29
This seems like LimeSurvey is not recognizing your namespaced classes, likely due to autoloading issues. You need to make sure that the autoloader is picking up PluginCore and TemplatePlugin. Then you need to try including the files if needed.
Furthermore, you need to check if config.xml correctly registers your plugin and follows LimeSurvey’s naming conventions. In other cases, test it with a non-namespaced version to see if the issue is namespace-related. I have practiced these steps for one of the clients website where they were focusing mainly on tech based services.
Upvotes: 0