Merge pull request #91 from open-sausages/pulls/4.0/compat
BUG Fix issue with initial save
This commit is contained in:
commit
57bf2c15ce
|
@ -327,8 +327,7 @@ class TagField extends DropdownField
|
||||||
if (!$values) {
|
if (!$values) {
|
||||||
$values = array();
|
$values = array();
|
||||||
}
|
}
|
||||||
|
if (empty($record) || empty($titleField)) {
|
||||||
if (empty($record) || empty($source) || empty($titleField)) {
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -313,6 +313,32 @@ class TagFieldTest extends SapphireTest
|
||||||
$record
|
$record
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Test you can save without a source set
|
||||||
|
*/
|
||||||
|
public function testSaveEmptySource()
|
||||||
|
{
|
||||||
|
$record = new TagFieldTestBlogPost();
|
||||||
|
$record->write();
|
||||||
|
|
||||||
|
// Clear database of tags
|
||||||
|
TagFieldTestBlogTag::get()->removeAll();
|
||||||
|
|
||||||
|
$field = new TagField('Tags', '', TagFieldTestBlogTag::get());
|
||||||
|
$field->setValue(['New Tag']);
|
||||||
|
$field->setCanCreate(true);
|
||||||
|
$field->saveInto($record);
|
||||||
|
|
||||||
|
$tag = TagFieldTestBlogTag::get()->first();
|
||||||
|
$this->assertNotEmpty($tag);
|
||||||
|
$this->assertEquals('New Tag', $tag->Title);
|
||||||
|
$record = TagFieldTestBlogPost::get()->byID($record->ID);
|
||||||
|
$this->assertEquals(
|
||||||
|
$tag->ID,
|
||||||
|
$record->Tags()->first()->ID
|
||||||
|
);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
class TagFieldTestBlogTag extends DataObject implements TestOnly
|
class TagFieldTestBlogTag extends DataObject implements TestOnly
|
||||||
|
|
Loading…
Reference in New Issue