Skip to content

Commit

Permalink
Merge branch '2.2-checkbox-radio-class' into 2.2
Browse files Browse the repository at this point in the history
* 2.2-checkbox-radio-class:
  Use class specified in theme config for radio/checkbox inputs
  Allow override css settings by request prefix
  • Loading branch information
rchavik committed Nov 20, 2014
2 parents 0f579e6 + 28b05fb commit 57b259d
Show file tree
Hide file tree
Showing 3 changed files with 58 additions and 10 deletions.
28 changes: 28 additions & 0 deletions Croogo/Test/Case/View/Helper/CroogoFormHelperTest.php
Expand Up @@ -494,4 +494,32 @@ public function testInputPlaceholderNestedModel() {
$this->assertTags($result, $expected);
}

/**
* Test radio button class
*/
public function testInputRadioButtonClass() {
$result = $this->CroogoForm->input('Node.promote', array(
'type' => 'radio',
'class' => 'super-radio-button',
'options' => array(
0 => 'Not promoted',
1 => 'Promoted',
),
));
$this->assertStringStartsWith('<div class="input radio">', $result);
$this->assertContains('class="super-radio-button"', $result);
}

/**
* Test checkbox class
*/
public function testInputCheckboxClass() {
$result = $this->CroogoForm->input('Node.promote', array(
'type' => 'checkbox',
'class' => 'super-checkbox-button',
));
$this->assertStringStartsWith('<div class="input checkbox">', $result);
$this->assertContains('class="super-checkbox-button"', $result);
}

}
28 changes: 19 additions & 9 deletions Croogo/View/Helper/CroogoFormHelper.php
Expand Up @@ -158,15 +158,25 @@ protected function _parseOptions($options) {
$options = parent::_parseOptions($options);
$options = $this->_parseOptionsAddon($options);

if (isset($options['class'])) {
$formInput = $this->Theme->getCssClass('formInput');
$isMultipleCheckbox = isset($options['multiple']) &&
$options['multiple'] === 'checkbox';
$isRadioOrCheckbox = isset($options['type']) &&
in_array($options['type'], array('checkbox', 'radio'));

if ($isMultipleCheckbox || $isRadioOrCheckbox) {
$options['class'] = str_replace($formInput, '', $options['class']);
$formInput = $this->Theme->getCssClass('formInput');
$isMultipleCheckbox = isset($options['multiple']) &&
$options['multiple'] === 'checkbox';
$isRadioOrCheckbox = isset($options['type']) &&
in_array($options['type'], array('checkbox', 'radio'));

if ($isMultipleCheckbox || $isRadioOrCheckbox) {
if ($options['type'] == 'radio') {
$class = $this->Theme->getCssClass('radioClass');
} elseif ($options['type'] == 'checkbox') {
$class = $this->Theme->getCssClass('checkboxClass');
}
if (empty($class) && isset($options['class'])) {
$class = str_replace($formInput, '', $options['class']);
}
if (empty($class)) {
unset($options['class']);
} else {
$options['class'] = $class;
}
}

Expand Down
12 changes: 11 additions & 1 deletion Extensions/Lib/CroogoTheme.php
Expand Up @@ -287,7 +287,17 @@ public static function config($theme = null) {
}

if (empty($themeData[$theme])) {
$themeData[$theme] = $croogoTheme->getData($theme);
$data = $croogoTheme->getData($theme);
$request = Router::getRequest();
if ($request) {
$prefix = $request->param('prefix');
if (isset($data['settings']['prefixes'][$prefix]['css'])) {
$data['settings']['css'] = Hash::merge($data['settings']['prefixes'][$prefix]['css'],
$data['settings']['css']
);
}
}
$themeData[$theme] = $data;
}

return $themeData[$theme];
Expand Down

0 comments on commit 57b259d

Please sign in to comment.