NEW Add cover image to a document
This commit is contained in:
parent
6b80f32832
commit
e1e5194c1c
|
@ -47,6 +47,10 @@ class DMSDocument extends DataObject implements DMSDocumentInterface
|
||||||
'Sets' => 'DMSDocumentSet'
|
'Sets' => 'DMSDocumentSet'
|
||||||
);
|
);
|
||||||
|
|
||||||
|
private static $has_one = array(
|
||||||
|
'CoverImage' => 'Image'
|
||||||
|
);
|
||||||
|
|
||||||
private static $many_many = array(
|
private static $many_many = array(
|
||||||
'RelatedDocuments' => 'DMSDocument',
|
'RelatedDocuments' => 'DMSDocument',
|
||||||
'Tags' => 'DMSTag',
|
'Tags' => 'DMSTag',
|
||||||
|
@ -906,8 +910,14 @@ class DMSDocument extends DataObject implements DMSDocumentInterface
|
||||||
$fieldsTop = $this->getFieldsForFile($relationList->count());
|
$fieldsTop = $this->getFieldsForFile($relationList->count());
|
||||||
$fields->add($fieldsTop);
|
$fields->add($fieldsTop);
|
||||||
|
|
||||||
$fields->add(new TextField('Title', 'Title'));
|
$fields->add(TextField::create('Title', _t('DMSDocument.TITLE', 'Title')));
|
||||||
$fields->add(new TextareaField('Description', 'Description'));
|
$fields->add(TextareaField::create('Description', _t('DMSDocument.DESCRIPTION', 'Description')));
|
||||||
|
|
||||||
|
$coverImageField = UploadField::create('CoverImage', _t('DMSDocument.COVERIMAGE', 'Cover Image'));
|
||||||
|
$coverImageField->getValidator()->setAllowedExtensions(array('jpg', 'jpeg', 'png', 'gif'));
|
||||||
|
$coverImageField->setConfig('allowedMaxFileNumber', 1);
|
||||||
|
$fields->add($coverImageField);
|
||||||
|
|
||||||
|
|
||||||
$downloadBehaviorSource = array(
|
$downloadBehaviorSource = array(
|
||||||
'open' => _t('DMSDocument.OPENINBROWSER', 'Open in browser'),
|
'open' => _t('DMSDocument.OPENINBROWSER', 'Open in browser'),
|
||||||
|
@ -1112,6 +1122,19 @@ class DMSDocument extends DataObject implements DMSDocumentInterface
|
||||||
return CompositeField::create($fields);
|
return CompositeField::create($fields);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Return a title to use on the frontend, preferably the "title", otherwise the filename without it's numeric ID
|
||||||
|
*
|
||||||
|
* @return string
|
||||||
|
*/
|
||||||
|
public function getTitle()
|
||||||
|
{
|
||||||
|
if ($this->getField('Title')) {
|
||||||
|
return $this->getField('Title');
|
||||||
|
}
|
||||||
|
return $this->FilenameWithoutID;
|
||||||
|
}
|
||||||
|
|
||||||
public function onBeforeWrite()
|
public function onBeforeWrite()
|
||||||
{
|
{
|
||||||
parent::onBeforeWrite();
|
parent::onBeforeWrite();
|
||||||
|
|
|
@ -9,6 +9,8 @@ en:
|
||||||
TYPE: 'File type'
|
TYPE: 'File type'
|
||||||
URL: URL
|
URL: URL
|
||||||
DMSDocument:
|
DMSDocument:
|
||||||
|
COVERIMAGE: Cover Image
|
||||||
|
DESCRIPTION: Description
|
||||||
EDIT: Edit
|
EDIT: Edit
|
||||||
EDITDOCUMENT: Edit this document
|
EDITDOCUMENT: Edit this document
|
||||||
PLURALNAME: Documents
|
PLURALNAME: Documents
|
||||||
|
@ -18,6 +20,7 @@ en:
|
||||||
Versions: Versions
|
Versions: Versions
|
||||||
DOWNLOAD: "Download {title}"
|
DOWNLOAD: "Download {title}"
|
||||||
LASTCHANGED: "Last changed: {date}"
|
LASTCHANGED: "Last changed: {date}"
|
||||||
|
TITLE: Title
|
||||||
DMSDocumentSet:
|
DMSDocumentSet:
|
||||||
ADDDOCUMENTBUTTON: Add Document
|
ADDDOCUMENTBUTTON: Add Document
|
||||||
ADDDOCUMENTSBUTTON: Add Documents
|
ADDDOCUMENTSBUTTON: Add Documents
|
||||||
|
|
|
@ -1,9 +1,11 @@
|
||||||
<% if not $isHidden %>
|
<% if not $isHidden %>
|
||||||
<div class="document $Extension">
|
<div class="document $Extension">
|
||||||
<% if $Title %>
|
<h4><a href="$Link" title="<%t DMSDocument.DOWNLOAD "Download {title}" title=$getTitle %>">$getTitle</a></h4>
|
||||||
<h4><a href="$Link" title="<%t DMSDocument.DOWNLOAD "Download {title}" title=$Title %>">$Title</a></h4>
|
|
||||||
<% else %>
|
<% if $CoverImage %>
|
||||||
<h4><a href="$Link" title="<%t DMSDocument.DOWNLOAD "Download {title}" title=$FilenameWithoutID %>">$FilenameWithoutID</a></h4>
|
<div class="article-thumbnail">
|
||||||
|
$CoverImage.FitMax(100, 100)
|
||||||
|
</div>
|
||||||
<% end_if %>
|
<% end_if %>
|
||||||
|
|
||||||
<p class="details"><% include DocumentDetails %></p>
|
<p class="details"><% include DocumentDetails %></p>
|
||||||
|
|
|
@ -247,4 +247,16 @@ class DMSDocumentTest extends SapphireTest
|
||||||
$this->assertCount(3, $result, 'Document 1 is related to 3 Pages');
|
$this->assertCount(3, $result, 'Document 1 is related to 3 Pages');
|
||||||
$this->assertSame(array('s1', 's2', 's3'), $result->column('URLSegment'));
|
$this->assertSame(array('s1', 's2', 's3'), $result->column('URLSegment'));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Test that the title is returned if it is set, otherwise the filename without ID
|
||||||
|
*/
|
||||||
|
public function testGetTitleOrFilenameWithoutId()
|
||||||
|
{
|
||||||
|
$d1 = $this->objFromFixture('DMSDocument', 'd1');
|
||||||
|
$this->assertSame('test-file-file-doesnt-exist-1', $d1->getTitle());
|
||||||
|
|
||||||
|
$d2 = $this->objFromFixture('DMSDocument', 'd2');
|
||||||
|
$this->assertSame('File That Doesn\'t Exist (Title)', $d2->getTitle());
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -78,6 +78,7 @@ DMSDocument:
|
||||||
d2:
|
d2:
|
||||||
Filename: test-file-file-doesnt-exist-2
|
Filename: test-file-file-doesnt-exist-2
|
||||||
Folder: 5
|
Folder: 5
|
||||||
|
Title: File That Doesn't Exist (Title)
|
||||||
Tags: =>DMSTag.t5, =>DMSTag.t6
|
Tags: =>DMSTag.t5, =>DMSTag.t6
|
||||||
Sets: =>DMSDocumentSet.ds1, =>DMSDocumentSet.ds2, =>DMSDocumentSet.ds3, =>DMSDocumentSet.ds4
|
Sets: =>DMSDocumentSet.ds1, =>DMSDocumentSet.ds2, =>DMSDocumentSet.ds3, =>DMSDocumentSet.ds4
|
||||||
document_with_relations:
|
document_with_relations:
|
||||||
|
|
Loading…
Reference in New Issue