arambalakjian / DataObject-as-Page

A SilverStripe module for displaying DataObjects as Pages
53 stars 27 forks source link

ModelAdmin actions removed for non-DataObjectAsPage #15

Closed bruce133 closed 11 years ago

bruce133 commented 12 years ago

DataObjectAsPageAdmin.php removes the default actions from the EditForm, which becomes a problem when using the same instance of ModelAdmin to manage other DataObjects (as opposed to DataObjectAsPage objects).

I've added a simple check so that the actions are only removed if the parent class of the record is DataObjectAsPage.

Note: This is my first patch submission, so please forgive me if this isn't the proper way to do it.

diff --git a/DataObjects-as-Pages/code/ModelAdmin/DataObjectAsPageAdmin.php b/DataObjects-as-Pages/code/ModelAdmin/DataObjectAsPageAdmin.php
index 0b6021a..f0aaff6 100644
--- a/DataObjects-as-Pages/code/ModelAdmin/DataObjectAsPageAdmin.php
+++ b/DataObjects-as-Pages/code/ModelAdmin/DataObjectAsPageAdmin.php
@@ -99,15 +99,17 @@ class DataObjectAsPageAdmin_RecordController extends ModelAdmin_RecordController
         } else {
             Director::redirectBack();
         }
-       }
+   }

-       public function EditForm() {
+   public function EditForm() {
        $form = parent::EditForm();
        $fields = $form->Actions();
-       $fields->removeByName('action_doSave');
-       $fields->removeByName('action_doDelete');
-       $fields->removeByName('action_goForward');
-       $fields->removeByName('action_goBack');
+       if (get_parent_class($this->currentRecord) == 'DataObjectAsPage') {
+           $fields->removeByName('action_doSave');
+           $fields->removeByName('action_doDelete');
+           $fields->removeByName('action_goForward');
+           $fields->removeByName('action_goBack');
+       }
        $form->setActions ($fields);    
        return $form;
    }   
arambalakjian commented 12 years ago

Hi Bruce,

Thanks for this, we actually just came across this issue too! My appologies for only just getting around to reviewing this.

I think the way to submit it is by doing a 'pull request' so that I can just click 'merge' and it will go into the repo.

Cheers,

Aram

arambalakjian commented 11 years ago

This is no longer an issue when using SS3.x