Skip to main content

This site requires you to update your browser. Your browsing experience maybe affected by not having the most up to date version.

Customising the CMS

getCMSActions not working


Reply

2 Posts   1316 Views

Avatar
mattconfusion

19 July 2010 at 7:15pm Community Member, 48 Posts

Hi,

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");
$actions->push($Action);

return $actions;
}

Then I created a CMSActionDecorator.

<?php
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;
         $newDataObject->write();
}
      
         
   
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/
Thanks

Avatar
mattconfusion

19 July 2010 at 9:04pm Community Member, 48 Posts

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??