fieldsilverstripedata-objects

Silverstripe 3: removeByName not working


Good morning,

I've been trying to use the removeByName method and it doesn't work. I'm basically trying to hide a field in my DataObject within the forms that's generated by ModelAdmin, which manages the object.

See sample code below:

///DataObject snippet...
class MyObject extends DataObject{
   public static $db = array(
       'Title' => 'Varchar',
       'Desc' => 'Text',
       'Template' => 'HTMLText',
   );

   //@Override
   public function getCMSField(){
       $fields = parent::getCMSField();
       $fields->removeByName('Template'); /// DOESN'T WORK!!!
       return $fields;
   }

}//class

Note: I'm not getting any errors. I'm just still seeing the field on the forms (Add and Edit) as usual.

Any help appreciated, thanks.


Solution

  • Okay, I found the issue.

    I was just going over the API again for the millionth time, and recognized that I've named the function wrong. See correction below:

    ///Correction, forgot to add the 's' at the end of both the function and the parent call.
    public function getCMSFields(){
        $fields = parent::getCMSFields();
    }
    

    I can understand an error not being generated in Apache logs for the function because it's legit. But as for the parent call, it should of generated an error since the method don't exists. (Theory: Perhaps, since the function was never actually being called, the parent call wasn't being executed and thus no errors [run-time error]).