mirror of
https://github.com/colymba/GridFieldBulkEditingTools.git
synced 2024-10-22 11:05:57 +02:00
Add record default title/name
This commit is contained in:
parent
3092972d8e
commit
61b90d2aed
@ -155,8 +155,6 @@ class GridFieldBulkUpload_Request extends RequestHandler {
|
||||
$record->extend("onBulkFileUpload", $this->gridField);
|
||||
|
||||
//get uploadField and process upload
|
||||
//$fileRelationName = $this->getFileRelationName();
|
||||
//$uploadField = $this->uploadForm()->Fields()->fieldByName($fileRelationName);
|
||||
$uploadField = $this->getUploadField();
|
||||
$uploadField->setRecord($record);
|
||||
|
||||
@ -174,9 +172,6 @@ class GridFieldBulkUpload_Request extends RequestHandler {
|
||||
// attached record to gridField relation
|
||||
$this->gridField->list->add($record->ID);
|
||||
|
||||
//get record's CMS Fields
|
||||
//$recordEditableFormFields = $this->getRecordHTMLFormFields( $record->ID );
|
||||
|
||||
// fetch uploadedFile record and sort out previewURL
|
||||
// update $uploadResponse datas in case changes happened onAfterWrite()
|
||||
$uploadedFile = DataObject::get_by_id( $this->component->getFileRelationClassName($this->gridField), $uploadResponse['id'] );
|
||||
@ -187,13 +182,28 @@ class GridFieldBulkUpload_Request extends RequestHandler {
|
||||
|
||||
if ( $uploadedFile instanceof Image )
|
||||
{
|
||||
$uploadResponse['preview_url'] = $uploadedFile->setHeight(50)->Link();
|
||||
$uploadResponse['thumbnail_url'] = $uploadedFile->CroppedImage(30,30)->getURL();
|
||||
}
|
||||
else{
|
||||
$uploadResponse['preview_url'] = $uploadedFile->Icon();
|
||||
$uploadResponse['thumbnail_url'] = $uploadedFile->Icon();
|
||||
}
|
||||
|
||||
// check if our new record has a Title, if not create one automatically
|
||||
$title = $record->getTitle();
|
||||
if ( !$title || $title === $record->ID )
|
||||
{
|
||||
$title = basename($uploadedFile->getFilename());
|
||||
|
||||
if ( $record->hasDatabaseField('Title') )
|
||||
{
|
||||
$record->Title = $title;
|
||||
$record->write();
|
||||
}
|
||||
else if ($record->hasDatabaseField('Name')){
|
||||
$record->Name = $title;
|
||||
$record->write();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Collect all data for JS template
|
||||
|
Loading…
Reference in New Issue
Block a user