/** * Returns all fields on the object which should be shown * in the output. Can be customised through {@link self::setCustomFields()}. * * @todo Allow for custom getters on the processed object (currently filtered through inheritedDatabaseFields) * @todo Field level permission checks * * @param DataObject $obj * @return array */ protected function getFieldsForObj($obj) { $dbFields = array(); // if custom fields are specified, only select these if(is_array($this->customFields)) { foreach($this->customFields as $fieldName) { // @todo Possible security risk by making methods accessible - implement field-level security if($obj->hasField($fieldName) || $obj->hasMethod("get{$fieldName}")) $dbFields[$fieldName] = $fieldName; } } else { // by default, all database fields are selected $dbFields = $obj->inheritedDatabaseFields(); } if(is_array($this->customAddFields)) { foreach($this->customAddFields as $fieldName) { // @todo Possible security risk by making methods accessible - implement field-level security if($obj->hasField($fieldName) || $obj->hasMethod("get{$fieldName}")) $dbFields[$fieldName] = $fieldName; } } // add default required fields $dbFields = array_merge($dbFields, array('ID'=>'Int')); // @todo Requires PHP 5.1+ if(is_array($this->removeFields)) { $dbFields = array_diff_key($dbFields, array_combine($this->removeFields,$this->removeFields)); } return $dbFields; }
/** * @param DataObject $target * @return array */ public function getContextFields(DataObject $target) { $result = array(); if (!$target) { return $result; } $fields = $target->inheritedDatabaseFields(); foreach ($fields as $field => $fieldDesc) { $result[$field] = $target->{$field}; } if ($target instanceof CMSPreviewable) { $result['CMSLink'] = $target->CMSEditLink(); } else { if ($target->hasMethod('WorkflowLink')) { $result['CMSLink'] = $target->WorkflowLink(); } } return $result; }