Update section plugin when page status changes


#1

I’m using a custom sections plugin to display an additional info as long as the page is a draft. I followed these instructions and everythings works really well … until the status of the page is actually changed from draft to listed.

Obviously, the initial value if the page is a draft or not never gets updated (until reloading the page of course).

Is there anything like hooks on the vue side?

Here’s my code …


index.php

Kirby::plugin('myname/myplugin', [
  'sections' => [
    'draftWarning' => [
      'computed' => [
        'visible' => function () {
          return $this->model()->isDraft();
        },
      ]
    ]
  ]
]);

index.js

panel.plugin('myname/myplugin {
  sections: {
    draftWarning: {
      data: function () {
        return {
          visible: null
        }
      },
      created: function() {
        this.load().then(response => {
          this.visible = response.visible;
        });
      },
      template: `
        <div class="k-field k-info-field" v-if="visible">
          <k-box theme="info">
            This page is not published yet!
          </k-box>
        </div>
      `
    }
  }
});


#2

The pages section is listening to a this.$events.$on("page.changeStatus", ... event. (see source code)


#3

Awesome. Thanks for the help … works great!