Jump to:

5540 Posts in 1738 Topics by 1224 members

Customising the CMS

SilverStripe Forums » Customising the CMS » getCMSActions not working

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

Page: 1
Go to End
Author Topic: 1302 Views
  • mattconfusion
    Community Member
    48 Posts

    getCMSActions not working Link to this post


    I followed advices and how to's here about adding buttons and functions inside the cms. What i want to do is basically copy values from a set of dataojbects and create a new set of data objects using those values, as a duplication.
    So i used getCMSactions. I set up in my page type a function like this

    function getCMSActions(){

    $actions = parent::getCMSActions();
    $Action = new FormAction("doAction", "Import values");

    return $actions;

    Then I created a CMSActionDecorator.

    class CMSActionDecorator extends LeftAndMainDecorator {

    function doAction(){
          $id = (int)$_REQUEST['ID'];
          $thisPage = DataObject::get_one('MyPage', 'ID ='. $id);
          $group = DataObject::get_one('MyPageGroup', 'ID =' . $thisPage->ParentID);
          $generalvaluespage= DataObject::get_one('GeneralValuesPage', 'Name = ' .$group->Title);
          $dataObjectToBeDuplicated = DataObject::get('DataObjectToBeDuplicated' , "CategoryID =". $generalvaluespage->ID);
          foreach($dataObjectToBeDuplicated as $do){
             $newDataObject = new MyDataObject;
             $newDataObject->Value1 = $do->Value1;
             $newDataObject->Value2 = $do->Value2;
    FormResponse::status_message(sprintf('All good!'),'good');
    return FormResponse::respond();

    Then I added the extension line on _config as usual: Object::add_extension('CMSMain', 'CMSActionDecorator');
    THis is not working. An error messagge inside the CMS says "SERVER ERROR". If i erase eveything except the request lines, it seems to be workin (no error messages, just the All Good green one). Anyone has clues?
    I used this tutorial http://www.ssbits.com/adding-a-cms-action-the-slightly-hacky-way/

  • mattconfusion
    Community Member
    48 Posts

    Re: getCMSActions not working Link to this post

    I've discovered a couple of mistakes. Still not working. The wrong part is actually the part in which I try to access the dataobjects, the dataobject ceration itself works. I can avoid the first Get, since having the ID of the page I can even have in the same way the ParentID. so:

    function doAction(){
          $id = (int)$_REQUEST['ID'];
          $parentid = (int)$_REQUEST['ParentID'];

    What is not working is the DataObject::get or get_one part that acts on the pages (I know because i've made lots of tests). The get or get one is working only if no where conditions are inserted? why??

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.