mirror of
https://github.com/silverstripe/silverstripe-framework
synced 2024-10-22 12:05:37 +00:00
FIX Folder Title not being exactly the same as Name field
Backport to 3.0 of PR #3086
This commit is contained in:
parent
fc8da3fb1d
commit
ad27cd5ec9
@ -603,11 +603,6 @@ class File extends DataObject {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Update title
|
|
||||||
if(!$this->getField('Title')) {
|
|
||||||
$this->__set('Title', str_replace(array('-','_'),' ', preg_replace('/\.[^.]+$/', '', $name)));
|
|
||||||
}
|
|
||||||
|
|
||||||
// Update actual field value
|
// Update actual field value
|
||||||
$this->setField('Name', $name);
|
$this->setField('Name', $name);
|
||||||
|
|
||||||
@ -615,7 +610,12 @@ class File extends DataObject {
|
|||||||
// Important: Circumvent the getter to avoid infinite loops
|
// Important: Circumvent the getter to avoid infinite loops
|
||||||
$this->setField('Filename', $this->getRelativePath());
|
$this->setField('Filename', $this->getRelativePath());
|
||||||
|
|
||||||
return $this->getField('Name');
|
// Update title
|
||||||
|
if(!$this->Title) {
|
||||||
|
$this->Title = str_replace(array('-','_'),' ', preg_replace('/\.[^.]+$/', '', $name));
|
||||||
|
}
|
||||||
|
|
||||||
|
return $name;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -334,13 +334,16 @@ class Folder extends File {
|
|||||||
* Note that this is not appropriate for files, because someone might want to create a human-readable name
|
* Note that this is not appropriate for files, because someone might want to create a human-readable name
|
||||||
* of a file that is different from its name on disk. But folders should always match their name on disk. */
|
* of a file that is different from its name on disk. But folders should always match their name on disk. */
|
||||||
public function setTitle($title) {
|
public function setTitle($title) {
|
||||||
$this->setField('Title',$title);
|
$this->setName($title);
|
||||||
parent::setName($title); //set the name and filename to match the title
|
}
|
||||||
|
|
||||||
|
public function getTitle() {
|
||||||
|
return $this->Name;
|
||||||
}
|
}
|
||||||
|
|
||||||
public function setName($name) {
|
public function setName($name) {
|
||||||
$this->setField('Title',$name);
|
|
||||||
parent::setName($name);
|
parent::setName($name);
|
||||||
|
$this->setField('Title', $this->Name);
|
||||||
}
|
}
|
||||||
|
|
||||||
public function setFilename($filename) {
|
public function setFilename($filename) {
|
||||||
|
@ -294,4 +294,19 @@ class FolderTest extends SapphireTest {
|
|||||||
parent::tearDown();
|
parent::tearDown();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function testTitleTiedToName() {
|
||||||
|
$newFolder = new Folder();
|
||||||
|
|
||||||
|
$newFolder->Name = 'TestNameCopiedToTitle';
|
||||||
|
$this->assertEquals($newFolder->Name, $newFolder->Title);
|
||||||
|
|
||||||
|
$newFolder->Title = 'TestTitleCopiedToName';
|
||||||
|
$this->assertEquals($newFolder->Name, $newFolder->Title);
|
||||||
|
|
||||||
|
$newFolder->Name = 'TestNameWithIllegalCharactersCopiedToTitle <!BANG!>';
|
||||||
|
$this->assertEquals($newFolder->Name, $newFolder->Title);
|
||||||
|
|
||||||
|
$newFolder->Title = 'TestTitleWithIllegalCharactersCopiedToName <!BANG!>';
|
||||||
|
$this->assertEquals($newFolder->Name, $newFolder->Title);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user