Skip to content

Commit

Permalink
Enhancement moving usage fields into the details tab until further no…
Browse files Browse the repository at this point in the history
…tice
  • Loading branch information
Christopher Joe committed Aug 23, 2017
1 parent 7e6d0f0 commit c8b036b
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 25 deletions.
34 changes: 11 additions & 23 deletions code/Forms/FileFormFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,7 @@ protected function getFormFieldTabs($record, $context = [])
$tabs = TabSet::create(
'Editor',
$this->getFormFieldDetailsTab($record, $context),
$this->getFormFieldSecurityTab($record, $context),
$this->getFormFieldUsageTab($record, $context)
$this->getFormFieldSecurityTab($record, $context)
);

if ($this->config()->get('show_history')) {
Expand All @@ -55,38 +54,27 @@ protected function getFormFieldTabs($record, $context = [])
return $tabs;
}

/**
* Build "Usage" tab
*
* @param File $record
* @param array $context
* @return Tab
*/
protected function getFormFieldUsageTab($record, $context = [])
protected function getFormFieldDetailsTab($record, $context = [])
{
// Add new tab for usage
return Tab::create(
'Usage',
// Update details tab
$tab = parent::getFormFieldDetailsTab($record, $context);

$tab->insertBefore('Name', TextField::create("Title", File::singleton()->fieldLabel('Title')));

$tab->push(
DatetimeField::create(
"Created",
_t('SilverStripe\\AssetAdmin\\Controller\\AssetAdmin.CREATED', 'First uploaded')
)
->setReadonly(true),
->setReadonly(true)
);
$tab->push(
DatetimeField::create(
"LastEdited",
_t('SilverStripe\\AssetAdmin\\Controller\\AssetAdmin.LASTEDIT', 'Last changed')
)
->setReadonly(true)
);
}

protected function getFormFieldDetailsTab($record, $context = [])
{
// Update details tab
$tab = parent::getFormFieldDetailsTab($record, $context);

$tab->insertBefore('Name', TextField::create("Title", File::singleton()->fieldLabel('Title')));

if ($this->getFormType($context) !== static::TYPE_ADMIN) {
$tab->push(LiteralField::create(
'EditLink',
Expand Down
3 changes: 1 addition & 2 deletions tests/php/Forms/FileFormBuilderTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -76,8 +76,7 @@ public function testEditFileForm()
$this->assertContains('document_92.png', $state['data']['preview']);
$this->assertEquals('document', $state['data']['category']);

// Usage tab
$uploaded = $form->Fields()->fieldByName('Editor.Usage.Created');
$uploaded = $form->Fields()->fieldByName('Editor.Details.Created');
$this->assertEquals(
$file->Created,
$uploaded->dataValue()
Expand Down

0 comments on commit c8b036b

Please sign in to comment.