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);
|
$record->extend("onBulkFileUpload", $this->gridField);
|
||||||
|
|
||||||
//get uploadField and process upload
|
//get uploadField and process upload
|
||||||
//$fileRelationName = $this->getFileRelationName();
|
|
||||||
//$uploadField = $this->uploadForm()->Fields()->fieldByName($fileRelationName);
|
|
||||||
$uploadField = $this->getUploadField();
|
$uploadField = $this->getUploadField();
|
||||||
$uploadField->setRecord($record);
|
$uploadField->setRecord($record);
|
||||||
|
|
||||||
@ -174,11 +172,8 @@ class GridFieldBulkUpload_Request extends RequestHandler {
|
|||||||
// attached record to gridField relation
|
// attached record to gridField relation
|
||||||
$this->gridField->list->add($record->ID);
|
$this->gridField->list->add($record->ID);
|
||||||
|
|
||||||
//get record's CMS Fields
|
// fetch uploadedFile record and sort out previewURL
|
||||||
//$recordEditableFormFields = $this->getRecordHTMLFormFields( $record->ID );
|
// update $uploadResponse datas in case changes happened onAfterWrite()
|
||||||
|
|
||||||
//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'] );
|
$uploadedFile = DataObject::get_by_id( $this->component->getFileRelationClassName($this->gridField), $uploadResponse['id'] );
|
||||||
if ( $uploadedFile )
|
if ( $uploadedFile )
|
||||||
{
|
{
|
||||||
@ -187,13 +182,28 @@ class GridFieldBulkUpload_Request extends RequestHandler {
|
|||||||
|
|
||||||
if ( $uploadedFile instanceof Image )
|
if ( $uploadedFile instanceof Image )
|
||||||
{
|
{
|
||||||
$uploadResponse['preview_url'] = $uploadedFile->setHeight(50)->Link();
|
|
||||||
$uploadResponse['thumbnail_url'] = $uploadedFile->CroppedImage(30,30)->getURL();
|
$uploadResponse['thumbnail_url'] = $uploadedFile->CroppedImage(30,30)->getURL();
|
||||||
}
|
}
|
||||||
else{
|
else{
|
||||||
$uploadResponse['preview_url'] = $uploadedFile->Icon();
|
|
||||||
$uploadResponse['thumbnail_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
|
// Collect all data for JS template
|
||||||
|
Loading…
Reference in New Issue
Block a user