Skip to content

Instantly share code, notes, and snippets.

@mariuswilms
Last active September 2, 2016 08:27
Show Gist options
  • Save mariuswilms/2e7f5ad18b9f6ee80423 to your computer and use it in GitHub Desktop.
Save mariuswilms/2e7f5ad18b9f6ee80423 to your computer and use it in GitHub Desktop.
li3_custom_form_helper.php
<?php
namespace app\extensions\helper;
class Form extends \lithium\template\helper\Form {
public function field($name, array $options = array()) {
$options += [
'class' => null,
'type' => isset($options['list']) ? 'select' : 'text',
'wrap' => []
];
if (!isset($options['wrap']['class'])) {
$options['wrap']['class'] = '';
}
$class = ['field'];
if ($options['type']) {
if (in_array($options['type'], ['checkbox', 'radio'])) {
$class[] = 'field-type-' . $options['type'];
$class[] = 'field-type-checkable';
} elseif (in_array($options['type'], ['select'])) {
$class[] = 'field-type-' . $options['type'];
} elseif (in_array($options['type'], ['textarea'])) {
$class[] = 'field-type-' . $options['type'];
} elseif (in_array($options['type'], ['number'])) {
// We're not there yet. Browser styling lacks.
$options['type'] = 'text';
$class[] = 'field-type-textual';
$class[] = 'field-type-numeric';
} else {
$class[] = 'field-type-' . $options['type'];
$class[] = 'field-type-textual';
}
$class[] = 'field-name-' . str_replace(['_', '.'], '-', $name);
}
if (isset($options['label']) && is_string($options['label'])) {
$length = strlen($options['label']);
if ($length > 25) {
$class[] = 'field-label-beta';
} elseif ($length > 15) {
$class[] = 'field-label-gamma';
} else {
$class[] = 'field-label-delta';
}
}
$options['class'] .= ($options['class'] ? ' ' : null) . 'input';
$options['wrap']['class'] .= ($options['wrap']['class'] ? ' ' : null) . implode(' ', $class);
return parent::field($name, $options);
}
}
?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment