Comments Plugin for Kirby v3

Ah, sorry, I got confused if all those ifs and trys:

    // Save comment as page
    if ($comments_page) {
        kirby()->impersonate('kirby');
        $comment_page = $comments_page->createChild([
            'slug' => $dirname,
            'template' => $template,
            'content' => $contents
        ]);
       $comment_page->publish();
    }

Sorry, i wasn’t home. So for me, the code works. Just some guesses: There is a problem with your pages, therefore the comments page cant be created and createChild on null is, where it ends.
It could also be a permissions problem.

about texnixes issues:

→ That’s true, for me it still works

→ I copied everything from kirby 2 code, thats correct. However for my use case, it does work. But i have two versions now, one customized at my website and the public one, so they could slightly differ.

→ Jupp thats true. Since i quickly needed something that works and i won’t by myself actively maintain this plugin (however merge requests are always welcome), i made the bare minimum to get it done.

Still thank you @texnixe for your investigations. :slight_smile: I will update this soon.

Thanks @RastaTux – I wonder if a clean install of Kirby 3 vs your upgrade makes any notable difference to the fact that yours is working and I’ve been unable to get this to work cleaning. I might give that a go as frankly, Kirby 3 is going to be much easier for what I’m trying to pull off.

@cadler No, without the fixes it can’t possibly work unless you apply the suggested fixes yourself.

Having said that, you could work around the issue by auto-creating a comments subpage every time an article (or whatever it is where you the comments to appear) is created following this recipe: https://getkirby.com/docs/cookbook/extensions/subpage-builder

Ough okay, sorry you were right. Actually it worked for me, because since i had already the “comments” folders due to moving everything over from an kirby v2 page, i didn’t get this error. I changed the things from @texnixe, however the “comments” page were created as draft.

I added $comments_page->publish(); and it gets created, but the _drafts folder and the old version are not getting deleted. I guess, it’s something about file permissions… Do you have an idea how to fix that? Actually i had always problems with permissions with kirby comments…

1 Like

You beat me to the punch @RastaTux – i’ve been trying to figure this “/_drafts” folder out and how to get it out of draft mode. Did the $comments_page->publish(); work, and if so where are you placing this in the file?

Hi @texnixe – I’ve followed the Subpage Builder instructions applied to this project and it doesn’t seem to work. Something about the instructions leads me to believe it’s incomplete (not simply because my implementation isn’t working :slight_smile: )

What exactly doesn’t work?

It seems that it runs into a loop if the blueprints you use in your subpage builder do not exist, so that it uses the default template. Apart from that issue the code works for me.

Regarding the Subpage Builder feature, and to set the stage, I’ve posted some screengrabs of the relevant pages below.

But essentially, the directory and page is not created when I create a new “Critique” page.
I’m also running into the same issue as @RastaTux above ("/_drafts/" is a directory created for comments and as such the comments don’t get published.

So it seems like two issues are holding me back:

  1. A directory called “_drafts” is being created by the comments plugin, but is either not being updated to “/comments/” as a subdirectory. In my situation I’d ideally skip the whole “preview” step and there would never be a “_drafts” directory.
  2. The Subpage builder does not create a subpage. I was originally thinking this would create the “/comments/” directory and a “comments” text file, but it seems it would just be the text file. So I might have been expecting something incorrectly here.




Your config can’t possibly work with two return statements in there… all options etc. should ever be returned in ONE return array.

<?php

return [
    'debug' => true,
    'hooks' => [
        'page.create:after' => function ($page) {
            buildPageTree($page);
        }
    ]
];

A return statement returns control to the calling script, everything that comes after is then ignored.

I already added this to the documentation a while ago (https://getkirby.com/docs/reference/system/options) because I’ve seen this error multiple times by now, but don’t know where else to put it so it gets attention?

1 Like

Booom! Works. :slight_smile:

Unfortunately I don’t have a great alternative suggestion regarding educating us more effectively on return statements / syntax. :frowning:

As with any system, as it becomes more complex, more documentation is necessary, all driven by more use cases… resulting in it becoming harder to access all information as an individual user trying to educate themselves on a the system in service of achieving their goal.

We deal with somewhat the same issue with Kickstarter, though clearly different context and circumstance.

Fine!

The comments subpage should now also be published automatically…

Hey!
The problem with using subpage builder - It needs changes on the above blueprint. It’s something that the plugin should do by itself without the need to change blueprints that have nothing to do with the comments plugin. Is there another solution?

As i said, i also tried to $comments_page->publish(); the comments page, but its not removing the _drafts folder. I guess it has something to do about permissions. If we could solve this, it would be a way cleaner solution imho…

I only suggested it as a workaround, not as a solution. I haven’t had a chance to look into why publishing the page doesn’t work in your plugin.

At least for me @texnixe solution does work, though now it seems once the comment is rendered to the page, the form does not render. So that’s my current challenge to pursue.

Still curious @RastaTux which file and line you’re applying “$comments_page_publish();” .

c

@cadler The form is not shown after the comment is successfully submitted… See the if-else statement in the form snippet.

Fantastic! Thanks. Got that squared away, and also included a <?php $_POST = array(); ?> to clear the form upon refresh allowing for an ease of multiple comments by contributors.

Hey! Finally i got some time to work on the last Issues for Kirby v3 Comments. There was still a bug that prevented it from working correctly.


Also, i’ve changed Session handling from PHP Sessions to Kirby Sessions.