Jump to:

1840 Posts in 1599 Topics by 557 members

Blog Module

SilverStripe Forums » Blog Module » Blog management with Modeladmin

Discuss the Blog Module.

Moderators: martimiz, Sean, biapar, Willr, Ingo, swaiba, simon_w

Page: 1
Go to End
Author Topic: 2812 Views
  • teejay
    Avatar
    Community Member
    63 Posts

    Blog management with Modeladmin Link to this post

    Hi I have a question about implementing the model admin with the blog entries. so what I have done is the following

    NewsAdmin.php

    class NewsAdmin extends ModelAdmin {

    public static $managed_models = array(
    'BlogEntry'
    );

    static $url_segment = 'news';
    static $menu_title = 'News';
    }

    thats its so far. I can work with the news i can search them but when i want to save i have some issues. i click in create new blog entrie and fill out everything. Then i click on add it add a new page to the site tree. Draft ! How can I add it to the blog holder, and publish it. If i edit the new again i have a publish button on the bottom but when i click on it nothing happends at all . can someone help me with that ?

  • teejay
    Avatar
    Community Member
    63 Posts

    Re: Blog management with Modeladmin Link to this post

    i had a chat in the silverstripe icq chat and stuckinrealtime (as usual ) had something to fix the issue partly.

    put the following code in BlogEntry.php (Model) if u have just one blogholder ! this will get the blogholder id and sets the PatentID to save the blogentries under these nodes.

    public function onBeforeWrite() {
        if(!$this->extension_instances['Versioned']->migratingVersion) {
           if (!$this->ParentID) {
           $tmp = DataObject::get_one('BlogHolder');
           if ( (($tmp) && ($tmp instanceof BlogHolder)) && (!$this->ParentID)) {
             $this->ParentID = $tmp->ID;
           }
           unset($tmp);
           }
        }
        parent::onBeforeWrite();
       }

    now there is just one issue how to publish a blog post from the model admin.
    i will have a look and keep u posted

  • carlos
    Avatar
    Community Member
    41 Posts

    Re: Blog management with Modeladmin Link to this post

    Hi teejay,

    You can try this (I haven't tested though).

    function onAfterWrite(){
    parent::onAfterWrite();
    $this->publish("stage","Live");
    }

    hope it helps.
    cheers
    Carlos

  • dizzystuff
    Avatar
    Community Member
    93 Posts

    Re: Blog management with Modeladmin Link to this post

    Hi teejay

    did you end up getting this working? (blog post management via modeladmin rather than site-tree)

    cheers

  • brice
    Avatar
    Community Member
    51 Posts

    Re: Blog management with Modeladmin Link to this post

    I have come up with a workaround as it was troublesome to get Save & Publish actions working in Model Admin. I bet with more time I could probably come up with the proper actions in EditForm() on my extension of ModelAdmin controller.... but the workaround is simple. It works by reloading the CMS to the SiteTree object (e.g. admin/show/[recordID]).

    Below is the code. When time avails I'd like to submit a patch to the core ModelAdmin_Recordcontroller that will detect if the currentRecord->is_a('SiteTree') and behave accordingly. Is there any interest in this?

    My problem with doing everything from SiteTree is that the interface gets troublesome (e.g. the create button often shows the wrong classes, clicking go creates multiple records, etc. etc.) -- which I presume will be cleaned up in the JS rewrite of 3.0.

    Here is:

    <?php

    class NewsAdmin extends ModelAdmin {
       public static $managed_models = array(
          'NewsPost'
       );
       
       public static $record_controller_class = "NewsAdmin_RecordController";

       static $url_segment = 'newsposts';
       static $menu_title = 'News Posts';
    }

    class NewsAdmin_RecordController extends ModelAdmin_RecordController {
       
       private function href(){
          // TODO: properly detect CMS URL, do not assume "[base]/admin"
          return Director::baseURL() . 'admin/show/' . $this->currentRecord->ID;
       }
       
       private function redirectHTML(){
          return '<script type="text/javascript">window.location = "' . $this->href() . '";</script>' .
             'Redirecting... please wait. <a href="' . $this->href() . '">Click here</a> to continue...';
       }
       
       function EditForm(){
          return new Form(
             $this,
             "EditForm",
             new FieldSet(
                new LiteralField('redirect', $this->redirectHTML())
             ),
             new FieldSet()
          );
       }
       
       function edit($request) {
          if ($this->currentRecord) {
             $href = Director::baseURL() . 'admin/show/' . $this->currentRecord->ID;
             return new SS_HTTPResponse(
                $this->redirectHTML(),
                200,
                sprintf("Redirecting to '%s' for editing.",$this->currentRecord->Title)
             );
          } else {
             return _t('ModelAdmin.ITEMNOTFOUND', "I can't find that item");
          }
       }

       function view($request) {
          if($this->currentRecord) {
             $href = $this->href();
             return new SS_HTTPResponse(
                $this->redirectHTML(),
                200,
                sprintf("Redirecting to '%s' for viewing.",$this->currentRecord->Title)
             );
          } else {
             return _t('ModelAdmin.ITEMNOTFOUND', "I can't find that item");
          }
       }
       
    }

  • Mo
    Avatar
    Community Member
    504 Posts

    Re: Blog management with Modeladmin Link to this post

    I don't know about anyone else, but i would love it if a model admin for Blog was part of the core blog module (maybe some you could enable/disable in your _config).

    I hear a lot of grumbles from clients who have used wordpress about how they prefer Wordpress' interface for blogging. I think maybe giving a 'posts' page, built on top of model admin might be a nice middle ground.

    brice: I agree about your comment on SiteTree's interface. Blogging is meant to be simple, click and post. I know you can use the /post action, but that does not seem to allow you to do things like attach images or use TinyMCE's full screen editor.

    Also, when you expand all your blog posts it can result in SiteTree becoming massively long :s.

    Mo

  • carlos
    Avatar
    Community Member
    41 Posts

    Re: Blog management with Modeladmin Link to this post

    Hi there,

    We want to improved Blog Module (ModelAdmin like) for Silverstripe 3.0

    cheers
    Carlos

  • guywatson
    Avatar
    Community Member
    15 Posts

    Re: Blog management with Modeladmin Link to this post

    Hi all

    This is amazing

    http://code.google.com/p/blogadmin/

    Thanks

    Guy

    2812 Views
Page: 1
Go to Top

Want to know more about the company that brought you SilverStripe? Then check out SilverStripe.com

Comments on this website? Please give feedback.