silverstripe / silverstripe-blog

Blog module for Silverstripe CMS
http://silverstripe.org/blog-module
BSD 2-Clause "Simplified" License
103 stars 169 forks source link

Blog posts can be created under non-blog pages #521

Open raissanorth opened 6 years ago

raissanorth commented 6 years ago

It is a bit odd and confusing that one can add a blog post under pages that are not of type blog. One even gets to see the preview within the CMS and it is therefore not immediately clear that the blog post is not actually visible on the live page.

dhensby commented 6 years ago

Looks like this feature would need to be pushed over the line to resolve this: https://github.com/silverstripe/silverstripe-cms/pull/1171

Cheddam commented 5 years ago

We have a test configured in our CWP regression suite that has been failing on this broken behaviour since it was created. The above PR was eventually closed without merging, as it was targeted at CMS 3 and didn't make the cut before that was shifted into maintenance mode.

Would be good to address this at some point, but likely still requires a core change to facilitate it.

kinglozzer commented 5 years ago

Would be good to address this at some point, but likely still requires a core change to facilitate it.

It can be done with canView() - we usually resolve this with an extension:

<?php

namespace App\Extensions\Blog;

use SilverStripe\Blog\Model\Blog;
use SilverStripe\Core\Extension;

class BlogPostExtension extends Extension
{
    /**
     * @param mixed $member
     * @param array $context
     * @return bool|null
     */
    public function canCreate($member = null, $context = []): ?bool
    {
        $parent = $context['Parent'] ?? null;
        if (!$parent || !$parent instanceof Blog) {
            return false;
        }

        return null;
    }
}
maxime-rainville commented 4 years ago

This is still an issue in our regression test.