FIX Update getIcon resource resolution methods

This commit is contained in:
Robbie Averill 2017-11-03 10:44:45 +13:00
parent 077d1463ed
commit ccf8f86bf8
4 changed files with 41 additions and 4 deletions

View File

@ -599,8 +599,17 @@ class EditableFormField extends DataObject
*/
public function getIcon()
{
return ModuleLoader::getModule('silverstripe/userforms')
->getRelativeResourcePath('images/' . strtolower($this->class) . '.png');
$classNamespaces = explode("\\", static::class);
$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()
{
return ModuleLoader::getModule('silverstripe/userforms')
->getRelativeResourcePath('images/editabledropdown.png');
$resource = ModuleLoader::getModule('silverstripe/userforms')->getResource('images/editabledropdown.png');
if (!$resource->exists()) {
return '';
}
return $resource->getURL();
}
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
$this->assertSame('removeClass("hide")', $displayRules['opposite']);
}
public function testGetIcon()
{
$field = new EditableTextField;
$this->assertContains('/images/editabletextfield.png', $field->getIcon());
}
}