Setting plugin variables with a Form


#1

I cannot get twig/md to recognise a dynamic variable.

In a plugin file, I have

class MyPlug extends Plugin 
{ protected $plugvar;
...
public function onPluginsInitialized() {
$this->grav['myplug'] = $this;
...
public function get($var) { return $this->plugvar[$var] ;}
public function set($var, $val) { $this->plugvar[$var]=$val;}
...
public onFormProcessed(Event $e) {
...
  $data=$form->value()->toArray();
  case 'myplug':
     foreach($data as $key => $val) {
        $this->plugvar[$key] = $val; }
...

Then in a shortcode file

 $this->shortcode->getHandlers()->add('myplug', function(ShortcodeInterface $sc) {
  $params = $sc->getParameters();
  foreach( $params as $key => $val){
   if ($val != null ) {
      $resp = $this->grav['myplug']->get($key);
      if ($resp) return $resp;
      else return 'undefined';

In a form.md

---
form:
  name: set-operator-form
  fields:
    - name: operator
      type: hidden
      content: undefined
  buttons:
    - type: submit
      value: "Select Operator"
    - type: reset
      value: Reset
  process:
    - myplug
process:
    twig: true
cache_enable: false

And finally in default.md

[myplug operator/]

The first time default.md is served, I get an expected ‘undefined’ response in the html.

Also after clicking on the Submit button of the Form, and going to default.md, there is no change, and I get an undefined response.

Using dump and $this->grav['debugger']->addMessage(...);
provide feedback that the form.md operates correctly.

Somehow default.md is not being processed again with the new dynamic information.

Is there an alternative way to get session variables? I have tried creating twig_vars, but I cannot access them across pages.

I know I am missing something, but I can’t find a clue in the documentation.


#2

[SOLVED] The problem was eliminated by reinstalling the form plugin.