From 1e260d2b48eb953a3c1122ef18c4b25e44a1688b Mon Sep 17 00:00:00 2001 From: colymba Date: Sat, 28 Jul 2012 14:17:19 +0300 Subject: [PATCH] API: Request Handler use $config + EditingTools --- code/GridFieldBulkImageUpload_Request.php | 37 ++++++++++++++++++++--- 1 file changed, 33 insertions(+), 4 deletions(-) diff --git a/code/GridFieldBulkImageUpload_Request.php b/code/GridFieldBulkImageUpload_Request.php index 40a2fbc..c45aa71 100644 --- a/code/GridFieldBulkImageUpload_Request.php +++ b/code/GridFieldBulkImageUpload_Request.php @@ -75,7 +75,7 @@ class GridFieldBulkImageUpload_Request extends RequestHandler { */ function getRecordImageField() { - $fieldName = $this->component->getRecordImageField(); + $fieldName = $this->component->getConfig('imageFieldName'); if ( $fieldName == null ) $fieldName = $this->getDefaultRecordImageField(); return $fieldName; @@ -89,7 +89,7 @@ class GridFieldBulkImageUpload_Request extends RequestHandler { */ function getRecordEditableFields() { - $fields = $this->component->getRecordEditableFields(); + $fields = $this->component->getConfig('editableFields'); if ( $fields == null ) $fields = $this->getDefaultRecordEditableFields(); return $fields; @@ -122,6 +122,7 @@ class GridFieldBulkImageUpload_Request extends RequestHandler { * * @return array */ + /* function getDefaultRecordEditableFields() { $recordClass = $this->gridField->list->dataClass; @@ -137,6 +138,7 @@ class GridFieldBulkImageUpload_Request extends RequestHandler { return $editableFields; } + */ /** * Return the CMS edit field for a given name. As set in the GridField managed DataObject getCMSFields method @@ -144,6 +146,7 @@ class GridFieldBulkImageUpload_Request extends RequestHandler { * @param string $fieldName * @return FormField */ + /* function getFieldEditForm($fieldName) { if ( !$this->recordCMSFieldList ) { @@ -160,6 +163,27 @@ class GridFieldBulkImageUpload_Request extends RequestHandler { return $field; } + */ + + function getRecordHTMLFormFields( $recordID = 0 ) + { + $config = $this->component->getConfig(); + $recordCMSDataFields = GridFieldBulkEditingTools::getModelCMSDataFields( $config, $this->gridField->list->dataClass ); + + //@TODO: if editableFields given use them with filterNonEditableRecordsFields() + // otherwise go through getModelFilteredDataFields + + + $recordCMSDataFields = GridFieldBulkEditingTools::filterNonEditableRecordsFields($config, $recordCMSDataFields); + + if ( $config['imageFieldName'] == null ) $config['imageFieldName'] = $this->getDefaultRecordImageField(); + + $recordCMSDataFields = GridFieldBulkEditingTools::getModelFilteredDataFields($config, $recordCMSDataFields); + $formFieldsHTML = GridFieldBulkEditingTools::dataFieldsToHTML($recordCMSDataFields); + $formFieldsHTML = GridFieldBulkEditingTools::escapeFormFieldsHTML($formFieldsHTML, $recordID); + + return $formFieldsHTML; + } /** * Default and main action that returns the upload form etc... @@ -306,8 +330,12 @@ class GridFieldBulkImageUpload_Request extends RequestHandler { $record->setField($this->getRecordImageField(), $file->ID); $record->write(); + //get record's CMS Fields + $recordEditableFormFields = $this->getRecordHTMLFormFields( $record->ID ); - // collect all editable fields forms + + // collect all editable fields forms + /* $recordEditableFieldsForms = array(); foreach ( $this->getRecordEditableFields() as $editableFieldName ) { @@ -316,6 +344,7 @@ class GridFieldBulkImageUpload_Request extends RequestHandler { array_push($recordEditableFieldsForms, $this->parseFieldHTMLWithRecordID($formField->FieldHolder(), $record->ID) ); } } + */ // Collect all output data. $return = array_merge($return, array( @@ -328,7 +357,7 @@ class GridFieldBulkImageUpload_Request extends RequestHandler { //'buttons' => $file->UploadFieldFileButtons, 'record' => array( 'ID' => $record->ID, - 'fields' => $recordEditableFieldsForms + 'fields' => $recordEditableFormFields ) ));