ModelAdmin actions removed for non-DataObjectAsPage #15

Closed
bruce133 opened this Issue Sep 25, 2012 · 2 comments

Projects

None yet

2 participants

@bruce133

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

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

This is no longer an issue when using SS3.x

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment