mirror of
https://github.com/silverstripe/silverstripe-framework
synced 2024-10-22 14:05:37 +02:00
Merge pull request #7302 from robbieaverill/pulls/4.0/has-class-returns-bool
API Make FormField::hasClass return a boolean instead of an int
This commit is contained in:
commit
d5b3280498
@ -1247,17 +1247,16 @@ class FormField extends RequestHandler
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns whether the current field has the given class added
|
||||
*
|
||||
* @param string $class
|
||||
*
|
||||
* @return int
|
||||
* @return bool
|
||||
*/
|
||||
public function hasClass($class)
|
||||
{
|
||||
$patten = '/' . strtolower($class) . '/i';
|
||||
|
||||
$subject = strtolower(static::class . ' ' . $this->extraClass());
|
||||
|
||||
return preg_match($patten, $subject);
|
||||
$classes = explode(' ', strtolower($this->extraClass()));
|
||||
return in_array(strtolower(trim($class)), $classes);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -373,4 +373,15 @@ class FormFieldTest extends SapphireTest
|
||||
$schema['message']['value']
|
||||
);
|
||||
}
|
||||
|
||||
public function testHasClass()
|
||||
{
|
||||
$field = new FormField('Test');
|
||||
$field->addExtraClass('foo BAr cool-banana');
|
||||
|
||||
$this->assertTrue($field->hasClass('foo'));
|
||||
$this->assertTrue($field->hasClass('bAr'));
|
||||
$this->assertFalse($field->hasClass('banana'));
|
||||
$this->assertTrue($field->hasClass('cool-BAnana'));
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user