Last active
September 2, 2016 08:27
-
-
Save mariuswilms/2e7f5ad18b9f6ee80423 to your computer and use it in GitHub Desktop.
li3_custom_form_helper.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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