Merge pull request #683 from creative-commoners/pulls/5.0/update-icon-paths

FIX Update getIcon resource resolution methods
This commit is contained in:
Dylan Wagstaff 2017-11-03 14:40:13 +13:00 committed by GitHub
commit bcadbad092
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 41 additions and 4 deletions

View File

@ -599,8 +599,17 @@ class EditableFormField extends DataObject
*/ */
public function getIcon() public function getIcon()
{ {
return ModuleLoader::getModule('silverstripe/userforms') $classNamespaces = explode("\\", static::class);
->getRelativeResourcePath('images/' . strtolower($this->class) . '.png'); $shortClass = end($classNamespaces);
$resource = ModuleLoader::getModule('silverstripe/userforms')
->getResource('images/' . strtolower($shortClass) . '.png');
if (!$resource->exists()) {
return '';
}
return $resource->getURL();
} }
/** /**

View File

@ -55,8 +55,13 @@ class EditableCountryDropdownField extends EditableFormField
public function getIcon() public function getIcon()
{ {
return ModuleLoader::getModule('silverstripe/userforms') $resource = ModuleLoader::getModule('silverstripe/userforms')->getResource('images/editabledropdown.png');
->getRelativeResourcePath('images/editabledropdown.png');
if (!$resource->exists()) {
return '';
}
return $resource->getURL();
} }
public function getSelectorField(EditableCustomRule $rule, $forOnLoad = false) public function getSelectorField(EditableCustomRule $rule, $forOnLoad = false)

View File

@ -0,0 +1,16 @@
<?php
namespace SilverStripe\UserForms\Tests\Model\EditableFormField;
use SilverStripe\Dev\SapphireTest;
use SilverStripe\UserForms\Model\EditableFormField\EditableCountryDropdownField;
class EditableCountryDropdownFieldTest extends SapphireTest
{
public function testGetIcon()
{
$field = new EditableCountryDropdownField;
$this->assertContains('/images/editabledropdown.png', $field->getIcon());
}
}

View File

@ -229,4 +229,11 @@ class EditableFormFieldTest extends FunctionalTest
// The opposite method should be to return it to its original state, i.e. show it again // The opposite method should be to return it to its original state, i.e. show it again
$this->assertSame('removeClass("hide")', $displayRules['opposite']); $this->assertSame('removeClass("hide")', $displayRules['opposite']);
} }
public function testGetIcon()
{
$field = new EditableTextField;
$this->assertContains('/images/editabletextfield.png', $field->getIcon());
}
} }