Recently I found out that LimeSurvey allows you to create plugins. It is so much better to add a functionality via a Plugin than hacking everything in some broken Frontend-JS that will be injected into the survey...
Long story short: I got the plugin working, but there are still some things that I'd wish to be better / easier.
I'll start in this post with my most pressing issue. The plugin in question shows a generated link at the end of each survey it got activated for in the survey settings.
I'm using this code inside the callback for the event "afterSurveyComplete" to show the link when a user configured it to show up:
Code:
$event->getContent($this)->addContent('<a href="' . $url . '">' . $linkText . '</a>');
However, the link will be displayed above the end message for the survey. There is a constant to choose between append and prepend for "addContent", but it does only refer to the order related to other plugin's output. From what I see there is no possibility to echo content after the end message, right?
Maybe another event-hook should be added there, I don't know.
I kind of solved the problem by introducing an alternative end message that would be displayed before the generated link. To enable a user to edit this message I added a field in my plugin settings for the survey like this in the "beforeSurveySettings" event-hook:
Code:
$event = $this->getEvent();
$event->set("surveysettings.{$this->id}", array(
'name' => get_class($this),
'settings' => array(
'prependSurveyEndText' => array(
'type' => 'html',
'default' => '',
'label' => 'Show this text as alternative endmessage',
'current' => $this->get('prependSurveyEndText', 'Survey', $event->get('survey'))
)
)
));
Unfortunately, this solves one problem, but introduces two more problems. Firstly, the editor doesn't render correctly (it's only a very basic editor without a toolbar like the other htmleditors). Secondly, the default end message for the survey needs to be "edited empty". The user needs to add some HTML that includes a non-visible character, because with an entirely empty end message in the survey, the default LimeSurvey end message would show up.
The coolest thing would be, if plugin developers could register text variables that would be replaced at runtime. But I don't see any such possibility right now. E.g. in this case I could simply declare a new text variable like CUSTOM_LINK and a user could insert it into the default end message HTML editor, while it would be replaced when loading the page.
Are there any ideas of how to overcome the challenges I'm facing with this plugin or any suggestions on how to implement a replace variable?
I would be glad for any suggestions