@@ -139,7 +139,7 @@ |
||
| 139 | 139 | $classes = array_intersect($classes, $this->fields); |
| 140 | 140 | |
| 141 | 141 | // Prepend field type |
| 142 | - $classes = array_map(function ($class) { |
|
| 142 | + $classes = array_map(function($class) { |
|
| 143 | 143 | return Str::startsWith($class, 'col') ? $class : 'input-'.$class; |
| 144 | 144 | }, $classes); |
| 145 | 145 | |
@@ -13,437 +13,437 @@ |
||
| 13 | 13 | */ |
| 14 | 14 | class TwitterBootstrap3 extends Framework implements FrameworkInterface |
| 15 | 15 | { |
| 16 | - /** |
|
| 17 | - * Form types that trigger special styling for this Framework |
|
| 18 | - * |
|
| 19 | - * @var array |
|
| 20 | - */ |
|
| 21 | - protected $availableTypes = array('horizontal', 'vertical', 'inline'); |
|
| 22 | - |
|
| 23 | - /** |
|
| 24 | - * The button types available |
|
| 25 | - * |
|
| 26 | - * @var array |
|
| 27 | - */ |
|
| 28 | - private $buttons = array( |
|
| 29 | - 'lg', |
|
| 30 | - 'sm', |
|
| 31 | - 'xs', |
|
| 32 | - 'block', |
|
| 33 | - 'link', |
|
| 34 | - 'default', |
|
| 35 | - 'primary', |
|
| 36 | - 'warning', |
|
| 37 | - 'danger', |
|
| 38 | - 'success', |
|
| 39 | - 'info', |
|
| 40 | - ); |
|
| 41 | - |
|
| 42 | - /** |
|
| 43 | - * The field sizes available |
|
| 44 | - * |
|
| 45 | - * @var array |
|
| 46 | - */ |
|
| 47 | - private $fields = array( |
|
| 48 | - 'lg', |
|
| 49 | - 'sm', |
|
| 50 | - // 'col-xs-1', 'col-xs-2', 'col-xs-3', 'col-xs-4', 'col-xs-5', 'col-xs-6', |
|
| 51 | - // 'col-xs-7', 'col-xs-8', 'col-xs-9', 'col-xs-10', 'col-xs-11', 'col-xs-12', |
|
| 52 | - // 'col-sm-1', 'col-sm-2', 'col-sm-3', 'col-sm-4', 'col-sm-5', 'col-sm-6', |
|
| 53 | - // 'col-sm-7', 'col-sm-8', 'col-sm-9', 'col-sm-10', 'col-sm-11', 'col-sm-12', |
|
| 54 | - // 'col-md-1', 'col-md-2', 'col-md-3', 'col-md-4', 'col-md-5', 'col-md-6', |
|
| 55 | - // 'col-md-7', 'col-md-8', 'col-md-9', 'col-md-10', 'col-md-11', 'col-md-12', |
|
| 56 | - // 'col-lg-1', 'col-lg-2', 'col-lg-3', 'col-lg-4', 'col-lg-5', 'col-lg-6', |
|
| 57 | - // 'col-lg-7', 'col-lg-8', 'col-lg-9', 'col-lg-10', 'col-lg-11', 'col-lg-12', |
|
| 58 | - ); |
|
| 59 | - |
|
| 60 | - /** |
|
| 61 | - * The field states available |
|
| 62 | - * |
|
| 63 | - * @var array |
|
| 64 | - */ |
|
| 65 | - protected $states = array( |
|
| 66 | - 'has-warning', |
|
| 67 | - 'has-error', |
|
| 68 | - 'has-success', |
|
| 69 | - ); |
|
| 70 | - |
|
| 71 | - /** |
|
| 72 | - * The default HTML tag used for icons |
|
| 73 | - * |
|
| 74 | - * @var string |
|
| 75 | - */ |
|
| 76 | - protected $iconTag = 'span'; |
|
| 77 | - |
|
| 78 | - /** |
|
| 79 | - * The default set for icon fonts |
|
| 80 | - * By default Bootstrap 3 offers only 'glyphicon' |
|
| 81 | - * See Former docs to use 'social' and 'filetypes' sets for specific icons. |
|
| 82 | - * |
|
| 83 | - * @var string |
|
| 84 | - */ |
|
| 85 | - protected $iconSet = 'glyphicon'; |
|
| 86 | - |
|
| 87 | - /** |
|
| 88 | - * The default prefix icon names |
|
| 89 | - * "icon" works for Bootstrap 2 and Font-awesome |
|
| 90 | - * |
|
| 91 | - * @var string |
|
| 92 | - */ |
|
| 93 | - protected $iconPrefix = 'glyphicon'; |
|
| 94 | - |
|
| 95 | - /** |
|
| 96 | - * Create a new TwitterBootstrap instance |
|
| 97 | - * |
|
| 98 | - * @param \Illuminate\Container\Container $app |
|
| 99 | - */ |
|
| 100 | - public function __construct(Container $app) |
|
| 101 | - { |
|
| 102 | - $this->app = $app; |
|
| 103 | - $this->setFrameworkDefaults(); |
|
| 104 | - } |
|
| 105 | - |
|
| 106 | - //////////////////////////////////////////////////////////////////// |
|
| 107 | - /////////////////////////// FILTER ARRAYS ////////////////////////// |
|
| 108 | - //////////////////////////////////////////////////////////////////// |
|
| 109 | - |
|
| 110 | - /** |
|
| 111 | - * Filter buttons classes |
|
| 112 | - * |
|
| 113 | - * @param array $classes An array of classes |
|
| 114 | - * |
|
| 115 | - * @return string[] A filtered array |
|
| 116 | - */ |
|
| 117 | - public function filterButtonClasses($classes) |
|
| 118 | - { |
|
| 119 | - // Filter classes |
|
| 120 | - // $classes = array_intersect($classes, $this->buttons); |
|
| 121 | - |
|
| 122 | - // Prepend button type |
|
| 123 | - $classes = $this->prependWith($classes, 'btn-'); |
|
| 124 | - $classes[] = 'btn'; |
|
| 125 | - |
|
| 126 | - return $classes; |
|
| 127 | - } |
|
| 128 | - |
|
| 129 | - /** |
|
| 130 | - * Filter field classes |
|
| 131 | - * |
|
| 132 | - * @param array $classes An array of classes |
|
| 133 | - * |
|
| 134 | - * @return array A filtered array |
|
| 135 | - */ |
|
| 136 | - public function filterFieldClasses($classes) |
|
| 137 | - { |
|
| 138 | - // Filter classes |
|
| 139 | - $classes = array_intersect($classes, $this->fields); |
|
| 140 | - |
|
| 141 | - // Prepend field type |
|
| 142 | - $classes = array_map(function ($class) { |
|
| 143 | - return Str::startsWith($class, 'col') ? $class : 'input-'.$class; |
|
| 144 | - }, $classes); |
|
| 145 | - |
|
| 146 | - return $classes; |
|
| 147 | - } |
|
| 148 | - |
|
| 149 | - //////////////////////////////////////////////////////////////////// |
|
| 150 | - ///////////////////// EXPOSE FRAMEWORK SPECIFICS /////////////////// |
|
| 151 | - //////////////////////////////////////////////////////////////////// |
|
| 152 | - |
|
| 153 | - /** |
|
| 154 | - * Framework error state |
|
| 155 | - * |
|
| 156 | - * @return string |
|
| 157 | - */ |
|
| 158 | - public function errorState() |
|
| 159 | - { |
|
| 160 | - return 'has-error'; |
|
| 161 | - } |
|
| 162 | - |
|
| 163 | - /** |
|
| 164 | - * Returns corresponding inline class of a field |
|
| 165 | - * |
|
| 166 | - * @param Field $field |
|
| 167 | - * |
|
| 168 | - * @return string |
|
| 169 | - */ |
|
| 170 | - public function getInlineLabelClass($field) |
|
| 171 | - { |
|
| 172 | - $inlineClass = parent::getInlineLabelClass($field); |
|
| 173 | - if ($field->isOfType('checkbox', 'checkboxes')) { |
|
| 174 | - $inlineClass = 'checkbox-'.$inlineClass; |
|
| 175 | - } elseif ($field->isOfType('radio', 'radios')) { |
|
| 176 | - $inlineClass = 'radio-'.$inlineClass; |
|
| 177 | - } |
|
| 178 | - |
|
| 179 | - return $inlineClass; |
|
| 180 | - } |
|
| 181 | - |
|
| 182 | - /** |
|
| 183 | - * Set the fields width from a label width |
|
| 184 | - * |
|
| 185 | - * @param array $labelWidths |
|
| 186 | - */ |
|
| 187 | - protected function setFieldWidths($labelWidths) |
|
| 188 | - { |
|
| 189 | - $labelWidthClass = $fieldWidthClass = $fieldOffsetClass = ''; |
|
| 190 | - |
|
| 191 | - $viewports = $this->getFrameworkOption('viewports'); |
|
| 192 | - foreach ($labelWidths as $viewport => $columns) { |
|
| 193 | - if ($viewport) { |
|
| 194 | - $labelWidthClass .= " col-$viewports[$viewport]-$columns"; |
|
| 195 | - $fieldWidthClass .= " col-$viewports[$viewport]-".(12 - $columns); |
|
| 196 | - $fieldOffsetClass .= " col-$viewports[$viewport]-offset-$columns"; |
|
| 197 | - } |
|
| 198 | - } |
|
| 199 | - |
|
| 200 | - $this->labelWidth = ltrim($labelWidthClass); |
|
| 201 | - $this->fieldWidth = ltrim($fieldWidthClass); |
|
| 202 | - $this->fieldOffset = ltrim($fieldOffsetClass); |
|
| 203 | - } |
|
| 204 | - |
|
| 205 | - //////////////////////////////////////////////////////////////////// |
|
| 206 | - ///////////////////////////// ADD CLASSES ////////////////////////// |
|
| 207 | - //////////////////////////////////////////////////////////////////// |
|
| 208 | - |
|
| 209 | - /** |
|
| 210 | - * Add classes to a field |
|
| 211 | - * |
|
| 212 | - * @param Field $field |
|
| 213 | - * @param array $classes The possible classes to add |
|
| 214 | - * |
|
| 215 | - * @return Field |
|
| 216 | - */ |
|
| 217 | - public function getFieldClasses(Field $field, $classes) |
|
| 218 | - { |
|
| 219 | - // Add inline class for checkables |
|
| 220 | - if ($field->isCheckable() and in_array('inline', $classes)) { |
|
| 221 | - $field->inline(); |
|
| 222 | - } |
|
| 223 | - |
|
| 224 | - // Filter classes according to field type |
|
| 225 | - if ($field->isButton()) { |
|
| 226 | - $classes = $this->filterButtonClasses($classes); |
|
| 227 | - } else { |
|
| 228 | - $classes = $this->filterFieldClasses($classes); |
|
| 229 | - } |
|
| 230 | - |
|
| 231 | - // Add form-control class for text-type, textarea and select fields |
|
| 232 | - // As text-type is open-ended we instead exclude those that shouldn't receive the class |
|
| 233 | - if (!$field->isCheckable() and !$field->isButton() and !in_array($field->getType(), array( |
|
| 234 | - 'file', |
|
| 235 | - 'plaintext', |
|
| 236 | - )) and !in_array('form-control', $classes) |
|
| 237 | - ) { |
|
| 238 | - $classes[] = 'form-control'; |
|
| 239 | - } |
|
| 240 | - |
|
| 241 | - return $this->addClassesToField($field, $classes); |
|
| 242 | - } |
|
| 243 | - |
|
| 244 | - /** |
|
| 245 | - * Add group classes |
|
| 246 | - * |
|
| 247 | - * @return string A list of group classes |
|
| 248 | - */ |
|
| 249 | - public function getGroupClasses() |
|
| 250 | - { |
|
| 251 | - return 'form-group'; |
|
| 252 | - } |
|
| 253 | - |
|
| 254 | - /** |
|
| 255 | - * Add label classes |
|
| 256 | - * |
|
| 257 | - * @return string[] An array of attributes with the label class |
|
| 258 | - */ |
|
| 259 | - public function getLabelClasses() |
|
| 260 | - { |
|
| 261 | - if ($this->app['former.form']->isOfType('horizontal')) { |
|
| 262 | - return array('control-label', $this->labelWidth); |
|
| 263 | - } elseif ($this->app['former.form']->isOfType('inline')) { |
|
| 264 | - return array('sr-only'); |
|
| 265 | - } else { |
|
| 266 | - return array('control-label'); |
|
| 267 | - } |
|
| 268 | - } |
|
| 269 | - |
|
| 270 | - /** |
|
| 271 | - * Add uneditable field classes |
|
| 272 | - * |
|
| 273 | - * @return string An array of attributes with the uneditable class |
|
| 274 | - */ |
|
| 275 | - public function getUneditableClasses() |
|
| 276 | - { |
|
| 277 | - return ''; |
|
| 278 | - } |
|
| 279 | - |
|
| 280 | - /** |
|
| 281 | - * Add plain text field classes |
|
| 282 | - * |
|
| 283 | - * @return string An array of attributes with the plain text class |
|
| 284 | - */ |
|
| 285 | - public function getPlainTextClasses() |
|
| 286 | - { |
|
| 287 | - return 'form-control-static'; |
|
| 288 | - } |
|
| 289 | - |
|
| 290 | - /** |
|
| 291 | - * Add form class |
|
| 292 | - * |
|
| 293 | - * @param string $type The type of form to add |
|
| 294 | - * |
|
| 295 | - * @return string|null |
|
| 296 | - */ |
|
| 297 | - public function getFormClasses($type) |
|
| 298 | - { |
|
| 299 | - return $type ? 'form-'.$type : null; |
|
| 300 | - } |
|
| 301 | - |
|
| 302 | - /** |
|
| 303 | - * Add actions block class |
|
| 304 | - * |
|
| 305 | - * @return string|null |
|
| 306 | - */ |
|
| 307 | - public function getActionClasses() |
|
| 308 | - { |
|
| 309 | - if ($this->app['former.form']->isOfType('horizontal') || $this->app['former.form']->isOfType('inline')) { |
|
| 310 | - return 'form-group'; |
|
| 311 | - } |
|
| 312 | - |
|
| 313 | - return null; |
|
| 314 | - } |
|
| 315 | - |
|
| 316 | - //////////////////////////////////////////////////////////////////// |
|
| 317 | - //////////////////////////// RENDER BLOCKS ///////////////////////// |
|
| 318 | - //////////////////////////////////////////////////////////////////// |
|
| 319 | - |
|
| 320 | - /** |
|
| 321 | - * Render an help text |
|
| 322 | - * |
|
| 323 | - * @param string $text |
|
| 324 | - * @param array $attributes |
|
| 325 | - * |
|
| 326 | - * @return Element |
|
| 327 | - */ |
|
| 328 | - public function createHelp($text, $attributes = array()) |
|
| 329 | - { |
|
| 330 | - return Element::create('span', $text, $attributes)->addClass('help-block'); |
|
| 331 | - } |
|
| 332 | - |
|
| 333 | - /** |
|
| 334 | - * Render an help text |
|
| 335 | - * |
|
| 336 | - * @param string $text |
|
| 337 | - * @param array $attributes |
|
| 338 | - * |
|
| 339 | - * @return Element |
|
| 340 | - */ |
|
| 341 | - public function createBlockHelp($text, $attributes = array()) |
|
| 342 | - { |
|
| 343 | - return Element::create('p', $text, $attributes)->addClass('help-block'); |
|
| 344 | - } |
|
| 345 | - |
|
| 346 | - /** |
|
| 347 | - * Render a disabled field |
|
| 348 | - * |
|
| 349 | - * @param Field $field |
|
| 350 | - * |
|
| 351 | - * @return Element |
|
| 352 | - */ |
|
| 353 | - public function createDisabledField(Field $field) |
|
| 354 | - { |
|
| 355 | - return Element::create('span', $field->getValue(), $field->getAttributes()); |
|
| 356 | - } |
|
| 357 | - |
|
| 358 | - /** |
|
| 359 | - * Render a plain text field |
|
| 360 | - * |
|
| 361 | - * @param Field $field |
|
| 362 | - * |
|
| 363 | - * @return Element |
|
| 364 | - */ |
|
| 365 | - public function createPlainTextField(Field $field) |
|
| 366 | - { |
|
| 367 | - $label = $field->getLabel(); |
|
| 368 | - if ($label) { |
|
| 369 | - $label->for(''); |
|
| 370 | - } |
|
| 371 | - |
|
| 372 | - return Element::create('div', $field->getValue(), $field->getAttributes()); |
|
| 373 | - } |
|
| 374 | - |
|
| 375 | - //////////////////////////////////////////////////////////////////// |
|
| 376 | - //////////////////////////// WRAP BLOCKS /////////////////////////// |
|
| 377 | - //////////////////////////////////////////////////////////////////// |
|
| 378 | - |
|
| 379 | - /** |
|
| 380 | - * Wrap an item to be prepended or appended to the current field |
|
| 381 | - * |
|
| 382 | - * @return Element A wrapped item |
|
| 383 | - */ |
|
| 384 | - public function placeAround($item) |
|
| 385 | - { |
|
| 386 | - // Render object |
|
| 387 | - if (is_object($item) and method_exists($item, '__toString')) { |
|
| 388 | - $item = $item->__toString(); |
|
| 389 | - } |
|
| 390 | - |
|
| 391 | - // Get class to use |
|
| 392 | - $class = (strpos($item, '<button') !== false) ? 'btn' : 'addon'; |
|
| 393 | - |
|
| 394 | - return Element::create('span', $item)->addClass('input-group-'.$class); |
|
| 395 | - } |
|
| 396 | - |
|
| 397 | - /** |
|
| 398 | - * Wrap a field with prepended and appended items |
|
| 399 | - * |
|
| 400 | - * @param Field $field |
|
| 401 | - * @param array $prepend |
|
| 402 | - * @param array $append |
|
| 403 | - * |
|
| 404 | - * @return string A field concatented with prepended and/or appended items |
|
| 405 | - */ |
|
| 406 | - public function prependAppend($field, $prepend, $append) |
|
| 407 | - { |
|
| 408 | - $return = '<div class="input-group">'; |
|
| 409 | - $return .= join(null, $prepend); |
|
| 410 | - $return .= $field->render(); |
|
| 411 | - $return .= join(null, $append); |
|
| 412 | - $return .= '</div>'; |
|
| 413 | - |
|
| 414 | - return $return; |
|
| 415 | - } |
|
| 416 | - |
|
| 417 | - /** |
|
| 418 | - * Wrap a field with potential additional tags |
|
| 419 | - * |
|
| 420 | - * @param Field $field |
|
| 421 | - * |
|
| 422 | - * @return Element A wrapped field |
|
| 423 | - */ |
|
| 424 | - public function wrapField($field) |
|
| 425 | - { |
|
| 426 | - if ($this->app['former.form']->isOfType('horizontal')) { |
|
| 427 | - return Element::create('div', $field)->addClass($this->fieldWidth); |
|
| 428 | - } |
|
| 429 | - |
|
| 430 | - return $field; |
|
| 431 | - } |
|
| 432 | - |
|
| 433 | - /** |
|
| 434 | - * Wrap actions block with potential additional tags |
|
| 435 | - * |
|
| 436 | - * @param Actions $actions |
|
| 437 | - * |
|
| 438 | - * @return string A wrapped actions block |
|
| 439 | - */ |
|
| 440 | - public function wrapActions($actions) |
|
| 441 | - { |
|
| 442 | - // For horizontal forms, we wrap the actions in a div |
|
| 443 | - if ($this->app['former.form']->isOfType('horizontal')) { |
|
| 444 | - return Element::create('div', $actions)->addClass(array($this->fieldOffset, $this->fieldWidth)); |
|
| 445 | - } |
|
| 446 | - |
|
| 447 | - return $actions; |
|
| 448 | - } |
|
| 16 | + /** |
|
| 17 | + * Form types that trigger special styling for this Framework |
|
| 18 | + * |
|
| 19 | + * @var array |
|
| 20 | + */ |
|
| 21 | + protected $availableTypes = array('horizontal', 'vertical', 'inline'); |
|
| 22 | + |
|
| 23 | + /** |
|
| 24 | + * The button types available |
|
| 25 | + * |
|
| 26 | + * @var array |
|
| 27 | + */ |
|
| 28 | + private $buttons = array( |
|
| 29 | + 'lg', |
|
| 30 | + 'sm', |
|
| 31 | + 'xs', |
|
| 32 | + 'block', |
|
| 33 | + 'link', |
|
| 34 | + 'default', |
|
| 35 | + 'primary', |
|
| 36 | + 'warning', |
|
| 37 | + 'danger', |
|
| 38 | + 'success', |
|
| 39 | + 'info', |
|
| 40 | + ); |
|
| 41 | + |
|
| 42 | + /** |
|
| 43 | + * The field sizes available |
|
| 44 | + * |
|
| 45 | + * @var array |
|
| 46 | + */ |
|
| 47 | + private $fields = array( |
|
| 48 | + 'lg', |
|
| 49 | + 'sm', |
|
| 50 | + // 'col-xs-1', 'col-xs-2', 'col-xs-3', 'col-xs-4', 'col-xs-5', 'col-xs-6', |
|
| 51 | + // 'col-xs-7', 'col-xs-8', 'col-xs-9', 'col-xs-10', 'col-xs-11', 'col-xs-12', |
|
| 52 | + // 'col-sm-1', 'col-sm-2', 'col-sm-3', 'col-sm-4', 'col-sm-5', 'col-sm-6', |
|
| 53 | + // 'col-sm-7', 'col-sm-8', 'col-sm-9', 'col-sm-10', 'col-sm-11', 'col-sm-12', |
|
| 54 | + // 'col-md-1', 'col-md-2', 'col-md-3', 'col-md-4', 'col-md-5', 'col-md-6', |
|
| 55 | + // 'col-md-7', 'col-md-8', 'col-md-9', 'col-md-10', 'col-md-11', 'col-md-12', |
|
| 56 | + // 'col-lg-1', 'col-lg-2', 'col-lg-3', 'col-lg-4', 'col-lg-5', 'col-lg-6', |
|
| 57 | + // 'col-lg-7', 'col-lg-8', 'col-lg-9', 'col-lg-10', 'col-lg-11', 'col-lg-12', |
|
| 58 | + ); |
|
| 59 | + |
|
| 60 | + /** |
|
| 61 | + * The field states available |
|
| 62 | + * |
|
| 63 | + * @var array |
|
| 64 | + */ |
|
| 65 | + protected $states = array( |
|
| 66 | + 'has-warning', |
|
| 67 | + 'has-error', |
|
| 68 | + 'has-success', |
|
| 69 | + ); |
|
| 70 | + |
|
| 71 | + /** |
|
| 72 | + * The default HTML tag used for icons |
|
| 73 | + * |
|
| 74 | + * @var string |
|
| 75 | + */ |
|
| 76 | + protected $iconTag = 'span'; |
|
| 77 | + |
|
| 78 | + /** |
|
| 79 | + * The default set for icon fonts |
|
| 80 | + * By default Bootstrap 3 offers only 'glyphicon' |
|
| 81 | + * See Former docs to use 'social' and 'filetypes' sets for specific icons. |
|
| 82 | + * |
|
| 83 | + * @var string |
|
| 84 | + */ |
|
| 85 | + protected $iconSet = 'glyphicon'; |
|
| 86 | + |
|
| 87 | + /** |
|
| 88 | + * The default prefix icon names |
|
| 89 | + * "icon" works for Bootstrap 2 and Font-awesome |
|
| 90 | + * |
|
| 91 | + * @var string |
|
| 92 | + */ |
|
| 93 | + protected $iconPrefix = 'glyphicon'; |
|
| 94 | + |
|
| 95 | + /** |
|
| 96 | + * Create a new TwitterBootstrap instance |
|
| 97 | + * |
|
| 98 | + * @param \Illuminate\Container\Container $app |
|
| 99 | + */ |
|
| 100 | + public function __construct(Container $app) |
|
| 101 | + { |
|
| 102 | + $this->app = $app; |
|
| 103 | + $this->setFrameworkDefaults(); |
|
| 104 | + } |
|
| 105 | + |
|
| 106 | + //////////////////////////////////////////////////////////////////// |
|
| 107 | + /////////////////////////// FILTER ARRAYS ////////////////////////// |
|
| 108 | + //////////////////////////////////////////////////////////////////// |
|
| 109 | + |
|
| 110 | + /** |
|
| 111 | + * Filter buttons classes |
|
| 112 | + * |
|
| 113 | + * @param array $classes An array of classes |
|
| 114 | + * |
|
| 115 | + * @return string[] A filtered array |
|
| 116 | + */ |
|
| 117 | + public function filterButtonClasses($classes) |
|
| 118 | + { |
|
| 119 | + // Filter classes |
|
| 120 | + // $classes = array_intersect($classes, $this->buttons); |
|
| 121 | + |
|
| 122 | + // Prepend button type |
|
| 123 | + $classes = $this->prependWith($classes, 'btn-'); |
|
| 124 | + $classes[] = 'btn'; |
|
| 125 | + |
|
| 126 | + return $classes; |
|
| 127 | + } |
|
| 128 | + |
|
| 129 | + /** |
|
| 130 | + * Filter field classes |
|
| 131 | + * |
|
| 132 | + * @param array $classes An array of classes |
|
| 133 | + * |
|
| 134 | + * @return array A filtered array |
|
| 135 | + */ |
|
| 136 | + public function filterFieldClasses($classes) |
|
| 137 | + { |
|
| 138 | + // Filter classes |
|
| 139 | + $classes = array_intersect($classes, $this->fields); |
|
| 140 | + |
|
| 141 | + // Prepend field type |
|
| 142 | + $classes = array_map(function ($class) { |
|
| 143 | + return Str::startsWith($class, 'col') ? $class : 'input-'.$class; |
|
| 144 | + }, $classes); |
|
| 145 | + |
|
| 146 | + return $classes; |
|
| 147 | + } |
|
| 148 | + |
|
| 149 | + //////////////////////////////////////////////////////////////////// |
|
| 150 | + ///////////////////// EXPOSE FRAMEWORK SPECIFICS /////////////////// |
|
| 151 | + //////////////////////////////////////////////////////////////////// |
|
| 152 | + |
|
| 153 | + /** |
|
| 154 | + * Framework error state |
|
| 155 | + * |
|
| 156 | + * @return string |
|
| 157 | + */ |
|
| 158 | + public function errorState() |
|
| 159 | + { |
|
| 160 | + return 'has-error'; |
|
| 161 | + } |
|
| 162 | + |
|
| 163 | + /** |
|
| 164 | + * Returns corresponding inline class of a field |
|
| 165 | + * |
|
| 166 | + * @param Field $field |
|
| 167 | + * |
|
| 168 | + * @return string |
|
| 169 | + */ |
|
| 170 | + public function getInlineLabelClass($field) |
|
| 171 | + { |
|
| 172 | + $inlineClass = parent::getInlineLabelClass($field); |
|
| 173 | + if ($field->isOfType('checkbox', 'checkboxes')) { |
|
| 174 | + $inlineClass = 'checkbox-'.$inlineClass; |
|
| 175 | + } elseif ($field->isOfType('radio', 'radios')) { |
|
| 176 | + $inlineClass = 'radio-'.$inlineClass; |
|
| 177 | + } |
|
| 178 | + |
|
| 179 | + return $inlineClass; |
|
| 180 | + } |
|
| 181 | + |
|
| 182 | + /** |
|
| 183 | + * Set the fields width from a label width |
|
| 184 | + * |
|
| 185 | + * @param array $labelWidths |
|
| 186 | + */ |
|
| 187 | + protected function setFieldWidths($labelWidths) |
|
| 188 | + { |
|
| 189 | + $labelWidthClass = $fieldWidthClass = $fieldOffsetClass = ''; |
|
| 190 | + |
|
| 191 | + $viewports = $this->getFrameworkOption('viewports'); |
|
| 192 | + foreach ($labelWidths as $viewport => $columns) { |
|
| 193 | + if ($viewport) { |
|
| 194 | + $labelWidthClass .= " col-$viewports[$viewport]-$columns"; |
|
| 195 | + $fieldWidthClass .= " col-$viewports[$viewport]-".(12 - $columns); |
|
| 196 | + $fieldOffsetClass .= " col-$viewports[$viewport]-offset-$columns"; |
|
| 197 | + } |
|
| 198 | + } |
|
| 199 | + |
|
| 200 | + $this->labelWidth = ltrim($labelWidthClass); |
|
| 201 | + $this->fieldWidth = ltrim($fieldWidthClass); |
|
| 202 | + $this->fieldOffset = ltrim($fieldOffsetClass); |
|
| 203 | + } |
|
| 204 | + |
|
| 205 | + //////////////////////////////////////////////////////////////////// |
|
| 206 | + ///////////////////////////// ADD CLASSES ////////////////////////// |
|
| 207 | + //////////////////////////////////////////////////////////////////// |
|
| 208 | + |
|
| 209 | + /** |
|
| 210 | + * Add classes to a field |
|
| 211 | + * |
|
| 212 | + * @param Field $field |
|
| 213 | + * @param array $classes The possible classes to add |
|
| 214 | + * |
|
| 215 | + * @return Field |
|
| 216 | + */ |
|
| 217 | + public function getFieldClasses(Field $field, $classes) |
|
| 218 | + { |
|
| 219 | + // Add inline class for checkables |
|
| 220 | + if ($field->isCheckable() and in_array('inline', $classes)) { |
|
| 221 | + $field->inline(); |
|
| 222 | + } |
|
| 223 | + |
|
| 224 | + // Filter classes according to field type |
|
| 225 | + if ($field->isButton()) { |
|
| 226 | + $classes = $this->filterButtonClasses($classes); |
|
| 227 | + } else { |
|
| 228 | + $classes = $this->filterFieldClasses($classes); |
|
| 229 | + } |
|
| 230 | + |
|
| 231 | + // Add form-control class for text-type, textarea and select fields |
|
| 232 | + // As text-type is open-ended we instead exclude those that shouldn't receive the class |
|
| 233 | + if (!$field->isCheckable() and !$field->isButton() and !in_array($field->getType(), array( |
|
| 234 | + 'file', |
|
| 235 | + 'plaintext', |
|
| 236 | + )) and !in_array('form-control', $classes) |
|
| 237 | + ) { |
|
| 238 | + $classes[] = 'form-control'; |
|
| 239 | + } |
|
| 240 | + |
|
| 241 | + return $this->addClassesToField($field, $classes); |
|
| 242 | + } |
|
| 243 | + |
|
| 244 | + /** |
|
| 245 | + * Add group classes |
|
| 246 | + * |
|
| 247 | + * @return string A list of group classes |
|
| 248 | + */ |
|
| 249 | + public function getGroupClasses() |
|
| 250 | + { |
|
| 251 | + return 'form-group'; |
|
| 252 | + } |
|
| 253 | + |
|
| 254 | + /** |
|
| 255 | + * Add label classes |
|
| 256 | + * |
|
| 257 | + * @return string[] An array of attributes with the label class |
|
| 258 | + */ |
|
| 259 | + public function getLabelClasses() |
|
| 260 | + { |
|
| 261 | + if ($this->app['former.form']->isOfType('horizontal')) { |
|
| 262 | + return array('control-label', $this->labelWidth); |
|
| 263 | + } elseif ($this->app['former.form']->isOfType('inline')) { |
|
| 264 | + return array('sr-only'); |
|
| 265 | + } else { |
|
| 266 | + return array('control-label'); |
|
| 267 | + } |
|
| 268 | + } |
|
| 269 | + |
|
| 270 | + /** |
|
| 271 | + * Add uneditable field classes |
|
| 272 | + * |
|
| 273 | + * @return string An array of attributes with the uneditable class |
|
| 274 | + */ |
|
| 275 | + public function getUneditableClasses() |
|
| 276 | + { |
|
| 277 | + return ''; |
|
| 278 | + } |
|
| 279 | + |
|
| 280 | + /** |
|
| 281 | + * Add plain text field classes |
|
| 282 | + * |
|
| 283 | + * @return string An array of attributes with the plain text class |
|
| 284 | + */ |
|
| 285 | + public function getPlainTextClasses() |
|
| 286 | + { |
|
| 287 | + return 'form-control-static'; |
|
| 288 | + } |
|
| 289 | + |
|
| 290 | + /** |
|
| 291 | + * Add form class |
|
| 292 | + * |
|
| 293 | + * @param string $type The type of form to add |
|
| 294 | + * |
|
| 295 | + * @return string|null |
|
| 296 | + */ |
|
| 297 | + public function getFormClasses($type) |
|
| 298 | + { |
|
| 299 | + return $type ? 'form-'.$type : null; |
|
| 300 | + } |
|
| 301 | + |
|
| 302 | + /** |
|
| 303 | + * Add actions block class |
|
| 304 | + * |
|
| 305 | + * @return string|null |
|
| 306 | + */ |
|
| 307 | + public function getActionClasses() |
|
| 308 | + { |
|
| 309 | + if ($this->app['former.form']->isOfType('horizontal') || $this->app['former.form']->isOfType('inline')) { |
|
| 310 | + return 'form-group'; |
|
| 311 | + } |
|
| 312 | + |
|
| 313 | + return null; |
|
| 314 | + } |
|
| 315 | + |
|
| 316 | + //////////////////////////////////////////////////////////////////// |
|
| 317 | + //////////////////////////// RENDER BLOCKS ///////////////////////// |
|
| 318 | + //////////////////////////////////////////////////////////////////// |
|
| 319 | + |
|
| 320 | + /** |
|
| 321 | + * Render an help text |
|
| 322 | + * |
|
| 323 | + * @param string $text |
|
| 324 | + * @param array $attributes |
|
| 325 | + * |
|
| 326 | + * @return Element |
|
| 327 | + */ |
|
| 328 | + public function createHelp($text, $attributes = array()) |
|
| 329 | + { |
|
| 330 | + return Element::create('span', $text, $attributes)->addClass('help-block'); |
|
| 331 | + } |
|
| 332 | + |
|
| 333 | + /** |
|
| 334 | + * Render an help text |
|
| 335 | + * |
|
| 336 | + * @param string $text |
|
| 337 | + * @param array $attributes |
|
| 338 | + * |
|
| 339 | + * @return Element |
|
| 340 | + */ |
|
| 341 | + public function createBlockHelp($text, $attributes = array()) |
|
| 342 | + { |
|
| 343 | + return Element::create('p', $text, $attributes)->addClass('help-block'); |
|
| 344 | + } |
|
| 345 | + |
|
| 346 | + /** |
|
| 347 | + * Render a disabled field |
|
| 348 | + * |
|
| 349 | + * @param Field $field |
|
| 350 | + * |
|
| 351 | + * @return Element |
|
| 352 | + */ |
|
| 353 | + public function createDisabledField(Field $field) |
|
| 354 | + { |
|
| 355 | + return Element::create('span', $field->getValue(), $field->getAttributes()); |
|
| 356 | + } |
|
| 357 | + |
|
| 358 | + /** |
|
| 359 | + * Render a plain text field |
|
| 360 | + * |
|
| 361 | + * @param Field $field |
|
| 362 | + * |
|
| 363 | + * @return Element |
|
| 364 | + */ |
|
| 365 | + public function createPlainTextField(Field $field) |
|
| 366 | + { |
|
| 367 | + $label = $field->getLabel(); |
|
| 368 | + if ($label) { |
|
| 369 | + $label->for(''); |
|
| 370 | + } |
|
| 371 | + |
|
| 372 | + return Element::create('div', $field->getValue(), $field->getAttributes()); |
|
| 373 | + } |
|
| 374 | + |
|
| 375 | + //////////////////////////////////////////////////////////////////// |
|
| 376 | + //////////////////////////// WRAP BLOCKS /////////////////////////// |
|
| 377 | + //////////////////////////////////////////////////////////////////// |
|
| 378 | + |
|
| 379 | + /** |
|
| 380 | + * Wrap an item to be prepended or appended to the current field |
|
| 381 | + * |
|
| 382 | + * @return Element A wrapped item |
|
| 383 | + */ |
|
| 384 | + public function placeAround($item) |
|
| 385 | + { |
|
| 386 | + // Render object |
|
| 387 | + if (is_object($item) and method_exists($item, '__toString')) { |
|
| 388 | + $item = $item->__toString(); |
|
| 389 | + } |
|
| 390 | + |
|
| 391 | + // Get class to use |
|
| 392 | + $class = (strpos($item, '<button') !== false) ? 'btn' : 'addon'; |
|
| 393 | + |
|
| 394 | + return Element::create('span', $item)->addClass('input-group-'.$class); |
|
| 395 | + } |
|
| 396 | + |
|
| 397 | + /** |
|
| 398 | + * Wrap a field with prepended and appended items |
|
| 399 | + * |
|
| 400 | + * @param Field $field |
|
| 401 | + * @param array $prepend |
|
| 402 | + * @param array $append |
|
| 403 | + * |
|
| 404 | + * @return string A field concatented with prepended and/or appended items |
|
| 405 | + */ |
|
| 406 | + public function prependAppend($field, $prepend, $append) |
|
| 407 | + { |
|
| 408 | + $return = '<div class="input-group">'; |
|
| 409 | + $return .= join(null, $prepend); |
|
| 410 | + $return .= $field->render(); |
|
| 411 | + $return .= join(null, $append); |
|
| 412 | + $return .= '</div>'; |
|
| 413 | + |
|
| 414 | + return $return; |
|
| 415 | + } |
|
| 416 | + |
|
| 417 | + /** |
|
| 418 | + * Wrap a field with potential additional tags |
|
| 419 | + * |
|
| 420 | + * @param Field $field |
|
| 421 | + * |
|
| 422 | + * @return Element A wrapped field |
|
| 423 | + */ |
|
| 424 | + public function wrapField($field) |
|
| 425 | + { |
|
| 426 | + if ($this->app['former.form']->isOfType('horizontal')) { |
|
| 427 | + return Element::create('div', $field)->addClass($this->fieldWidth); |
|
| 428 | + } |
|
| 429 | + |
|
| 430 | + return $field; |
|
| 431 | + } |
|
| 432 | + |
|
| 433 | + /** |
|
| 434 | + * Wrap actions block with potential additional tags |
|
| 435 | + * |
|
| 436 | + * @param Actions $actions |
|
| 437 | + * |
|
| 438 | + * @return string A wrapped actions block |
|
| 439 | + */ |
|
| 440 | + public function wrapActions($actions) |
|
| 441 | + { |
|
| 442 | + // For horizontal forms, we wrap the actions in a div |
|
| 443 | + if ($this->app['former.form']->isOfType('horizontal')) { |
|
| 444 | + return Element::create('div', $actions)->addClass(array($this->fieldOffset, $this->fieldWidth)); |
|
| 445 | + } |
|
| 446 | + |
|
| 447 | + return $actions; |
|
| 448 | + } |
|
| 449 | 449 | } |
@@ -124,7 +124,7 @@ |
||
| 124 | 124 | $classes = array_intersect($classes, $this->fields); |
| 125 | 125 | |
| 126 | 126 | // Prepend field type |
| 127 | - $classes = array_map(function ($class) { |
|
| 127 | + $classes = array_map(function($class) { |
|
| 128 | 128 | return Str::startsWith($class, 'span') ? $class : 'input-'.$class; |
| 129 | 129 | }, $classes); |
| 130 | 130 | |
@@ -13,374 +13,374 @@ |
||
| 13 | 13 | */ |
| 14 | 14 | class TwitterBootstrap extends Framework implements FrameworkInterface |
| 15 | 15 | { |
| 16 | - /** |
|
| 17 | - * Form types that trigger special styling for this Framework |
|
| 18 | - * |
|
| 19 | - * @var array |
|
| 20 | - */ |
|
| 21 | - protected $availableTypes = array('horizontal', 'vertical', 'inline', 'search'); |
|
| 22 | - |
|
| 23 | - /** |
|
| 24 | - * The button types available |
|
| 25 | - * |
|
| 26 | - * @var array |
|
| 27 | - */ |
|
| 28 | - private $buttons = array( |
|
| 29 | - 'large', |
|
| 30 | - 'small', |
|
| 31 | - 'mini', |
|
| 32 | - 'block', |
|
| 33 | - 'danger', |
|
| 34 | - 'info', |
|
| 35 | - 'inverse', |
|
| 36 | - 'link', |
|
| 37 | - 'primary', |
|
| 38 | - 'success', |
|
| 39 | - 'warning', |
|
| 40 | - ); |
|
| 41 | - |
|
| 42 | - /** |
|
| 43 | - * The field sizes available |
|
| 44 | - * |
|
| 45 | - * @var array |
|
| 46 | - */ |
|
| 47 | - private $fields = array( |
|
| 48 | - 'mini', |
|
| 49 | - 'small', |
|
| 50 | - 'medium', |
|
| 51 | - 'large', |
|
| 52 | - 'xlarge', |
|
| 53 | - 'xxlarge', |
|
| 54 | - 'span1', |
|
| 55 | - 'span2', |
|
| 56 | - 'span3', |
|
| 57 | - 'span4', |
|
| 58 | - 'span5', |
|
| 59 | - 'span6', |
|
| 60 | - 'span7', |
|
| 61 | - 'span8', |
|
| 62 | - 'span9', |
|
| 63 | - 'span10', |
|
| 64 | - 'span11', |
|
| 65 | - 'span12', |
|
| 66 | - ); |
|
| 67 | - |
|
| 68 | - /** |
|
| 69 | - * The field states available |
|
| 70 | - * |
|
| 71 | - * @var array |
|
| 72 | - */ |
|
| 73 | - protected $states = array( |
|
| 74 | - 'success', |
|
| 75 | - 'warning', |
|
| 76 | - 'error', |
|
| 77 | - 'info', |
|
| 78 | - ); |
|
| 79 | - |
|
| 80 | - /** |
|
| 81 | - * Create a new TwitterBootstrap instance |
|
| 82 | - * |
|
| 83 | - * @param \Illuminate\Container\Container $app |
|
| 84 | - */ |
|
| 85 | - public function __construct(Container $app) |
|
| 86 | - { |
|
| 87 | - $this->app = $app; |
|
| 88 | - $this->setFrameworkDefaults(); |
|
| 89 | - } |
|
| 90 | - |
|
| 91 | - //////////////////////////////////////////////////////////////////// |
|
| 92 | - /////////////////////////// FILTER ARRAYS ////////////////////////// |
|
| 93 | - //////////////////////////////////////////////////////////////////// |
|
| 94 | - |
|
| 95 | - /** |
|
| 96 | - * Filter buttons classes |
|
| 97 | - * |
|
| 98 | - * @param array $classes An array of classes |
|
| 99 | - * |
|
| 100 | - * @return string[] A filtered array |
|
| 101 | - */ |
|
| 102 | - public function filterButtonClasses($classes) |
|
| 103 | - { |
|
| 104 | - // Filter classes |
|
| 105 | - // $classes = array_intersect($classes, $this->buttons); |
|
| 106 | - |
|
| 107 | - // Prepend button type |
|
| 108 | - $classes = $this->prependWith($classes, 'btn-'); |
|
| 109 | - $classes[] = 'btn'; |
|
| 110 | - |
|
| 111 | - return $classes; |
|
| 112 | - } |
|
| 113 | - |
|
| 114 | - /** |
|
| 115 | - * Filter field classes |
|
| 116 | - * |
|
| 117 | - * @param array $classes An array of classes |
|
| 118 | - * |
|
| 119 | - * @return array A filtered array |
|
| 120 | - */ |
|
| 121 | - public function filterFieldClasses($classes) |
|
| 122 | - { |
|
| 123 | - // Filter classes |
|
| 124 | - $classes = array_intersect($classes, $this->fields); |
|
| 125 | - |
|
| 126 | - // Prepend field type |
|
| 127 | - $classes = array_map(function ($class) { |
|
| 128 | - return Str::startsWith($class, 'span') ? $class : 'input-'.$class; |
|
| 129 | - }, $classes); |
|
| 130 | - |
|
| 131 | - return $classes; |
|
| 132 | - } |
|
| 133 | - |
|
| 134 | - //////////////////////////////////////////////////////////////////// |
|
| 135 | - ///////////////////////////// ADD CLASSES ////////////////////////// |
|
| 136 | - //////////////////////////////////////////////////////////////////// |
|
| 137 | - |
|
| 138 | - /** |
|
| 139 | - * Add classes to a field |
|
| 140 | - * |
|
| 141 | - * @param Field $field |
|
| 142 | - * @param array $classes The possible classes to add |
|
| 143 | - * |
|
| 144 | - * @return Field |
|
| 145 | - */ |
|
| 146 | - public function getFieldClasses(Field $field, $classes) |
|
| 147 | - { |
|
| 148 | - // Add inline class for checkables |
|
| 149 | - if ($field->isCheckable() and in_array('inline', $classes)) { |
|
| 150 | - $field->inline(); |
|
| 151 | - } |
|
| 152 | - |
|
| 153 | - // Filter classes according to field type |
|
| 154 | - if ($field->isButton()) { |
|
| 155 | - $classes = $this->filterButtonClasses($classes); |
|
| 156 | - } else { |
|
| 157 | - $classes = $this->filterFieldClasses($classes); |
|
| 158 | - } |
|
| 159 | - |
|
| 160 | - return $this->addClassesToField($field, $classes); |
|
| 161 | - } |
|
| 162 | - |
|
| 163 | - /** |
|
| 164 | - * Add group classes |
|
| 165 | - * |
|
| 166 | - * @return string A list of group classes |
|
| 167 | - */ |
|
| 168 | - public function getGroupClasses() |
|
| 169 | - { |
|
| 170 | - return 'control-group'; |
|
| 171 | - } |
|
| 172 | - |
|
| 173 | - /** |
|
| 174 | - * Add label classes |
|
| 175 | - * |
|
| 176 | - * @return string An array of attributes with the label class |
|
| 177 | - */ |
|
| 178 | - public function getLabelClasses() |
|
| 179 | - { |
|
| 180 | - return 'control-label'; |
|
| 181 | - } |
|
| 182 | - |
|
| 183 | - /** |
|
| 184 | - * Add uneditable field classes |
|
| 185 | - * |
|
| 186 | - * @return string An array of attributes with the uneditable class |
|
| 187 | - */ |
|
| 188 | - public function getUneditableClasses() |
|
| 189 | - { |
|
| 190 | - return 'uneditable-input'; |
|
| 191 | - } |
|
| 192 | - |
|
| 193 | - public function getPlainTextClasses() |
|
| 194 | - { |
|
| 195 | - return null; |
|
| 196 | - } |
|
| 197 | - |
|
| 198 | - /** |
|
| 199 | - * Add form class |
|
| 200 | - * |
|
| 201 | - * @param string $type The type of form to add |
|
| 202 | - * |
|
| 203 | - * @return string|null |
|
| 204 | - */ |
|
| 205 | - public function getFormClasses($type) |
|
| 206 | - { |
|
| 207 | - return $type ? 'form-'.$type : null; |
|
| 208 | - } |
|
| 209 | - |
|
| 210 | - /** |
|
| 211 | - * Add actions block class |
|
| 212 | - * |
|
| 213 | - * @return string |
|
| 214 | - */ |
|
| 215 | - public function getActionClasses() |
|
| 216 | - { |
|
| 217 | - return 'form-actions'; |
|
| 218 | - } |
|
| 219 | - |
|
| 220 | - //////////////////////////////////////////////////////////////////// |
|
| 221 | - //////////////////////////// RENDER BLOCKS ///////////////////////// |
|
| 222 | - //////////////////////////////////////////////////////////////////// |
|
| 223 | - |
|
| 224 | - /** |
|
| 225 | - * Render an help text |
|
| 226 | - * |
|
| 227 | - * @param string $text |
|
| 228 | - * @param array $attributes |
|
| 229 | - * |
|
| 230 | - * @return Element |
|
| 231 | - */ |
|
| 232 | - public function createHelp($text, $attributes = array()) |
|
| 233 | - { |
|
| 234 | - return Element::create('span', $text, $attributes)->addClass('help-inline'); |
|
| 235 | - } |
|
| 236 | - |
|
| 237 | - /** |
|
| 238 | - * Render a block help text |
|
| 239 | - * |
|
| 240 | - * @param string $text |
|
| 241 | - * @param array $attributes |
|
| 242 | - * |
|
| 243 | - * @return Element |
|
| 244 | - */ |
|
| 245 | - public function createBlockHelp($text, $attributes = array()) |
|
| 246 | - { |
|
| 247 | - return Element::create('p', $text, $attributes)->addClass('help-block'); |
|
| 248 | - } |
|
| 249 | - |
|
| 250 | - /** |
|
| 251 | - * Render a disabled field |
|
| 252 | - * |
|
| 253 | - * @param Field $field |
|
| 254 | - * |
|
| 255 | - * @return Element |
|
| 256 | - */ |
|
| 257 | - public function createDisabledField(Field $field) |
|
| 258 | - { |
|
| 259 | - return Element::create('span', $field->getValue(), $field->getAttributes()); |
|
| 260 | - } |
|
| 261 | - |
|
| 262 | - /** |
|
| 263 | - * Render a plain text field |
|
| 264 | - * Which fallback to a disabled field |
|
| 265 | - * |
|
| 266 | - * @param Field $field |
|
| 267 | - * |
|
| 268 | - * @return Element |
|
| 269 | - */ |
|
| 270 | - public function createPlainTextField(Field $field) |
|
| 271 | - { |
|
| 272 | - return $this->createDisabledField($field); |
|
| 273 | - } |
|
| 274 | - |
|
| 275 | - /** |
|
| 276 | - * Render an icon |
|
| 277 | - * |
|
| 278 | - * @param array $attributes Its general attributes |
|
| 279 | - * |
|
| 280 | - * @return string |
|
| 281 | - */ |
|
| 282 | - public function createIcon($iconType, $attributes = array(), $iconSettings = array()) |
|
| 283 | - { |
|
| 284 | - // Check for empty icons |
|
| 285 | - if (!$iconType) { |
|
| 286 | - return false; |
|
| 287 | - } |
|
| 288 | - |
|
| 289 | - // Create tag |
|
| 290 | - $tag = array_get($iconSettings, 'tag', $this->iconTag); |
|
| 291 | - $icon = Element::create($tag, null, $attributes); |
|
| 292 | - |
|
| 293 | - // White icons ignore user overrides to use legacy Bootstrap styling |
|
| 294 | - if (Str::contains($iconType, 'white')) { |
|
| 295 | - $iconType = str_replace('white', '', $iconType); |
|
| 296 | - $iconType = trim($iconType, '-'); |
|
| 297 | - $icon->addClass('icon-white'); |
|
| 298 | - $set = null; |
|
| 299 | - $prefix = 'icon'; |
|
| 300 | - } else { |
|
| 301 | - $set = array_get($iconSettings, 'set', $this->iconSet); |
|
| 302 | - $prefix = array_get($iconSettings, 'prefix', $this->iconPrefix); |
|
| 303 | - } |
|
| 304 | - $icon->addClass("$set $prefix-$iconType"); |
|
| 305 | - |
|
| 306 | - return $icon; |
|
| 307 | - } |
|
| 308 | - |
|
| 309 | - //////////////////////////////////////////////////////////////////// |
|
| 310 | - //////////////////////////// WRAP BLOCKS /////////////////////////// |
|
| 311 | - //////////////////////////////////////////////////////////////////// |
|
| 312 | - |
|
| 313 | - /** |
|
| 314 | - * Wrap an item to be prepended or appended to the current field |
|
| 315 | - * |
|
| 316 | - * @param string $item |
|
| 317 | - * |
|
| 318 | - * @return string A wrapped item |
|
| 319 | - */ |
|
| 320 | - public function placeAround($item) |
|
| 321 | - { |
|
| 322 | - // Render object |
|
| 323 | - if (is_object($item) and method_exists($item, '__toString')) { |
|
| 324 | - $item = $item->__toString(); |
|
| 325 | - } |
|
| 326 | - |
|
| 327 | - // Return unwrapped if button |
|
| 328 | - if (strpos($item, '<button') !== false) { |
|
| 329 | - return $item; |
|
| 330 | - } |
|
| 331 | - |
|
| 332 | - return Element::create('span', $item)->addClass('add-on'); |
|
| 333 | - } |
|
| 334 | - |
|
| 335 | - /** |
|
| 336 | - * Wrap a field with prepended and appended items |
|
| 337 | - * |
|
| 338 | - * @param Field $field |
|
| 339 | - * @param array $prepend |
|
| 340 | - * @param array $append |
|
| 341 | - * |
|
| 342 | - * @return string A field concatented with prepended and/or appended items |
|
| 343 | - */ |
|
| 344 | - public function prependAppend($field, $prepend, $append) |
|
| 345 | - { |
|
| 346 | - $class = array(); |
|
| 347 | - if ($prepend) { |
|
| 348 | - $class[] = 'input-prepend'; |
|
| 349 | - } |
|
| 350 | - if ($append) { |
|
| 351 | - $class[] = 'input-append'; |
|
| 352 | - } |
|
| 353 | - |
|
| 354 | - $return = '<div class="'.join(' ', $class).'">'; |
|
| 355 | - $return .= join(null, $prepend); |
|
| 356 | - $return .= $field->render(); |
|
| 357 | - $return .= join(null, $append); |
|
| 358 | - $return .= '</div>'; |
|
| 359 | - |
|
| 360 | - return $return; |
|
| 361 | - } |
|
| 362 | - |
|
| 363 | - /** |
|
| 364 | - * Wrap a field with potential additional tags |
|
| 365 | - * |
|
| 366 | - * @param Field $field |
|
| 367 | - * |
|
| 368 | - * @return Element A wrapped field |
|
| 369 | - */ |
|
| 370 | - public function wrapField($field) |
|
| 371 | - { |
|
| 372 | - return Element::create('div', $field)->addClass('controls'); |
|
| 373 | - } |
|
| 374 | - |
|
| 375 | - /** |
|
| 376 | - * Wrap actions block with potential additional tags |
|
| 377 | - * |
|
| 378 | - * @param Actions $actions |
|
| 379 | - * |
|
| 380 | - * @return string A wrapped actions block |
|
| 381 | - */ |
|
| 382 | - public function wrapActions($actions) |
|
| 383 | - { |
|
| 384 | - return $actions; |
|
| 385 | - } |
|
| 16 | + /** |
|
| 17 | + * Form types that trigger special styling for this Framework |
|
| 18 | + * |
|
| 19 | + * @var array |
|
| 20 | + */ |
|
| 21 | + protected $availableTypes = array('horizontal', 'vertical', 'inline', 'search'); |
|
| 22 | + |
|
| 23 | + /** |
|
| 24 | + * The button types available |
|
| 25 | + * |
|
| 26 | + * @var array |
|
| 27 | + */ |
|
| 28 | + private $buttons = array( |
|
| 29 | + 'large', |
|
| 30 | + 'small', |
|
| 31 | + 'mini', |
|
| 32 | + 'block', |
|
| 33 | + 'danger', |
|
| 34 | + 'info', |
|
| 35 | + 'inverse', |
|
| 36 | + 'link', |
|
| 37 | + 'primary', |
|
| 38 | + 'success', |
|
| 39 | + 'warning', |
|
| 40 | + ); |
|
| 41 | + |
|
| 42 | + /** |
|
| 43 | + * The field sizes available |
|
| 44 | + * |
|
| 45 | + * @var array |
|
| 46 | + */ |
|
| 47 | + private $fields = array( |
|
| 48 | + 'mini', |
|
| 49 | + 'small', |
|
| 50 | + 'medium', |
|
| 51 | + 'large', |
|
| 52 | + 'xlarge', |
|
| 53 | + 'xxlarge', |
|
| 54 | + 'span1', |
|
| 55 | + 'span2', |
|
| 56 | + 'span3', |
|
| 57 | + 'span4', |
|
| 58 | + 'span5', |
|
| 59 | + 'span6', |
|
| 60 | + 'span7', |
|
| 61 | + 'span8', |
|
| 62 | + 'span9', |
|
| 63 | + 'span10', |
|
| 64 | + 'span11', |
|
| 65 | + 'span12', |
|
| 66 | + ); |
|
| 67 | + |
|
| 68 | + /** |
|
| 69 | + * The field states available |
|
| 70 | + * |
|
| 71 | + * @var array |
|
| 72 | + */ |
|
| 73 | + protected $states = array( |
|
| 74 | + 'success', |
|
| 75 | + 'warning', |
|
| 76 | + 'error', |
|
| 77 | + 'info', |
|
| 78 | + ); |
|
| 79 | + |
|
| 80 | + /** |
|
| 81 | + * Create a new TwitterBootstrap instance |
|
| 82 | + * |
|
| 83 | + * @param \Illuminate\Container\Container $app |
|
| 84 | + */ |
|
| 85 | + public function __construct(Container $app) |
|
| 86 | + { |
|
| 87 | + $this->app = $app; |
|
| 88 | + $this->setFrameworkDefaults(); |
|
| 89 | + } |
|
| 90 | + |
|
| 91 | + //////////////////////////////////////////////////////////////////// |
|
| 92 | + /////////////////////////// FILTER ARRAYS ////////////////////////// |
|
| 93 | + //////////////////////////////////////////////////////////////////// |
|
| 94 | + |
|
| 95 | + /** |
|
| 96 | + * Filter buttons classes |
|
| 97 | + * |
|
| 98 | + * @param array $classes An array of classes |
|
| 99 | + * |
|
| 100 | + * @return string[] A filtered array |
|
| 101 | + */ |
|
| 102 | + public function filterButtonClasses($classes) |
|
| 103 | + { |
|
| 104 | + // Filter classes |
|
| 105 | + // $classes = array_intersect($classes, $this->buttons); |
|
| 106 | + |
|
| 107 | + // Prepend button type |
|
| 108 | + $classes = $this->prependWith($classes, 'btn-'); |
|
| 109 | + $classes[] = 'btn'; |
|
| 110 | + |
|
| 111 | + return $classes; |
|
| 112 | + } |
|
| 113 | + |
|
| 114 | + /** |
|
| 115 | + * Filter field classes |
|
| 116 | + * |
|
| 117 | + * @param array $classes An array of classes |
|
| 118 | + * |
|
| 119 | + * @return array A filtered array |
|
| 120 | + */ |
|
| 121 | + public function filterFieldClasses($classes) |
|
| 122 | + { |
|
| 123 | + // Filter classes |
|
| 124 | + $classes = array_intersect($classes, $this->fields); |
|
| 125 | + |
|
| 126 | + // Prepend field type |
|
| 127 | + $classes = array_map(function ($class) { |
|
| 128 | + return Str::startsWith($class, 'span') ? $class : 'input-'.$class; |
|
| 129 | + }, $classes); |
|
| 130 | + |
|
| 131 | + return $classes; |
|
| 132 | + } |
|
| 133 | + |
|
| 134 | + //////////////////////////////////////////////////////////////////// |
|
| 135 | + ///////////////////////////// ADD CLASSES ////////////////////////// |
|
| 136 | + //////////////////////////////////////////////////////////////////// |
|
| 137 | + |
|
| 138 | + /** |
|
| 139 | + * Add classes to a field |
|
| 140 | + * |
|
| 141 | + * @param Field $field |
|
| 142 | + * @param array $classes The possible classes to add |
|
| 143 | + * |
|
| 144 | + * @return Field |
|
| 145 | + */ |
|
| 146 | + public function getFieldClasses(Field $field, $classes) |
|
| 147 | + { |
|
| 148 | + // Add inline class for checkables |
|
| 149 | + if ($field->isCheckable() and in_array('inline', $classes)) { |
|
| 150 | + $field->inline(); |
|
| 151 | + } |
|
| 152 | + |
|
| 153 | + // Filter classes according to field type |
|
| 154 | + if ($field->isButton()) { |
|
| 155 | + $classes = $this->filterButtonClasses($classes); |
|
| 156 | + } else { |
|
| 157 | + $classes = $this->filterFieldClasses($classes); |
|
| 158 | + } |
|
| 159 | + |
|
| 160 | + return $this->addClassesToField($field, $classes); |
|
| 161 | + } |
|
| 162 | + |
|
| 163 | + /** |
|
| 164 | + * Add group classes |
|
| 165 | + * |
|
| 166 | + * @return string A list of group classes |
|
| 167 | + */ |
|
| 168 | + public function getGroupClasses() |
|
| 169 | + { |
|
| 170 | + return 'control-group'; |
|
| 171 | + } |
|
| 172 | + |
|
| 173 | + /** |
|
| 174 | + * Add label classes |
|
| 175 | + * |
|
| 176 | + * @return string An array of attributes with the label class |
|
| 177 | + */ |
|
| 178 | + public function getLabelClasses() |
|
| 179 | + { |
|
| 180 | + return 'control-label'; |
|
| 181 | + } |
|
| 182 | + |
|
| 183 | + /** |
|
| 184 | + * Add uneditable field classes |
|
| 185 | + * |
|
| 186 | + * @return string An array of attributes with the uneditable class |
|
| 187 | + */ |
|
| 188 | + public function getUneditableClasses() |
|
| 189 | + { |
|
| 190 | + return 'uneditable-input'; |
|
| 191 | + } |
|
| 192 | + |
|
| 193 | + public function getPlainTextClasses() |
|
| 194 | + { |
|
| 195 | + return null; |
|
| 196 | + } |
|
| 197 | + |
|
| 198 | + /** |
|
| 199 | + * Add form class |
|
| 200 | + * |
|
| 201 | + * @param string $type The type of form to add |
|
| 202 | + * |
|
| 203 | + * @return string|null |
|
| 204 | + */ |
|
| 205 | + public function getFormClasses($type) |
|
| 206 | + { |
|
| 207 | + return $type ? 'form-'.$type : null; |
|
| 208 | + } |
|
| 209 | + |
|
| 210 | + /** |
|
| 211 | + * Add actions block class |
|
| 212 | + * |
|
| 213 | + * @return string |
|
| 214 | + */ |
|
| 215 | + public function getActionClasses() |
|
| 216 | + { |
|
| 217 | + return 'form-actions'; |
|
| 218 | + } |
|
| 219 | + |
|
| 220 | + //////////////////////////////////////////////////////////////////// |
|
| 221 | + //////////////////////////// RENDER BLOCKS ///////////////////////// |
|
| 222 | + //////////////////////////////////////////////////////////////////// |
|
| 223 | + |
|
| 224 | + /** |
|
| 225 | + * Render an help text |
|
| 226 | + * |
|
| 227 | + * @param string $text |
|
| 228 | + * @param array $attributes |
|
| 229 | + * |
|
| 230 | + * @return Element |
|
| 231 | + */ |
|
| 232 | + public function createHelp($text, $attributes = array()) |
|
| 233 | + { |
|
| 234 | + return Element::create('span', $text, $attributes)->addClass('help-inline'); |
|
| 235 | + } |
|
| 236 | + |
|
| 237 | + /** |
|
| 238 | + * Render a block help text |
|
| 239 | + * |
|
| 240 | + * @param string $text |
|
| 241 | + * @param array $attributes |
|
| 242 | + * |
|
| 243 | + * @return Element |
|
| 244 | + */ |
|
| 245 | + public function createBlockHelp($text, $attributes = array()) |
|
| 246 | + { |
|
| 247 | + return Element::create('p', $text, $attributes)->addClass('help-block'); |
|
| 248 | + } |
|
| 249 | + |
|
| 250 | + /** |
|
| 251 | + * Render a disabled field |
|
| 252 | + * |
|
| 253 | + * @param Field $field |
|
| 254 | + * |
|
| 255 | + * @return Element |
|
| 256 | + */ |
|
| 257 | + public function createDisabledField(Field $field) |
|
| 258 | + { |
|
| 259 | + return Element::create('span', $field->getValue(), $field->getAttributes()); |
|
| 260 | + } |
|
| 261 | + |
|
| 262 | + /** |
|
| 263 | + * Render a plain text field |
|
| 264 | + * Which fallback to a disabled field |
|
| 265 | + * |
|
| 266 | + * @param Field $field |
|
| 267 | + * |
|
| 268 | + * @return Element |
|
| 269 | + */ |
|
| 270 | + public function createPlainTextField(Field $field) |
|
| 271 | + { |
|
| 272 | + return $this->createDisabledField($field); |
|
| 273 | + } |
|
| 274 | + |
|
| 275 | + /** |
|
| 276 | + * Render an icon |
|
| 277 | + * |
|
| 278 | + * @param array $attributes Its general attributes |
|
| 279 | + * |
|
| 280 | + * @return string |
|
| 281 | + */ |
|
| 282 | + public function createIcon($iconType, $attributes = array(), $iconSettings = array()) |
|
| 283 | + { |
|
| 284 | + // Check for empty icons |
|
| 285 | + if (!$iconType) { |
|
| 286 | + return false; |
|
| 287 | + } |
|
| 288 | + |
|
| 289 | + // Create tag |
|
| 290 | + $tag = array_get($iconSettings, 'tag', $this->iconTag); |
|
| 291 | + $icon = Element::create($tag, null, $attributes); |
|
| 292 | + |
|
| 293 | + // White icons ignore user overrides to use legacy Bootstrap styling |
|
| 294 | + if (Str::contains($iconType, 'white')) { |
|
| 295 | + $iconType = str_replace('white', '', $iconType); |
|
| 296 | + $iconType = trim($iconType, '-'); |
|
| 297 | + $icon->addClass('icon-white'); |
|
| 298 | + $set = null; |
|
| 299 | + $prefix = 'icon'; |
|
| 300 | + } else { |
|
| 301 | + $set = array_get($iconSettings, 'set', $this->iconSet); |
|
| 302 | + $prefix = array_get($iconSettings, 'prefix', $this->iconPrefix); |
|
| 303 | + } |
|
| 304 | + $icon->addClass("$set $prefix-$iconType"); |
|
| 305 | + |
|
| 306 | + return $icon; |
|
| 307 | + } |
|
| 308 | + |
|
| 309 | + //////////////////////////////////////////////////////////////////// |
|
| 310 | + //////////////////////////// WRAP BLOCKS /////////////////////////// |
|
| 311 | + //////////////////////////////////////////////////////////////////// |
|
| 312 | + |
|
| 313 | + /** |
|
| 314 | + * Wrap an item to be prepended or appended to the current field |
|
| 315 | + * |
|
| 316 | + * @param string $item |
|
| 317 | + * |
|
| 318 | + * @return string A wrapped item |
|
| 319 | + */ |
|
| 320 | + public function placeAround($item) |
|
| 321 | + { |
|
| 322 | + // Render object |
|
| 323 | + if (is_object($item) and method_exists($item, '__toString')) { |
|
| 324 | + $item = $item->__toString(); |
|
| 325 | + } |
|
| 326 | + |
|
| 327 | + // Return unwrapped if button |
|
| 328 | + if (strpos($item, '<button') !== false) { |
|
| 329 | + return $item; |
|
| 330 | + } |
|
| 331 | + |
|
| 332 | + return Element::create('span', $item)->addClass('add-on'); |
|
| 333 | + } |
|
| 334 | + |
|
| 335 | + /** |
|
| 336 | + * Wrap a field with prepended and appended items |
|
| 337 | + * |
|
| 338 | + * @param Field $field |
|
| 339 | + * @param array $prepend |
|
| 340 | + * @param array $append |
|
| 341 | + * |
|
| 342 | + * @return string A field concatented with prepended and/or appended items |
|
| 343 | + */ |
|
| 344 | + public function prependAppend($field, $prepend, $append) |
|
| 345 | + { |
|
| 346 | + $class = array(); |
|
| 347 | + if ($prepend) { |
|
| 348 | + $class[] = 'input-prepend'; |
|
| 349 | + } |
|
| 350 | + if ($append) { |
|
| 351 | + $class[] = 'input-append'; |
|
| 352 | + } |
|
| 353 | + |
|
| 354 | + $return = '<div class="'.join(' ', $class).'">'; |
|
| 355 | + $return .= join(null, $prepend); |
|
| 356 | + $return .= $field->render(); |
|
| 357 | + $return .= join(null, $append); |
|
| 358 | + $return .= '</div>'; |
|
| 359 | + |
|
| 360 | + return $return; |
|
| 361 | + } |
|
| 362 | + |
|
| 363 | + /** |
|
| 364 | + * Wrap a field with potential additional tags |
|
| 365 | + * |
|
| 366 | + * @param Field $field |
|
| 367 | + * |
|
| 368 | + * @return Element A wrapped field |
|
| 369 | + */ |
|
| 370 | + public function wrapField($field) |
|
| 371 | + { |
|
| 372 | + return Element::create('div', $field)->addClass('controls'); |
|
| 373 | + } |
|
| 374 | + |
|
| 375 | + /** |
|
| 376 | + * Wrap actions block with potential additional tags |
|
| 377 | + * |
|
| 378 | + * @param Actions $actions |
|
| 379 | + * |
|
| 380 | + * @return string A wrapped actions block |
|
| 381 | + */ |
|
| 382 | + public function wrapActions($actions) |
|
| 383 | + { |
|
| 384 | + return $actions; |
|
| 385 | + } |
|
| 386 | 386 | } |
@@ -126,7 +126,7 @@ |
||
| 126 | 126 | * |
| 127 | 127 | * @param Field $field |
| 128 | 128 | * |
| 129 | - * @return Element |
|
| 129 | + * @return Input |
|
| 130 | 130 | */ |
| 131 | 131 | public function createPlainTextField(Field $field) |
| 132 | 132 | { |
@@ -13,274 +13,274 @@ |
||
| 13 | 13 | */ |
| 14 | 14 | class ZurbFoundation extends Framework implements FrameworkInterface |
| 15 | 15 | { |
| 16 | - /** |
|
| 17 | - * Form types that trigger special styling for this Framework |
|
| 18 | - * |
|
| 19 | - * @var array |
|
| 20 | - */ |
|
| 21 | - protected $availableTypes = array('horizontal', 'vertical'); |
|
| 22 | - |
|
| 23 | - /** |
|
| 24 | - * The field sizes available |
|
| 25 | - * |
|
| 26 | - * @var array |
|
| 27 | - */ |
|
| 28 | - private $fields = array( |
|
| 29 | - 1 => 'one', |
|
| 30 | - 2 => 'two', |
|
| 31 | - 3 => 'three', |
|
| 32 | - 4 => 'four', |
|
| 33 | - 5 => 'five', |
|
| 34 | - 6 => 'six', |
|
| 35 | - 7 => 'seven', |
|
| 36 | - 8 => 'eight', |
|
| 37 | - 9 => 'nine', |
|
| 38 | - 10 => 'ten', |
|
| 39 | - 11 => 'eleven', |
|
| 40 | - 12 => 'twelve', |
|
| 41 | - ); |
|
| 42 | - |
|
| 43 | - /** |
|
| 44 | - * The field states available |
|
| 45 | - * |
|
| 46 | - * @var array |
|
| 47 | - */ |
|
| 48 | - protected $states = array( |
|
| 49 | - 'error', |
|
| 50 | - ); |
|
| 51 | - |
|
| 52 | - /** |
|
| 53 | - * Create a new ZurbFoundation instance |
|
| 54 | - * |
|
| 55 | - * @param Container $app |
|
| 56 | - */ |
|
| 57 | - public function __construct(Container $app) |
|
| 58 | - { |
|
| 59 | - $this->app = $app; |
|
| 60 | - $this->setFrameworkDefaults(); |
|
| 61 | - } |
|
| 62 | - |
|
| 63 | - //////////////////////////////////////////////////////////////////// |
|
| 64 | - /////////////////////////// FILTER ARRAYS ////////////////////////// |
|
| 65 | - //////////////////////////////////////////////////////////////////// |
|
| 66 | - |
|
| 67 | - public function filterButtonClasses($classes) |
|
| 68 | - { |
|
| 69 | - return $classes; |
|
| 70 | - } |
|
| 71 | - |
|
| 72 | - public function filterFieldClasses($classes) |
|
| 73 | - { |
|
| 74 | - // Filter classes |
|
| 75 | - $classes = array_intersect($classes, $this->fields); |
|
| 76 | - |
|
| 77 | - return $classes; |
|
| 78 | - } |
|
| 79 | - |
|
| 80 | - //////////////////////////////////////////////////////////////////// |
|
| 81 | - ///////////////////// EXPOSE FRAMEWORK SPECIFICS /////////////////// |
|
| 82 | - //////////////////////////////////////////////////////////////////// |
|
| 83 | - |
|
| 84 | - protected function setFieldWidths($labelWidths) |
|
| 85 | - { |
|
| 86 | - $labelWidthClass = $fieldWidthClass = $fieldOffsetClass = ''; |
|
| 87 | - |
|
| 88 | - $viewports = $this->getFrameworkOption('viewports'); |
|
| 89 | - |
|
| 90 | - foreach ($labelWidths as $viewport => $columns) { |
|
| 91 | - if ($viewport) { |
|
| 92 | - $labelWidthClass .= $viewports[$viewport].$this->fields[$columns].' '; |
|
| 93 | - $fieldWidthClass .= $viewports[$viewport].$this->fields[12 - $columns].' '; |
|
| 94 | - $fieldOffsetClass .= $viewports[$viewport].'offset-by-'.$this->fields[$columns].' '; |
|
| 95 | - } |
|
| 96 | - } |
|
| 97 | - |
|
| 98 | - $this->labelWidth = $labelWidthClass.'columns'; |
|
| 99 | - $this->fieldWidth = $fieldWidthClass.'columns'; |
|
| 100 | - $this->fieldOffset = $fieldOffsetClass.'columns'; |
|
| 101 | - } |
|
| 102 | - |
|
| 103 | - //////////////////////////////////////////////////////////////////// |
|
| 104 | - ///////////////////////////// ADD CLASSES ////////////////////////// |
|
| 105 | - //////////////////////////////////////////////////////////////////// |
|
| 106 | - |
|
| 107 | - public function getFieldClasses(Field $field, $classes = array()) |
|
| 108 | - { |
|
| 109 | - $classes = $this->filterFieldClasses($classes); |
|
| 110 | - |
|
| 111 | - return $this->addClassesToField($field, $classes); |
|
| 112 | - } |
|
| 113 | - |
|
| 114 | - public function getGroupClasses() |
|
| 115 | - { |
|
| 116 | - if ($this->app['former.form']->isOfType('horizontal')) { |
|
| 117 | - return 'row'; |
|
| 118 | - } else { |
|
| 119 | - return null; |
|
| 120 | - } |
|
| 121 | - } |
|
| 122 | - |
|
| 123 | - /** |
|
| 124 | - * Add label classes |
|
| 125 | - * |
|
| 126 | - * @return string|null An array of attributes with the label class |
|
| 127 | - */ |
|
| 128 | - public function getLabelClasses() |
|
| 129 | - { |
|
| 130 | - if ($this->app['former.form']->isOfType('horizontal')) { |
|
| 131 | - return $this->getFrameworkOption('wrappedLabelClasses'); |
|
| 132 | - } else { |
|
| 133 | - return null; |
|
| 134 | - } |
|
| 135 | - } |
|
| 136 | - |
|
| 137 | - public function getUneditableClasses() |
|
| 138 | - { |
|
| 139 | - return null; |
|
| 140 | - } |
|
| 141 | - |
|
| 142 | - public function getPlainTextClasses() |
|
| 143 | - { |
|
| 144 | - return null; |
|
| 145 | - } |
|
| 146 | - |
|
| 147 | - public function getFormClasses($type) |
|
| 148 | - { |
|
| 149 | - return null; |
|
| 150 | - } |
|
| 151 | - |
|
| 152 | - public function getActionClasses() |
|
| 153 | - { |
|
| 154 | - return null; |
|
| 155 | - } |
|
| 156 | - |
|
| 157 | - //////////////////////////////////////////////////////////////////// |
|
| 158 | - //////////////////////////// RENDER BLOCKS ///////////////////////// |
|
| 159 | - //////////////////////////////////////////////////////////////////// |
|
| 160 | - |
|
| 161 | - public function createHelp($text, $attributes = null) |
|
| 162 | - { |
|
| 163 | - if (is_null($attributes) or empty($attributes)) { |
|
| 164 | - $attributes = $this->getFrameworkOption('error_classes'); |
|
| 165 | - } |
|
| 166 | - |
|
| 167 | - return Element::create('span', $text, $attributes); |
|
| 168 | - } |
|
| 169 | - |
|
| 170 | - /** |
|
| 171 | - * Render a disabled field |
|
| 172 | - * |
|
| 173 | - * @param Field $field |
|
| 174 | - * |
|
| 175 | - * @return Input |
|
| 176 | - */ |
|
| 177 | - public function createDisabledField(Field $field) |
|
| 178 | - { |
|
| 179 | - $field->disabled(); |
|
| 180 | - |
|
| 181 | - return Input::create('text', $field->getName(), $field->getValue(), $field->getAttributes()); |
|
| 182 | - } |
|
| 183 | - |
|
| 184 | - /** |
|
| 185 | - * Render a plain text field |
|
| 186 | - * Which fallback to a disabled field |
|
| 187 | - * |
|
| 188 | - * @param Field $field |
|
| 189 | - * |
|
| 190 | - * @return Element |
|
| 191 | - */ |
|
| 192 | - public function createPlainTextField(Field $field) |
|
| 193 | - { |
|
| 194 | - return $this->createDisabledField($field); |
|
| 195 | - } |
|
| 196 | - |
|
| 197 | - //////////////////////////////////////////////////////////////////// |
|
| 198 | - //////////////////////////// WRAP BLOCKS /////////////////////////// |
|
| 199 | - //////////////////////////////////////////////////////////////////// |
|
| 200 | - |
|
| 201 | - /** |
|
| 202 | - * Wrap an item to be prepended or appended to the current field. |
|
| 203 | - * For Zurb we return the item and handle the wrapping in prependAppend |
|
| 204 | - * as wrapping is dependent on whether we're prepending or appending. |
|
| 205 | - * |
|
| 206 | - * @return string A wrapped item |
|
| 207 | - */ |
|
| 208 | - public function placeAround($item) |
|
| 209 | - { |
|
| 210 | - return $item; |
|
| 211 | - } |
|
| 212 | - |
|
| 213 | - /** |
|
| 214 | - * Wrap a field with prepended and appended items |
|
| 215 | - * |
|
| 216 | - * @param Field $field |
|
| 217 | - * @param array $prepend |
|
| 218 | - * @param array $append |
|
| 219 | - * |
|
| 220 | - * @return string A field concatented with prepended and/or appended items |
|
| 221 | - */ |
|
| 222 | - public function prependAppend($field, $prepend, $append) |
|
| 223 | - { |
|
| 224 | - $return = ''; |
|
| 225 | - |
|
| 226 | - foreach ($prepend as $item) { |
|
| 227 | - $return .= '<div class="two mobile-one columns"><span class="prefix">'.$item.'</span></div>'; |
|
| 228 | - } |
|
| 229 | - |
|
| 230 | - $return .= '<div class="ten mobile-three columns">'.$field->render().'</div>'; |
|
| 231 | - |
|
| 232 | - foreach ($append as $item) { |
|
| 233 | - $return .= '<div class="two mobile-one columns"><span class="postfix">'.$item.'</span></div>'; |
|
| 234 | - } |
|
| 235 | - |
|
| 236 | - return $return; |
|
| 237 | - } |
|
| 238 | - |
|
| 239 | - /** |
|
| 240 | - * Wraps all label contents with potential additional tags. |
|
| 241 | - * |
|
| 242 | - * @param string $label |
|
| 243 | - * |
|
| 244 | - * @return string A wrapped label |
|
| 245 | - */ |
|
| 246 | - public function wrapLabel($label) |
|
| 247 | - { |
|
| 248 | - if ($this->app['former.form']->isOfType('horizontal')) { |
|
| 249 | - return Element::create('div', $label)->addClass($this->labelWidth); |
|
| 250 | - } else { |
|
| 251 | - return $label; |
|
| 252 | - } |
|
| 253 | - } |
|
| 254 | - |
|
| 255 | - /** |
|
| 256 | - * Wraps all field contents with potential additional tags. |
|
| 257 | - * |
|
| 258 | - * @param Field $field |
|
| 259 | - * |
|
| 260 | - * @return Element A wrapped field |
|
| 261 | - */ |
|
| 262 | - public function wrapField($field) |
|
| 263 | - { |
|
| 264 | - if ($this->app['former.form']->isOfType('horizontal')) { |
|
| 265 | - return Element::create('div', $field)->addClass($this->fieldWidth); |
|
| 266 | - } else { |
|
| 267 | - return $field; |
|
| 268 | - } |
|
| 269 | - } |
|
| 270 | - |
|
| 271 | - /** |
|
| 272 | - * Wrap actions block with potential additional tags |
|
| 273 | - * |
|
| 274 | - * @param Actions $actions |
|
| 275 | - * |
|
| 276 | - * @return string A wrapped actions block |
|
| 277 | - */ |
|
| 278 | - public function wrapActions($actions) |
|
| 279 | - { |
|
| 280 | - if ($this->app['former.form']->isOfType('horizontal')) { |
|
| 281 | - return Element::create('div', $actions)->addClass(array($this->fieldOffset, $this->fieldWidth)); |
|
| 282 | - } else { |
|
| 283 | - return $actions; |
|
| 284 | - } |
|
| 285 | - } |
|
| 16 | + /** |
|
| 17 | + * Form types that trigger special styling for this Framework |
|
| 18 | + * |
|
| 19 | + * @var array |
|
| 20 | + */ |
|
| 21 | + protected $availableTypes = array('horizontal', 'vertical'); |
|
| 22 | + |
|
| 23 | + /** |
|
| 24 | + * The field sizes available |
|
| 25 | + * |
|
| 26 | + * @var array |
|
| 27 | + */ |
|
| 28 | + private $fields = array( |
|
| 29 | + 1 => 'one', |
|
| 30 | + 2 => 'two', |
|
| 31 | + 3 => 'three', |
|
| 32 | + 4 => 'four', |
|
| 33 | + 5 => 'five', |
|
| 34 | + 6 => 'six', |
|
| 35 | + 7 => 'seven', |
|
| 36 | + 8 => 'eight', |
|
| 37 | + 9 => 'nine', |
|
| 38 | + 10 => 'ten', |
|
| 39 | + 11 => 'eleven', |
|
| 40 | + 12 => 'twelve', |
|
| 41 | + ); |
|
| 42 | + |
|
| 43 | + /** |
|
| 44 | + * The field states available |
|
| 45 | + * |
|
| 46 | + * @var array |
|
| 47 | + */ |
|
| 48 | + protected $states = array( |
|
| 49 | + 'error', |
|
| 50 | + ); |
|
| 51 | + |
|
| 52 | + /** |
|
| 53 | + * Create a new ZurbFoundation instance |
|
| 54 | + * |
|
| 55 | + * @param Container $app |
|
| 56 | + */ |
|
| 57 | + public function __construct(Container $app) |
|
| 58 | + { |
|
| 59 | + $this->app = $app; |
|
| 60 | + $this->setFrameworkDefaults(); |
|
| 61 | + } |
|
| 62 | + |
|
| 63 | + //////////////////////////////////////////////////////////////////// |
|
| 64 | + /////////////////////////// FILTER ARRAYS ////////////////////////// |
|
| 65 | + //////////////////////////////////////////////////////////////////// |
|
| 66 | + |
|
| 67 | + public function filterButtonClasses($classes) |
|
| 68 | + { |
|
| 69 | + return $classes; |
|
| 70 | + } |
|
| 71 | + |
|
| 72 | + public function filterFieldClasses($classes) |
|
| 73 | + { |
|
| 74 | + // Filter classes |
|
| 75 | + $classes = array_intersect($classes, $this->fields); |
|
| 76 | + |
|
| 77 | + return $classes; |
|
| 78 | + } |
|
| 79 | + |
|
| 80 | + //////////////////////////////////////////////////////////////////// |
|
| 81 | + ///////////////////// EXPOSE FRAMEWORK SPECIFICS /////////////////// |
|
| 82 | + //////////////////////////////////////////////////////////////////// |
|
| 83 | + |
|
| 84 | + protected function setFieldWidths($labelWidths) |
|
| 85 | + { |
|
| 86 | + $labelWidthClass = $fieldWidthClass = $fieldOffsetClass = ''; |
|
| 87 | + |
|
| 88 | + $viewports = $this->getFrameworkOption('viewports'); |
|
| 89 | + |
|
| 90 | + foreach ($labelWidths as $viewport => $columns) { |
|
| 91 | + if ($viewport) { |
|
| 92 | + $labelWidthClass .= $viewports[$viewport].$this->fields[$columns].' '; |
|
| 93 | + $fieldWidthClass .= $viewports[$viewport].$this->fields[12 - $columns].' '; |
|
| 94 | + $fieldOffsetClass .= $viewports[$viewport].'offset-by-'.$this->fields[$columns].' '; |
|
| 95 | + } |
|
| 96 | + } |
|
| 97 | + |
|
| 98 | + $this->labelWidth = $labelWidthClass.'columns'; |
|
| 99 | + $this->fieldWidth = $fieldWidthClass.'columns'; |
|
| 100 | + $this->fieldOffset = $fieldOffsetClass.'columns'; |
|
| 101 | + } |
|
| 102 | + |
|
| 103 | + //////////////////////////////////////////////////////////////////// |
|
| 104 | + ///////////////////////////// ADD CLASSES ////////////////////////// |
|
| 105 | + //////////////////////////////////////////////////////////////////// |
|
| 106 | + |
|
| 107 | + public function getFieldClasses(Field $field, $classes = array()) |
|
| 108 | + { |
|
| 109 | + $classes = $this->filterFieldClasses($classes); |
|
| 110 | + |
|
| 111 | + return $this->addClassesToField($field, $classes); |
|
| 112 | + } |
|
| 113 | + |
|
| 114 | + public function getGroupClasses() |
|
| 115 | + { |
|
| 116 | + if ($this->app['former.form']->isOfType('horizontal')) { |
|
| 117 | + return 'row'; |
|
| 118 | + } else { |
|
| 119 | + return null; |
|
| 120 | + } |
|
| 121 | + } |
|
| 122 | + |
|
| 123 | + /** |
|
| 124 | + * Add label classes |
|
| 125 | + * |
|
| 126 | + * @return string|null An array of attributes with the label class |
|
| 127 | + */ |
|
| 128 | + public function getLabelClasses() |
|
| 129 | + { |
|
| 130 | + if ($this->app['former.form']->isOfType('horizontal')) { |
|
| 131 | + return $this->getFrameworkOption('wrappedLabelClasses'); |
|
| 132 | + } else { |
|
| 133 | + return null; |
|
| 134 | + } |
|
| 135 | + } |
|
| 136 | + |
|
| 137 | + public function getUneditableClasses() |
|
| 138 | + { |
|
| 139 | + return null; |
|
| 140 | + } |
|
| 141 | + |
|
| 142 | + public function getPlainTextClasses() |
|
| 143 | + { |
|
| 144 | + return null; |
|
| 145 | + } |
|
| 146 | + |
|
| 147 | + public function getFormClasses($type) |
|
| 148 | + { |
|
| 149 | + return null; |
|
| 150 | + } |
|
| 151 | + |
|
| 152 | + public function getActionClasses() |
|
| 153 | + { |
|
| 154 | + return null; |
|
| 155 | + } |
|
| 156 | + |
|
| 157 | + //////////////////////////////////////////////////////////////////// |
|
| 158 | + //////////////////////////// RENDER BLOCKS ///////////////////////// |
|
| 159 | + //////////////////////////////////////////////////////////////////// |
|
| 160 | + |
|
| 161 | + public function createHelp($text, $attributes = null) |
|
| 162 | + { |
|
| 163 | + if (is_null($attributes) or empty($attributes)) { |
|
| 164 | + $attributes = $this->getFrameworkOption('error_classes'); |
|
| 165 | + } |
|
| 166 | + |
|
| 167 | + return Element::create('span', $text, $attributes); |
|
| 168 | + } |
|
| 169 | + |
|
| 170 | + /** |
|
| 171 | + * Render a disabled field |
|
| 172 | + * |
|
| 173 | + * @param Field $field |
|
| 174 | + * |
|
| 175 | + * @return Input |
|
| 176 | + */ |
|
| 177 | + public function createDisabledField(Field $field) |
|
| 178 | + { |
|
| 179 | + $field->disabled(); |
|
| 180 | + |
|
| 181 | + return Input::create('text', $field->getName(), $field->getValue(), $field->getAttributes()); |
|
| 182 | + } |
|
| 183 | + |
|
| 184 | + /** |
|
| 185 | + * Render a plain text field |
|
| 186 | + * Which fallback to a disabled field |
|
| 187 | + * |
|
| 188 | + * @param Field $field |
|
| 189 | + * |
|
| 190 | + * @return Element |
|
| 191 | + */ |
|
| 192 | + public function createPlainTextField(Field $field) |
|
| 193 | + { |
|
| 194 | + return $this->createDisabledField($field); |
|
| 195 | + } |
|
| 196 | + |
|
| 197 | + //////////////////////////////////////////////////////////////////// |
|
| 198 | + //////////////////////////// WRAP BLOCKS /////////////////////////// |
|
| 199 | + //////////////////////////////////////////////////////////////////// |
|
| 200 | + |
|
| 201 | + /** |
|
| 202 | + * Wrap an item to be prepended or appended to the current field. |
|
| 203 | + * For Zurb we return the item and handle the wrapping in prependAppend |
|
| 204 | + * as wrapping is dependent on whether we're prepending or appending. |
|
| 205 | + * |
|
| 206 | + * @return string A wrapped item |
|
| 207 | + */ |
|
| 208 | + public function placeAround($item) |
|
| 209 | + { |
|
| 210 | + return $item; |
|
| 211 | + } |
|
| 212 | + |
|
| 213 | + /** |
|
| 214 | + * Wrap a field with prepended and appended items |
|
| 215 | + * |
|
| 216 | + * @param Field $field |
|
| 217 | + * @param array $prepend |
|
| 218 | + * @param array $append |
|
| 219 | + * |
|
| 220 | + * @return string A field concatented with prepended and/or appended items |
|
| 221 | + */ |
|
| 222 | + public function prependAppend($field, $prepend, $append) |
|
| 223 | + { |
|
| 224 | + $return = ''; |
|
| 225 | + |
|
| 226 | + foreach ($prepend as $item) { |
|
| 227 | + $return .= '<div class="two mobile-one columns"><span class="prefix">'.$item.'</span></div>'; |
|
| 228 | + } |
|
| 229 | + |
|
| 230 | + $return .= '<div class="ten mobile-three columns">'.$field->render().'</div>'; |
|
| 231 | + |
|
| 232 | + foreach ($append as $item) { |
|
| 233 | + $return .= '<div class="two mobile-one columns"><span class="postfix">'.$item.'</span></div>'; |
|
| 234 | + } |
|
| 235 | + |
|
| 236 | + return $return; |
|
| 237 | + } |
|
| 238 | + |
|
| 239 | + /** |
|
| 240 | + * Wraps all label contents with potential additional tags. |
|
| 241 | + * |
|
| 242 | + * @param string $label |
|
| 243 | + * |
|
| 244 | + * @return string A wrapped label |
|
| 245 | + */ |
|
| 246 | + public function wrapLabel($label) |
|
| 247 | + { |
|
| 248 | + if ($this->app['former.form']->isOfType('horizontal')) { |
|
| 249 | + return Element::create('div', $label)->addClass($this->labelWidth); |
|
| 250 | + } else { |
|
| 251 | + return $label; |
|
| 252 | + } |
|
| 253 | + } |
|
| 254 | + |
|
| 255 | + /** |
|
| 256 | + * Wraps all field contents with potential additional tags. |
|
| 257 | + * |
|
| 258 | + * @param Field $field |
|
| 259 | + * |
|
| 260 | + * @return Element A wrapped field |
|
| 261 | + */ |
|
| 262 | + public function wrapField($field) |
|
| 263 | + { |
|
| 264 | + if ($this->app['former.form']->isOfType('horizontal')) { |
|
| 265 | + return Element::create('div', $field)->addClass($this->fieldWidth); |
|
| 266 | + } else { |
|
| 267 | + return $field; |
|
| 268 | + } |
|
| 269 | + } |
|
| 270 | + |
|
| 271 | + /** |
|
| 272 | + * Wrap actions block with potential additional tags |
|
| 273 | + * |
|
| 274 | + * @param Actions $actions |
|
| 275 | + * |
|
| 276 | + * @return string A wrapped actions block |
|
| 277 | + */ |
|
| 278 | + public function wrapActions($actions) |
|
| 279 | + { |
|
| 280 | + if ($this->app['former.form']->isOfType('horizontal')) { |
|
| 281 | + return Element::create('div', $actions)->addClass(array($this->fieldOffset, $this->fieldWidth)); |
|
| 282 | + } else { |
|
| 283 | + return $actions; |
|
| 284 | + } |
|
| 285 | + } |
|
| 286 | 286 | } |
@@ -126,7 +126,7 @@ |
||
| 126 | 126 | * |
| 127 | 127 | * @param Field $field |
| 128 | 128 | * |
| 129 | - * @return Element |
|
| 129 | + * @return Input |
|
| 130 | 130 | */ |
| 131 | 131 | public function createPlainTextField(Field $field) |
| 132 | 132 | { |
@@ -13,281 +13,281 @@ |
||
| 13 | 13 | */ |
| 14 | 14 | class ZurbFoundation4 extends Framework implements FrameworkInterface |
| 15 | 15 | { |
| 16 | - /** |
|
| 17 | - * Form types that trigger special styling for this Framework |
|
| 18 | - * |
|
| 19 | - * @var array |
|
| 20 | - */ |
|
| 21 | - protected $availableTypes = array('horizontal', 'vertical'); |
|
| 22 | - |
|
| 23 | - /** |
|
| 24 | - * The button types available |
|
| 25 | - * |
|
| 26 | - * @var array |
|
| 27 | - */ |
|
| 28 | - private $buttons = array( |
|
| 29 | - 'tiny', |
|
| 30 | - 'small', |
|
| 31 | - 'medium', |
|
| 32 | - 'large', |
|
| 33 | - 'success', |
|
| 34 | - 'radius', |
|
| 35 | - 'round', |
|
| 36 | - 'disabled', |
|
| 37 | - 'prefix', |
|
| 38 | - 'postfix', |
|
| 39 | - ); |
|
| 40 | - |
|
| 41 | - /** |
|
| 42 | - * The field sizes available |
|
| 43 | - * Zurb Foundation 4 does not apply sizes to the form element, but to the wrapper div |
|
| 44 | - * |
|
| 45 | - * @var array |
|
| 46 | - */ |
|
| 47 | - private $fields = array(); |
|
| 48 | - |
|
| 49 | - /** |
|
| 50 | - * The field states available |
|
| 51 | - * |
|
| 52 | - * @var array |
|
| 53 | - */ |
|
| 54 | - protected $states = array( |
|
| 55 | - 'error', |
|
| 56 | - ); |
|
| 57 | - |
|
| 58 | - /** |
|
| 59 | - * Create a new ZurbFoundation instance |
|
| 60 | - * |
|
| 61 | - * @param \Illuminate\Container\Container $app |
|
| 62 | - */ |
|
| 63 | - public function __construct(Container $app) |
|
| 64 | - { |
|
| 65 | - $this->app = $app; |
|
| 66 | - $this->setFrameworkDefaults(); |
|
| 67 | - } |
|
| 68 | - |
|
| 69 | - //////////////////////////////////////////////////////////////////// |
|
| 70 | - /////////////////////////// FILTER ARRAYS ////////////////////////// |
|
| 71 | - //////////////////////////////////////////////////////////////////// |
|
| 72 | - |
|
| 73 | - public function filterButtonClasses($classes) |
|
| 74 | - { |
|
| 75 | - // Filter classes |
|
| 76 | - $classes = array_intersect($classes, $this->buttons); |
|
| 77 | - $classes[] = 'button'; |
|
| 78 | - |
|
| 79 | - return $classes; |
|
| 80 | - } |
|
| 81 | - |
|
| 82 | - public function filterFieldClasses($classes) |
|
| 83 | - { |
|
| 84 | - return null; |
|
| 85 | - } |
|
| 86 | - |
|
| 87 | - //////////////////////////////////////////////////////////////////// |
|
| 88 | - ///////////////////// EXPOSE FRAMEWORK SPECIFICS /////////////////// |
|
| 89 | - //////////////////////////////////////////////////////////////////// |
|
| 90 | - |
|
| 91 | - protected function setFieldWidths($labelWidths) |
|
| 92 | - { |
|
| 93 | - $labelWidthClass = $fieldWidthClass = $fieldOffsetClass = ''; |
|
| 94 | - |
|
| 95 | - $viewports = $this->getFrameworkOption('viewports'); |
|
| 96 | - |
|
| 97 | - foreach ($labelWidths as $viewport => $columns) { |
|
| 98 | - if ($viewport) { |
|
| 99 | - $labelWidthClass .= $viewports[$viewport].'-'.$columns.' '; |
|
| 100 | - $fieldWidthClass .= $viewports[$viewport].'-'.(12 - $columns).' '; |
|
| 101 | - $fieldOffsetClass .= $viewports[$viewport].'-offset-'.$columns.' '; |
|
| 102 | - } |
|
| 103 | - } |
|
| 104 | - |
|
| 105 | - $this->labelWidth = $labelWidthClass.'columns'; |
|
| 106 | - $this->fieldWidth = $fieldWidthClass.'columns'; |
|
| 107 | - $this->fieldOffset = $fieldOffsetClass.'columns'; |
|
| 108 | - } |
|
| 109 | - |
|
| 110 | - //////////////////////////////////////////////////////////////////// |
|
| 111 | - ///////////////////////////// ADD CLASSES ////////////////////////// |
|
| 112 | - //////////////////////////////////////////////////////////////////// |
|
| 113 | - |
|
| 114 | - public function getFieldClasses(Field $field, $classes = array()) |
|
| 115 | - { |
|
| 116 | - if ($field->isButton()) { |
|
| 117 | - $classes = $this->filterButtonClasses($classes); |
|
| 118 | - } else { |
|
| 119 | - $classes = $this->filterFieldClasses($classes); |
|
| 120 | - } |
|
| 121 | - |
|
| 122 | - return $this->addClassesToField($field, $classes); |
|
| 123 | - } |
|
| 124 | - |
|
| 125 | - public function getGroupClasses() |
|
| 126 | - { |
|
| 127 | - if ($this->app['former.form']->isOfType('horizontal')) { |
|
| 128 | - return 'row'; |
|
| 129 | - } else { |
|
| 130 | - return null; |
|
| 131 | - } |
|
| 132 | - } |
|
| 133 | - |
|
| 134 | - /** |
|
| 135 | - * Add label classes |
|
| 136 | - * |
|
| 137 | - * @return string|null An array of attributes with the label class |
|
| 138 | - */ |
|
| 139 | - public function getLabelClasses() |
|
| 140 | - { |
|
| 141 | - if ($this->app['former.form']->isOfType('horizontal')) { |
|
| 142 | - return $this->getFrameworkOption('wrappedLabelClasses'); |
|
| 143 | - } else { |
|
| 144 | - return null; |
|
| 145 | - } |
|
| 146 | - } |
|
| 147 | - |
|
| 148 | - public function getUneditableClasses() |
|
| 149 | - { |
|
| 150 | - return null; |
|
| 151 | - } |
|
| 152 | - |
|
| 153 | - public function getPlainTextClasses() |
|
| 154 | - { |
|
| 155 | - return null; |
|
| 156 | - } |
|
| 157 | - |
|
| 158 | - public function getFormClasses($type) |
|
| 159 | - { |
|
| 160 | - return null; |
|
| 161 | - } |
|
| 162 | - |
|
| 163 | - public function getActionClasses() |
|
| 164 | - { |
|
| 165 | - return null; |
|
| 166 | - } |
|
| 167 | - |
|
| 168 | - //////////////////////////////////////////////////////////////////// |
|
| 169 | - //////////////////////////// RENDER BLOCKS ///////////////////////// |
|
| 170 | - //////////////////////////////////////////////////////////////////// |
|
| 171 | - |
|
| 172 | - public function createHelp($text, $attributes = null) |
|
| 173 | - { |
|
| 174 | - if (is_null($attributes) or empty($attributes)) { |
|
| 175 | - $attributes = $this->getFrameworkOption('error_classes'); |
|
| 176 | - } |
|
| 177 | - |
|
| 178 | - return Element::create('span', $text, $attributes); |
|
| 179 | - } |
|
| 180 | - |
|
| 181 | - /** |
|
| 182 | - * Render a disabled field |
|
| 183 | - * |
|
| 184 | - * @param Field $field |
|
| 185 | - * |
|
| 186 | - * @return Input |
|
| 187 | - */ |
|
| 188 | - public function createDisabledField(Field $field) |
|
| 189 | - { |
|
| 190 | - $field->disabled(); |
|
| 191 | - |
|
| 192 | - return Input::create('text', $field->getName(), $field->getValue(), $field->getAttributes()); |
|
| 193 | - } |
|
| 194 | - |
|
| 195 | - /** |
|
| 196 | - * Render a plain text field |
|
| 197 | - * Which fallback to a disabled field |
|
| 198 | - * |
|
| 199 | - * @param Field $field |
|
| 200 | - * |
|
| 201 | - * @return Element |
|
| 202 | - */ |
|
| 203 | - public function createPlainTextField(Field $field) |
|
| 204 | - { |
|
| 205 | - return $this->createDisabledField($field); |
|
| 206 | - } |
|
| 207 | - |
|
| 208 | - //////////////////////////////////////////////////////////////////// |
|
| 209 | - //////////////////////////// WRAP BLOCKS /////////////////////////// |
|
| 210 | - //////////////////////////////////////////////////////////////////// |
|
| 211 | - |
|
| 212 | - /** |
|
| 213 | - * Wrap an item to be prepended or appended to the current field. |
|
| 214 | - * For Zurb we return the item and handle the wrapping in prependAppend |
|
| 215 | - * as wrapping is dependent on whether we're prepending or appending. |
|
| 216 | - * |
|
| 217 | - * @return string A wrapped item |
|
| 218 | - */ |
|
| 219 | - public function placeAround($item) |
|
| 220 | - { |
|
| 221 | - return $item; |
|
| 222 | - } |
|
| 223 | - |
|
| 224 | - /** |
|
| 225 | - * Wrap a field with prepended and appended items |
|
| 226 | - * |
|
| 227 | - * @param Field $field |
|
| 228 | - * @param array $prepend |
|
| 229 | - * @param array $append |
|
| 230 | - * |
|
| 231 | - * @return string A field concatented with prepended and/or appended items |
|
| 232 | - */ |
|
| 233 | - public function prependAppend($field, $prepend, $append) |
|
| 234 | - { |
|
| 235 | - $return = ''; |
|
| 236 | - |
|
| 237 | - foreach ($prepend as $item) { |
|
| 238 | - $return .= '<div class="large-2 small-3 columns"><span class="prefix">'.$item.'</span></div>'; |
|
| 239 | - } |
|
| 240 | - |
|
| 241 | - $return .= '<div class="large-10 small-9 columns">'.$field->render().'</div>'; |
|
| 242 | - |
|
| 243 | - foreach ($append as $item) { |
|
| 244 | - $return .= '<div class="large-2 small-3 columns"><span class="postfix">'.$item.'</span></div>'; |
|
| 245 | - } |
|
| 246 | - |
|
| 247 | - return $return; |
|
| 248 | - } |
|
| 249 | - |
|
| 250 | - /** |
|
| 251 | - * Wraps all label contents with potential additional tags. |
|
| 252 | - * |
|
| 253 | - * @param string $label |
|
| 254 | - * |
|
| 255 | - * @return string A wrapped label |
|
| 256 | - */ |
|
| 257 | - public function wrapLabel($label) |
|
| 258 | - { |
|
| 259 | - if ($this->app['former.form']->isOfType('horizontal')) { |
|
| 260 | - return Element::create('div', $label)->addClass($this->labelWidth); |
|
| 261 | - } else { |
|
| 262 | - return $label; |
|
| 263 | - } |
|
| 264 | - } |
|
| 265 | - |
|
| 266 | - /** |
|
| 267 | - * Wraps all field contents with potential additional tags. |
|
| 268 | - * |
|
| 269 | - * @param Field $field |
|
| 270 | - * |
|
| 271 | - * @return Element A wrapped field |
|
| 272 | - */ |
|
| 273 | - public function wrapField($field) |
|
| 274 | - { |
|
| 275 | - if ($this->app['former.form']->isOfType('horizontal')) { |
|
| 276 | - return Element::create('div', $field)->addClass($this->fieldWidth); |
|
| 277 | - } else { |
|
| 278 | - return $field; |
|
| 279 | - } |
|
| 280 | - } |
|
| 281 | - |
|
| 282 | - /** |
|
| 283 | - * Wrap actions block with potential additional tags |
|
| 284 | - * |
|
| 285 | - * @param Actions $actions |
|
| 286 | - * |
|
| 287 | - * @return string A wrapped actions block |
|
| 288 | - */ |
|
| 289 | - public function wrapActions($actions) |
|
| 290 | - { |
|
| 291 | - return $actions; |
|
| 292 | - } |
|
| 16 | + /** |
|
| 17 | + * Form types that trigger special styling for this Framework |
|
| 18 | + * |
|
| 19 | + * @var array |
|
| 20 | + */ |
|
| 21 | + protected $availableTypes = array('horizontal', 'vertical'); |
|
| 22 | + |
|
| 23 | + /** |
|
| 24 | + * The button types available |
|
| 25 | + * |
|
| 26 | + * @var array |
|
| 27 | + */ |
|
| 28 | + private $buttons = array( |
|
| 29 | + 'tiny', |
|
| 30 | + 'small', |
|
| 31 | + 'medium', |
|
| 32 | + 'large', |
|
| 33 | + 'success', |
|
| 34 | + 'radius', |
|
| 35 | + 'round', |
|
| 36 | + 'disabled', |
|
| 37 | + 'prefix', |
|
| 38 | + 'postfix', |
|
| 39 | + ); |
|
| 40 | + |
|
| 41 | + /** |
|
| 42 | + * The field sizes available |
|
| 43 | + * Zurb Foundation 4 does not apply sizes to the form element, but to the wrapper div |
|
| 44 | + * |
|
| 45 | + * @var array |
|
| 46 | + */ |
|
| 47 | + private $fields = array(); |
|
| 48 | + |
|
| 49 | + /** |
|
| 50 | + * The field states available |
|
| 51 | + * |
|
| 52 | + * @var array |
|
| 53 | + */ |
|
| 54 | + protected $states = array( |
|
| 55 | + 'error', |
|
| 56 | + ); |
|
| 57 | + |
|
| 58 | + /** |
|
| 59 | + * Create a new ZurbFoundation instance |
|
| 60 | + * |
|
| 61 | + * @param \Illuminate\Container\Container $app |
|
| 62 | + */ |
|
| 63 | + public function __construct(Container $app) |
|
| 64 | + { |
|
| 65 | + $this->app = $app; |
|
| 66 | + $this->setFrameworkDefaults(); |
|
| 67 | + } |
|
| 68 | + |
|
| 69 | + //////////////////////////////////////////////////////////////////// |
|
| 70 | + /////////////////////////// FILTER ARRAYS ////////////////////////// |
|
| 71 | + //////////////////////////////////////////////////////////////////// |
|
| 72 | + |
|
| 73 | + public function filterButtonClasses($classes) |
|
| 74 | + { |
|
| 75 | + // Filter classes |
|
| 76 | + $classes = array_intersect($classes, $this->buttons); |
|
| 77 | + $classes[] = 'button'; |
|
| 78 | + |
|
| 79 | + return $classes; |
|
| 80 | + } |
|
| 81 | + |
|
| 82 | + public function filterFieldClasses($classes) |
|
| 83 | + { |
|
| 84 | + return null; |
|
| 85 | + } |
|
| 86 | + |
|
| 87 | + //////////////////////////////////////////////////////////////////// |
|
| 88 | + ///////////////////// EXPOSE FRAMEWORK SPECIFICS /////////////////// |
|
| 89 | + //////////////////////////////////////////////////////////////////// |
|
| 90 | + |
|
| 91 | + protected function setFieldWidths($labelWidths) |
|
| 92 | + { |
|
| 93 | + $labelWidthClass = $fieldWidthClass = $fieldOffsetClass = ''; |
|
| 94 | + |
|
| 95 | + $viewports = $this->getFrameworkOption('viewports'); |
|
| 96 | + |
|
| 97 | + foreach ($labelWidths as $viewport => $columns) { |
|
| 98 | + if ($viewport) { |
|
| 99 | + $labelWidthClass .= $viewports[$viewport].'-'.$columns.' '; |
|
| 100 | + $fieldWidthClass .= $viewports[$viewport].'-'.(12 - $columns).' '; |
|
| 101 | + $fieldOffsetClass .= $viewports[$viewport].'-offset-'.$columns.' '; |
|
| 102 | + } |
|
| 103 | + } |
|
| 104 | + |
|
| 105 | + $this->labelWidth = $labelWidthClass.'columns'; |
|
| 106 | + $this->fieldWidth = $fieldWidthClass.'columns'; |
|
| 107 | + $this->fieldOffset = $fieldOffsetClass.'columns'; |
|
| 108 | + } |
|
| 109 | + |
|
| 110 | + //////////////////////////////////////////////////////////////////// |
|
| 111 | + ///////////////////////////// ADD CLASSES ////////////////////////// |
|
| 112 | + //////////////////////////////////////////////////////////////////// |
|
| 113 | + |
|
| 114 | + public function getFieldClasses(Field $field, $classes = array()) |
|
| 115 | + { |
|
| 116 | + if ($field->isButton()) { |
|
| 117 | + $classes = $this->filterButtonClasses($classes); |
|
| 118 | + } else { |
|
| 119 | + $classes = $this->filterFieldClasses($classes); |
|
| 120 | + } |
|
| 121 | + |
|
| 122 | + return $this->addClassesToField($field, $classes); |
|
| 123 | + } |
|
| 124 | + |
|
| 125 | + public function getGroupClasses() |
|
| 126 | + { |
|
| 127 | + if ($this->app['former.form']->isOfType('horizontal')) { |
|
| 128 | + return 'row'; |
|
| 129 | + } else { |
|
| 130 | + return null; |
|
| 131 | + } |
|
| 132 | + } |
|
| 133 | + |
|
| 134 | + /** |
|
| 135 | + * Add label classes |
|
| 136 | + * |
|
| 137 | + * @return string|null An array of attributes with the label class |
|
| 138 | + */ |
|
| 139 | + public function getLabelClasses() |
|
| 140 | + { |
|
| 141 | + if ($this->app['former.form']->isOfType('horizontal')) { |
|
| 142 | + return $this->getFrameworkOption('wrappedLabelClasses'); |
|
| 143 | + } else { |
|
| 144 | + return null; |
|
| 145 | + } |
|
| 146 | + } |
|
| 147 | + |
|
| 148 | + public function getUneditableClasses() |
|
| 149 | + { |
|
| 150 | + return null; |
|
| 151 | + } |
|
| 152 | + |
|
| 153 | + public function getPlainTextClasses() |
|
| 154 | + { |
|
| 155 | + return null; |
|
| 156 | + } |
|
| 157 | + |
|
| 158 | + public function getFormClasses($type) |
|
| 159 | + { |
|
| 160 | + return null; |
|
| 161 | + } |
|
| 162 | + |
|
| 163 | + public function getActionClasses() |
|
| 164 | + { |
|
| 165 | + return null; |
|
| 166 | + } |
|
| 167 | + |
|
| 168 | + //////////////////////////////////////////////////////////////////// |
|
| 169 | + //////////////////////////// RENDER BLOCKS ///////////////////////// |
|
| 170 | + //////////////////////////////////////////////////////////////////// |
|
| 171 | + |
|
| 172 | + public function createHelp($text, $attributes = null) |
|
| 173 | + { |
|
| 174 | + if (is_null($attributes) or empty($attributes)) { |
|
| 175 | + $attributes = $this->getFrameworkOption('error_classes'); |
|
| 176 | + } |
|
| 177 | + |
|
| 178 | + return Element::create('span', $text, $attributes); |
|
| 179 | + } |
|
| 180 | + |
|
| 181 | + /** |
|
| 182 | + * Render a disabled field |
|
| 183 | + * |
|
| 184 | + * @param Field $field |
|
| 185 | + * |
|
| 186 | + * @return Input |
|
| 187 | + */ |
|
| 188 | + public function createDisabledField(Field $field) |
|
| 189 | + { |
|
| 190 | + $field->disabled(); |
|
| 191 | + |
|
| 192 | + return Input::create('text', $field->getName(), $field->getValue(), $field->getAttributes()); |
|
| 193 | + } |
|
| 194 | + |
|
| 195 | + /** |
|
| 196 | + * Render a plain text field |
|
| 197 | + * Which fallback to a disabled field |
|
| 198 | + * |
|
| 199 | + * @param Field $field |
|
| 200 | + * |
|
| 201 | + * @return Element |
|
| 202 | + */ |
|
| 203 | + public function createPlainTextField(Field $field) |
|
| 204 | + { |
|
| 205 | + return $this->createDisabledField($field); |
|
| 206 | + } |
|
| 207 | + |
|
| 208 | + //////////////////////////////////////////////////////////////////// |
|
| 209 | + //////////////////////////// WRAP BLOCKS /////////////////////////// |
|
| 210 | + //////////////////////////////////////////////////////////////////// |
|
| 211 | + |
|
| 212 | + /** |
|
| 213 | + * Wrap an item to be prepended or appended to the current field. |
|
| 214 | + * For Zurb we return the item and handle the wrapping in prependAppend |
|
| 215 | + * as wrapping is dependent on whether we're prepending or appending. |
|
| 216 | + * |
|
| 217 | + * @return string A wrapped item |
|
| 218 | + */ |
|
| 219 | + public function placeAround($item) |
|
| 220 | + { |
|
| 221 | + return $item; |
|
| 222 | + } |
|
| 223 | + |
|
| 224 | + /** |
|
| 225 | + * Wrap a field with prepended and appended items |
|
| 226 | + * |
|
| 227 | + * @param Field $field |
|
| 228 | + * @param array $prepend |
|
| 229 | + * @param array $append |
|
| 230 | + * |
|
| 231 | + * @return string A field concatented with prepended and/or appended items |
|
| 232 | + */ |
|
| 233 | + public function prependAppend($field, $prepend, $append) |
|
| 234 | + { |
|
| 235 | + $return = ''; |
|
| 236 | + |
|
| 237 | + foreach ($prepend as $item) { |
|
| 238 | + $return .= '<div class="large-2 small-3 columns"><span class="prefix">'.$item.'</span></div>'; |
|
| 239 | + } |
|
| 240 | + |
|
| 241 | + $return .= '<div class="large-10 small-9 columns">'.$field->render().'</div>'; |
|
| 242 | + |
|
| 243 | + foreach ($append as $item) { |
|
| 244 | + $return .= '<div class="large-2 small-3 columns"><span class="postfix">'.$item.'</span></div>'; |
|
| 245 | + } |
|
| 246 | + |
|
| 247 | + return $return; |
|
| 248 | + } |
|
| 249 | + |
|
| 250 | + /** |
|
| 251 | + * Wraps all label contents with potential additional tags. |
|
| 252 | + * |
|
| 253 | + * @param string $label |
|
| 254 | + * |
|
| 255 | + * @return string A wrapped label |
|
| 256 | + */ |
|
| 257 | + public function wrapLabel($label) |
|
| 258 | + { |
|
| 259 | + if ($this->app['former.form']->isOfType('horizontal')) { |
|
| 260 | + return Element::create('div', $label)->addClass($this->labelWidth); |
|
| 261 | + } else { |
|
| 262 | + return $label; |
|
| 263 | + } |
|
| 264 | + } |
|
| 265 | + |
|
| 266 | + /** |
|
| 267 | + * Wraps all field contents with potential additional tags. |
|
| 268 | + * |
|
| 269 | + * @param Field $field |
|
| 270 | + * |
|
| 271 | + * @return Element A wrapped field |
|
| 272 | + */ |
|
| 273 | + public function wrapField($field) |
|
| 274 | + { |
|
| 275 | + if ($this->app['former.form']->isOfType('horizontal')) { |
|
| 276 | + return Element::create('div', $field)->addClass($this->fieldWidth); |
|
| 277 | + } else { |
|
| 278 | + return $field; |
|
| 279 | + } |
|
| 280 | + } |
|
| 281 | + |
|
| 282 | + /** |
|
| 283 | + * Wrap actions block with potential additional tags |
|
| 284 | + * |
|
| 285 | + * @param Actions $actions |
|
| 286 | + * |
|
| 287 | + * @return string A wrapped actions block |
|
| 288 | + */ |
|
| 289 | + public function wrapActions($actions) |
|
| 290 | + { |
|
| 291 | + return $actions; |
|
| 292 | + } |
|
| 293 | 293 | } |
@@ -126,7 +126,7 @@ |
||
| 126 | 126 | * |
| 127 | 127 | * @param Field $field |
| 128 | 128 | * |
| 129 | - * @return Element |
|
| 129 | + * @return Input |
|
| 130 | 130 | */ |
| 131 | 131 | public function createPlainTextField(Field $field) |
| 132 | 132 | { |
@@ -13,283 +13,283 @@ |
||
| 13 | 13 | */ |
| 14 | 14 | class ZurbFoundation5 extends Framework implements FrameworkInterface |
| 15 | 15 | { |
| 16 | - /** |
|
| 17 | - * Form types that trigger special styling for this Framework |
|
| 18 | - * |
|
| 19 | - * @var array |
|
| 20 | - */ |
|
| 21 | - protected $availableTypes = array('horizontal', 'vertical'); |
|
| 22 | - |
|
| 23 | - /** |
|
| 24 | - * The button types available |
|
| 25 | - * |
|
| 26 | - * @var array |
|
| 27 | - */ |
|
| 28 | - private $buttons = array( |
|
| 29 | - 'tiny', |
|
| 30 | - 'small', |
|
| 31 | - 'medium', |
|
| 32 | - 'large', |
|
| 33 | - 'success', |
|
| 34 | - 'radius', |
|
| 35 | - 'round', |
|
| 36 | - 'disabled', |
|
| 37 | - 'prefix', |
|
| 38 | - 'postfix', |
|
| 39 | - ); |
|
| 40 | - |
|
| 41 | - /** |
|
| 42 | - * The field sizes available |
|
| 43 | - * Zurb Foundation 5 does not apply sizes to the form element, but to the wrapper div |
|
| 44 | - * |
|
| 45 | - * @var array |
|
| 46 | - */ |
|
| 47 | - private $fields = array(); |
|
| 48 | - |
|
| 49 | - /** |
|
| 50 | - * The field states available |
|
| 51 | - * |
|
| 52 | - * @var array |
|
| 53 | - */ |
|
| 54 | - protected $states = array( |
|
| 55 | - 'error', |
|
| 56 | - ); |
|
| 57 | - |
|
| 58 | - /** |
|
| 59 | - * Create a new ZurbFoundation instance |
|
| 60 | - * |
|
| 61 | - * @param \Illuminate\Container\Container $app |
|
| 62 | - */ |
|
| 63 | - public function __construct(Container $app) |
|
| 64 | - { |
|
| 65 | - $this->app = $app; |
|
| 66 | - $this->setFrameworkDefaults(); |
|
| 67 | - } |
|
| 68 | - |
|
| 69 | - //////////////////////////////////////////////////////////////////// |
|
| 70 | - /////////////////////////// FILTER ARRAYS ////////////////////////// |
|
| 71 | - //////////////////////////////////////////////////////////////////// |
|
| 72 | - |
|
| 73 | - public function filterButtonClasses($classes) |
|
| 74 | - { |
|
| 75 | - // Filter classes |
|
| 76 | - $classes = array_intersect($classes, $this->buttons); |
|
| 77 | - $classes[] = 'button'; |
|
| 78 | - |
|
| 79 | - return $classes; |
|
| 80 | - } |
|
| 81 | - |
|
| 82 | - public function filterFieldClasses($classes) |
|
| 83 | - { |
|
| 84 | - return null; |
|
| 85 | - } |
|
| 86 | - |
|
| 87 | - //////////////////////////////////////////////////////////////////// |
|
| 88 | - ///////////////////// EXPOSE FRAMEWORK SPECIFICS /////////////////// |
|
| 89 | - //////////////////////////////////////////////////////////////////// |
|
| 90 | - |
|
| 91 | - protected function setFieldWidths($labelWidths) |
|
| 92 | - { |
|
| 93 | - $labelWidthClass = $fieldWidthClass = $fieldOffsetClass = ''; |
|
| 94 | - |
|
| 95 | - $viewports = $this->getFrameworkOption('viewports'); |
|
| 96 | - |
|
| 97 | - foreach ($labelWidths as $viewport => $columns) { |
|
| 98 | - if ($viewport) { |
|
| 99 | - $labelWidthClass .= $viewports[$viewport].'-'.$columns.' '; |
|
| 100 | - $fieldWidthClass .= $viewports[$viewport].'-'.(12 - $columns).' '; |
|
| 101 | - $fieldOffsetClass .= $viewports[$viewport].'-offset-'.$columns.' '; |
|
| 102 | - } |
|
| 103 | - } |
|
| 104 | - |
|
| 105 | - $this->labelWidth = $labelWidthClass.'columns'; |
|
| 106 | - $this->fieldWidth = $fieldWidthClass.'columns'; |
|
| 107 | - $this->fieldOffset = $fieldOffsetClass.'columns'; |
|
| 108 | - } |
|
| 109 | - |
|
| 110 | - //////////////////////////////////////////////////////////////////// |
|
| 111 | - ///////////////////////////// ADD CLASSES ////////////////////////// |
|
| 112 | - //////////////////////////////////////////////////////////////////// |
|
| 113 | - |
|
| 114 | - public function getFieldClasses(Field $field, $classes = array()) |
|
| 115 | - { |
|
| 116 | - if ($field->isButton()) { |
|
| 117 | - $classes = $this->filterButtonClasses($classes); |
|
| 118 | - } else { |
|
| 119 | - $classes = $this->filterFieldClasses($classes); |
|
| 120 | - } |
|
| 121 | - |
|
| 122 | - return $this->addClassesToField($field, $classes); |
|
| 123 | - } |
|
| 124 | - |
|
| 125 | - public function getGroupClasses() |
|
| 126 | - { |
|
| 127 | - if ($this->app['former.form']->isOfType('horizontal')) { |
|
| 128 | - return 'row'; |
|
| 129 | - } else { |
|
| 130 | - return null; |
|
| 131 | - } |
|
| 132 | - } |
|
| 133 | - |
|
| 134 | - /** |
|
| 135 | - * Add label classes |
|
| 136 | - * |
|
| 137 | - * @return string|null An array of attributes with the label class |
|
| 138 | - */ |
|
| 139 | - public function getLabelClasses() |
|
| 140 | - { |
|
| 141 | - if ($this->app['former.form']->isOfType('horizontal')) { |
|
| 142 | - return $this->getFrameworkOption('wrappedLabelClasses'); |
|
| 143 | - } else { |
|
| 144 | - return null; |
|
| 145 | - } |
|
| 146 | - } |
|
| 147 | - |
|
| 148 | - public function getUneditableClasses() |
|
| 149 | - { |
|
| 150 | - return null; |
|
| 151 | - } |
|
| 152 | - |
|
| 153 | - public function getPlainTextClasses() |
|
| 154 | - { |
|
| 155 | - return null; |
|
| 156 | - } |
|
| 157 | - |
|
| 158 | - public function getFormClasses($type) |
|
| 159 | - { |
|
| 160 | - return null; |
|
| 161 | - } |
|
| 162 | - |
|
| 163 | - public function getActionClasses() |
|
| 164 | - { |
|
| 165 | - return null; |
|
| 166 | - } |
|
| 167 | - |
|
| 168 | - //////////////////////////////////////////////////////////////////// |
|
| 169 | - //////////////////////////// RENDER BLOCKS ///////////////////////// |
|
| 170 | - //////////////////////////////////////////////////////////////////// |
|
| 171 | - |
|
| 172 | - public function createHelp($text, $attributes = null) |
|
| 173 | - { |
|
| 174 | - if (is_null($attributes) or empty($attributes)) { |
|
| 175 | - $attributes = $this->getFrameworkOption('error_classes'); |
|
| 176 | - } |
|
| 177 | - |
|
| 178 | - return Element::create('small', $text, $attributes); |
|
| 179 | - } |
|
| 180 | - |
|
| 181 | - /** |
|
| 182 | - * Render a disabled field |
|
| 183 | - * |
|
| 184 | - * @param Field $field |
|
| 185 | - * |
|
| 186 | - * @return Input |
|
| 187 | - */ |
|
| 188 | - public function createDisabledField(Field $field) |
|
| 189 | - { |
|
| 190 | - $field->disabled(); |
|
| 191 | - |
|
| 192 | - return Input::create('text', $field->getName(), $field->getValue(), $field->getAttributes()); |
|
| 193 | - } |
|
| 194 | - |
|
| 195 | - /** |
|
| 196 | - * Render a plain text field |
|
| 197 | - * Which fallback to a disabled field |
|
| 198 | - * |
|
| 199 | - * @param Field $field |
|
| 200 | - * |
|
| 201 | - * @return Element |
|
| 202 | - */ |
|
| 203 | - public function createPlainTextField(Field $field) |
|
| 204 | - { |
|
| 205 | - return $this->createDisabledField($field); |
|
| 206 | - } |
|
| 207 | - |
|
| 208 | - //////////////////////////////////////////////////////////////////// |
|
| 209 | - //////////////////////////// WRAP BLOCKS /////////////////////////// |
|
| 210 | - //////////////////////////////////////////////////////////////////// |
|
| 211 | - |
|
| 212 | - /** |
|
| 213 | - * Wrap an item to be prepended or appended to the current field. |
|
| 214 | - * For Zurb we return the item and handle the wrapping in prependAppend |
|
| 215 | - * as wrapping is dependent on whether we're prepending or appending. |
|
| 216 | - * |
|
| 217 | - * @return string A wrapped item |
|
| 218 | - */ |
|
| 219 | - public function placeAround($item) |
|
| 220 | - { |
|
| 221 | - return $item; |
|
| 222 | - } |
|
| 223 | - |
|
| 224 | - /** |
|
| 225 | - * Wrap a field with prepended and appended items |
|
| 226 | - * |
|
| 227 | - * @param Field $field |
|
| 228 | - * @param array $prepend |
|
| 229 | - * @param array $append |
|
| 230 | - * |
|
| 231 | - * @return string A field concatented with prepended and/or appended items |
|
| 232 | - */ |
|
| 233 | - public function prependAppend($field, $prepend, $append) |
|
| 234 | - { |
|
| 235 | - $return = '<div class="row collapse">'; |
|
| 236 | - |
|
| 237 | - foreach ($prepend as $item) { |
|
| 238 | - $return .= '<div class="large-2 small-3 columns"><span class="prefix">'.$item.'</span></div>'; |
|
| 239 | - } |
|
| 240 | - |
|
| 241 | - $return .= '<div class="large-10 small-9 columns">'.$field->render().'</div>'; |
|
| 242 | - |
|
| 243 | - foreach ($append as $item) { |
|
| 244 | - $return .= '<div class="large-2 small-3 columns"><span class="postfix">'.$item.'</span></div>'; |
|
| 245 | - } |
|
| 246 | - |
|
| 247 | - $return .= '</div>'; |
|
| 248 | - |
|
| 249 | - return $return; |
|
| 250 | - } |
|
| 251 | - |
|
| 252 | - /** |
|
| 253 | - * Wraps all label contents with potential additional tags. |
|
| 254 | - * |
|
| 255 | - * @param string $label |
|
| 256 | - * |
|
| 257 | - * @return string A wrapped label |
|
| 258 | - */ |
|
| 259 | - public function wrapLabel($label) |
|
| 260 | - { |
|
| 261 | - if ($this->app['former.form']->isOfType('horizontal')) { |
|
| 262 | - return Element::create('div', $label)->addClass($this->labelWidth); |
|
| 263 | - } else { |
|
| 264 | - return $label; |
|
| 265 | - } |
|
| 266 | - } |
|
| 267 | - |
|
| 268 | - /** |
|
| 269 | - * Wraps all field contents with potential additional tags. |
|
| 270 | - * |
|
| 271 | - * @param Field $field |
|
| 272 | - * |
|
| 273 | - * @return Element A wrapped field |
|
| 274 | - */ |
|
| 275 | - public function wrapField($field) |
|
| 276 | - { |
|
| 277 | - if ($this->app['former.form']->isOfType('horizontal')) { |
|
| 278 | - return Element::create('div', $field)->addClass($this->fieldWidth); |
|
| 279 | - } else { |
|
| 280 | - return $field; |
|
| 281 | - } |
|
| 282 | - } |
|
| 283 | - |
|
| 284 | - /** |
|
| 285 | - * Wrap actions block with potential additional tags |
|
| 286 | - * |
|
| 287 | - * @param Actions $actions |
|
| 288 | - * |
|
| 289 | - * @return string A wrapped actions block |
|
| 290 | - */ |
|
| 291 | - public function wrapActions($actions) |
|
| 292 | - { |
|
| 293 | - return $actions; |
|
| 294 | - } |
|
| 16 | + /** |
|
| 17 | + * Form types that trigger special styling for this Framework |
|
| 18 | + * |
|
| 19 | + * @var array |
|
| 20 | + */ |
|
| 21 | + protected $availableTypes = array('horizontal', 'vertical'); |
|
| 22 | + |
|
| 23 | + /** |
|
| 24 | + * The button types available |
|
| 25 | + * |
|
| 26 | + * @var array |
|
| 27 | + */ |
|
| 28 | + private $buttons = array( |
|
| 29 | + 'tiny', |
|
| 30 | + 'small', |
|
| 31 | + 'medium', |
|
| 32 | + 'large', |
|
| 33 | + 'success', |
|
| 34 | + 'radius', |
|
| 35 | + 'round', |
|
| 36 | + 'disabled', |
|
| 37 | + 'prefix', |
|
| 38 | + 'postfix', |
|
| 39 | + ); |
|
| 40 | + |
|
| 41 | + /** |
|
| 42 | + * The field sizes available |
|
| 43 | + * Zurb Foundation 5 does not apply sizes to the form element, but to the wrapper div |
|
| 44 | + * |
|
| 45 | + * @var array |
|
| 46 | + */ |
|
| 47 | + private $fields = array(); |
|
| 48 | + |
|
| 49 | + /** |
|
| 50 | + * The field states available |
|
| 51 | + * |
|
| 52 | + * @var array |
|
| 53 | + */ |
|
| 54 | + protected $states = array( |
|
| 55 | + 'error', |
|
| 56 | + ); |
|
| 57 | + |
|
| 58 | + /** |
|
| 59 | + * Create a new ZurbFoundation instance |
|
| 60 | + * |
|
| 61 | + * @param \Illuminate\Container\Container $app |
|
| 62 | + */ |
|
| 63 | + public function __construct(Container $app) |
|
| 64 | + { |
|
| 65 | + $this->app = $app; |
|
| 66 | + $this->setFrameworkDefaults(); |
|
| 67 | + } |
|
| 68 | + |
|
| 69 | + //////////////////////////////////////////////////////////////////// |
|
| 70 | + /////////////////////////// FILTER ARRAYS ////////////////////////// |
|
| 71 | + //////////////////////////////////////////////////////////////////// |
|
| 72 | + |
|
| 73 | + public function filterButtonClasses($classes) |
|
| 74 | + { |
|
| 75 | + // Filter classes |
|
| 76 | + $classes = array_intersect($classes, $this->buttons); |
|
| 77 | + $classes[] = 'button'; |
|
| 78 | + |
|
| 79 | + return $classes; |
|
| 80 | + } |
|
| 81 | + |
|
| 82 | + public function filterFieldClasses($classes) |
|
| 83 | + { |
|
| 84 | + return null; |
|
| 85 | + } |
|
| 86 | + |
|
| 87 | + //////////////////////////////////////////////////////////////////// |
|
| 88 | + ///////////////////// EXPOSE FRAMEWORK SPECIFICS /////////////////// |
|
| 89 | + //////////////////////////////////////////////////////////////////// |
|
| 90 | + |
|
| 91 | + protected function setFieldWidths($labelWidths) |
|
| 92 | + { |
|
| 93 | + $labelWidthClass = $fieldWidthClass = $fieldOffsetClass = ''; |
|
| 94 | + |
|
| 95 | + $viewports = $this->getFrameworkOption('viewports'); |
|
| 96 | + |
|
| 97 | + foreach ($labelWidths as $viewport => $columns) { |
|
| 98 | + if ($viewport) { |
|
| 99 | + $labelWidthClass .= $viewports[$viewport].'-'.$columns.' '; |
|
| 100 | + $fieldWidthClass .= $viewports[$viewport].'-'.(12 - $columns).' '; |
|
| 101 | + $fieldOffsetClass .= $viewports[$viewport].'-offset-'.$columns.' '; |
|
| 102 | + } |
|
| 103 | + } |
|
| 104 | + |
|
| 105 | + $this->labelWidth = $labelWidthClass.'columns'; |
|
| 106 | + $this->fieldWidth = $fieldWidthClass.'columns'; |
|
| 107 | + $this->fieldOffset = $fieldOffsetClass.'columns'; |
|
| 108 | + } |
|
| 109 | + |
|
| 110 | + //////////////////////////////////////////////////////////////////// |
|
| 111 | + ///////////////////////////// ADD CLASSES ////////////////////////// |
|
| 112 | + //////////////////////////////////////////////////////////////////// |
|
| 113 | + |
|
| 114 | + public function getFieldClasses(Field $field, $classes = array()) |
|
| 115 | + { |
|
| 116 | + if ($field->isButton()) { |
|
| 117 | + $classes = $this->filterButtonClasses($classes); |
|
| 118 | + } else { |
|
| 119 | + $classes = $this->filterFieldClasses($classes); |
|
| 120 | + } |
|
| 121 | + |
|
| 122 | + return $this->addClassesToField($field, $classes); |
|
| 123 | + } |
|
| 124 | + |
|
| 125 | + public function getGroupClasses() |
|
| 126 | + { |
|
| 127 | + if ($this->app['former.form']->isOfType('horizontal')) { |
|
| 128 | + return 'row'; |
|
| 129 | + } else { |
|
| 130 | + return null; |
|
| 131 | + } |
|
| 132 | + } |
|
| 133 | + |
|
| 134 | + /** |
|
| 135 | + * Add label classes |
|
| 136 | + * |
|
| 137 | + * @return string|null An array of attributes with the label class |
|
| 138 | + */ |
|
| 139 | + public function getLabelClasses() |
|
| 140 | + { |
|
| 141 | + if ($this->app['former.form']->isOfType('horizontal')) { |
|
| 142 | + return $this->getFrameworkOption('wrappedLabelClasses'); |
|
| 143 | + } else { |
|
| 144 | + return null; |
|
| 145 | + } |
|
| 146 | + } |
|
| 147 | + |
|
| 148 | + public function getUneditableClasses() |
|
| 149 | + { |
|
| 150 | + return null; |
|
| 151 | + } |
|
| 152 | + |
|
| 153 | + public function getPlainTextClasses() |
|
| 154 | + { |
|
| 155 | + return null; |
|
| 156 | + } |
|
| 157 | + |
|
| 158 | + public function getFormClasses($type) |
|
| 159 | + { |
|
| 160 | + return null; |
|
| 161 | + } |
|
| 162 | + |
|
| 163 | + public function getActionClasses() |
|
| 164 | + { |
|
| 165 | + return null; |
|
| 166 | + } |
|
| 167 | + |
|
| 168 | + //////////////////////////////////////////////////////////////////// |
|
| 169 | + //////////////////////////// RENDER BLOCKS ///////////////////////// |
|
| 170 | + //////////////////////////////////////////////////////////////////// |
|
| 171 | + |
|
| 172 | + public function createHelp($text, $attributes = null) |
|
| 173 | + { |
|
| 174 | + if (is_null($attributes) or empty($attributes)) { |
|
| 175 | + $attributes = $this->getFrameworkOption('error_classes'); |
|
| 176 | + } |
|
| 177 | + |
|
| 178 | + return Element::create('small', $text, $attributes); |
|
| 179 | + } |
|
| 180 | + |
|
| 181 | + /** |
|
| 182 | + * Render a disabled field |
|
| 183 | + * |
|
| 184 | + * @param Field $field |
|
| 185 | + * |
|
| 186 | + * @return Input |
|
| 187 | + */ |
|
| 188 | + public function createDisabledField(Field $field) |
|
| 189 | + { |
|
| 190 | + $field->disabled(); |
|
| 191 | + |
|
| 192 | + return Input::create('text', $field->getName(), $field->getValue(), $field->getAttributes()); |
|
| 193 | + } |
|
| 194 | + |
|
| 195 | + /** |
|
| 196 | + * Render a plain text field |
|
| 197 | + * Which fallback to a disabled field |
|
| 198 | + * |
|
| 199 | + * @param Field $field |
|
| 200 | + * |
|
| 201 | + * @return Element |
|
| 202 | + */ |
|
| 203 | + public function createPlainTextField(Field $field) |
|
| 204 | + { |
|
| 205 | + return $this->createDisabledField($field); |
|
| 206 | + } |
|
| 207 | + |
|
| 208 | + //////////////////////////////////////////////////////////////////// |
|
| 209 | + //////////////////////////// WRAP BLOCKS /////////////////////////// |
|
| 210 | + //////////////////////////////////////////////////////////////////// |
|
| 211 | + |
|
| 212 | + /** |
|
| 213 | + * Wrap an item to be prepended or appended to the current field. |
|
| 214 | + * For Zurb we return the item and handle the wrapping in prependAppend |
|
| 215 | + * as wrapping is dependent on whether we're prepending or appending. |
|
| 216 | + * |
|
| 217 | + * @return string A wrapped item |
|
| 218 | + */ |
|
| 219 | + public function placeAround($item) |
|
| 220 | + { |
|
| 221 | + return $item; |
|
| 222 | + } |
|
| 223 | + |
|
| 224 | + /** |
|
| 225 | + * Wrap a field with prepended and appended items |
|
| 226 | + * |
|
| 227 | + * @param Field $field |
|
| 228 | + * @param array $prepend |
|
| 229 | + * @param array $append |
|
| 230 | + * |
|
| 231 | + * @return string A field concatented with prepended and/or appended items |
|
| 232 | + */ |
|
| 233 | + public function prependAppend($field, $prepend, $append) |
|
| 234 | + { |
|
| 235 | + $return = '<div class="row collapse">'; |
|
| 236 | + |
|
| 237 | + foreach ($prepend as $item) { |
|
| 238 | + $return .= '<div class="large-2 small-3 columns"><span class="prefix">'.$item.'</span></div>'; |
|
| 239 | + } |
|
| 240 | + |
|
| 241 | + $return .= '<div class="large-10 small-9 columns">'.$field->render().'</div>'; |
|
| 242 | + |
|
| 243 | + foreach ($append as $item) { |
|
| 244 | + $return .= '<div class="large-2 small-3 columns"><span class="postfix">'.$item.'</span></div>'; |
|
| 245 | + } |
|
| 246 | + |
|
| 247 | + $return .= '</div>'; |
|
| 248 | + |
|
| 249 | + return $return; |
|
| 250 | + } |
|
| 251 | + |
|
| 252 | + /** |
|
| 253 | + * Wraps all label contents with potential additional tags. |
|
| 254 | + * |
|
| 255 | + * @param string $label |
|
| 256 | + * |
|
| 257 | + * @return string A wrapped label |
|
| 258 | + */ |
|
| 259 | + public function wrapLabel($label) |
|
| 260 | + { |
|
| 261 | + if ($this->app['former.form']->isOfType('horizontal')) { |
|
| 262 | + return Element::create('div', $label)->addClass($this->labelWidth); |
|
| 263 | + } else { |
|
| 264 | + return $label; |
|
| 265 | + } |
|
| 266 | + } |
|
| 267 | + |
|
| 268 | + /** |
|
| 269 | + * Wraps all field contents with potential additional tags. |
|
| 270 | + * |
|
| 271 | + * @param Field $field |
|
| 272 | + * |
|
| 273 | + * @return Element A wrapped field |
|
| 274 | + */ |
|
| 275 | + public function wrapField($field) |
|
| 276 | + { |
|
| 277 | + if ($this->app['former.form']->isOfType('horizontal')) { |
|
| 278 | + return Element::create('div', $field)->addClass($this->fieldWidth); |
|
| 279 | + } else { |
|
| 280 | + return $field; |
|
| 281 | + } |
|
| 282 | + } |
|
| 283 | + |
|
| 284 | + /** |
|
| 285 | + * Wrap actions block with potential additional tags |
|
| 286 | + * |
|
| 287 | + * @param Actions $actions |
|
| 288 | + * |
|
| 289 | + * @return string A wrapped actions block |
|
| 290 | + */ |
|
| 291 | + public function wrapActions($actions) |
|
| 292 | + { |
|
| 293 | + return $actions; |
|
| 294 | + } |
|
| 295 | 295 | } |
@@ -10,105 +10,105 @@ |
||
| 10 | 10 | */ |
| 11 | 11 | class Button extends Field |
| 12 | 12 | { |
| 13 | - /** |
|
| 14 | - * The Button default element |
|
| 15 | - * |
|
| 16 | - * @var string |
|
| 17 | - */ |
|
| 18 | - protected $element = 'input'; |
|
| 13 | + /** |
|
| 14 | + * The Button default element |
|
| 15 | + * |
|
| 16 | + * @var string |
|
| 17 | + */ |
|
| 18 | + protected $element = 'input'; |
|
| 19 | 19 | |
| 20 | - /** |
|
| 21 | - * Default value for self-closing |
|
| 22 | - * |
|
| 23 | - * @var boolean |
|
| 24 | - */ |
|
| 25 | - protected $isSelfClosing = true; |
|
| 20 | + /** |
|
| 21 | + * Default value for self-closing |
|
| 22 | + * |
|
| 23 | + * @var boolean |
|
| 24 | + */ |
|
| 25 | + protected $isSelfClosing = true; |
|
| 26 | 26 | |
| 27 | - /** |
|
| 28 | - * A list of class properties to be added to attributes |
|
| 29 | - * |
|
| 30 | - * @var array |
|
| 31 | - */ |
|
| 32 | - protected $injectedProperties = array( |
|
| 33 | - 'name', |
|
| 34 | - 'type', |
|
| 35 | - 'value', |
|
| 36 | - ); |
|
| 27 | + /** |
|
| 28 | + * A list of class properties to be added to attributes |
|
| 29 | + * |
|
| 30 | + * @var array |
|
| 31 | + */ |
|
| 32 | + protected $injectedProperties = array( |
|
| 33 | + 'name', |
|
| 34 | + 'type', |
|
| 35 | + 'value', |
|
| 36 | + ); |
|
| 37 | 37 | |
| 38 | - //////////////////////////////////////////////////////////////////// |
|
| 39 | - /////////////////////////// CORE METHODS /////////////////////////// |
|
| 40 | - //////////////////////////////////////////////////////////////////// |
|
| 38 | + //////////////////////////////////////////////////////////////////// |
|
| 39 | + /////////////////////////// CORE METHODS /////////////////////////// |
|
| 40 | + //////////////////////////////////////////////////////////////////// |
|
| 41 | 41 | |
| 42 | - /** |
|
| 43 | - * Easier arguments order for button fields |
|
| 44 | - * |
|
| 45 | - * @param Container $app The Container |
|
| 46 | - * @param string $type button/submit/reset/etc |
|
| 47 | - * @param string $value The text of the button |
|
| 48 | - * @param string $link Its link |
|
| 49 | - * @param array $attributes Its attributes |
|
| 50 | - */ |
|
| 51 | - public function __construct(Container $app, $type, $value, $link, $attributes) |
|
| 52 | - { |
|
| 53 | - $this->app = $app; |
|
| 54 | - $this->attributes = (array) $attributes; |
|
| 55 | - $this->type = $type; |
|
| 56 | - $this->value($value); |
|
| 42 | + /** |
|
| 43 | + * Easier arguments order for button fields |
|
| 44 | + * |
|
| 45 | + * @param Container $app The Container |
|
| 46 | + * @param string $type button/submit/reset/etc |
|
| 47 | + * @param string $value The text of the button |
|
| 48 | + * @param string $link Its link |
|
| 49 | + * @param array $attributes Its attributes |
|
| 50 | + */ |
|
| 51 | + public function __construct(Container $app, $type, $value, $link, $attributes) |
|
| 52 | + { |
|
| 53 | + $this->app = $app; |
|
| 54 | + $this->attributes = (array) $attributes; |
|
| 55 | + $this->type = $type; |
|
| 56 | + $this->value($value); |
|
| 57 | 57 | |
| 58 | - // Set correct element for the various button patterns |
|
| 59 | - switch ($type) { |
|
| 60 | - case 'button': |
|
| 61 | - $this->element = 'button'; |
|
| 62 | - $this->isSelfClosing = false; |
|
| 63 | - break; |
|
| 64 | - case 'link': |
|
| 65 | - $this->type = null; |
|
| 66 | - $this->element = 'a'; |
|
| 67 | - $this->attributes['href'] = $link; |
|
| 68 | - $this->isSelfClosing = false; |
|
| 69 | - break; |
|
| 70 | - } |
|
| 71 | - } |
|
| 58 | + // Set correct element for the various button patterns |
|
| 59 | + switch ($type) { |
|
| 60 | + case 'button': |
|
| 61 | + $this->element = 'button'; |
|
| 62 | + $this->isSelfClosing = false; |
|
| 63 | + break; |
|
| 64 | + case 'link': |
|
| 65 | + $this->type = null; |
|
| 66 | + $this->element = 'a'; |
|
| 67 | + $this->attributes['href'] = $link; |
|
| 68 | + $this->isSelfClosing = false; |
|
| 69 | + break; |
|
| 70 | + } |
|
| 71 | + } |
|
| 72 | 72 | |
| 73 | - //////////////////////////////////////////////////////////////////// |
|
| 74 | - ////////////////////////// FIELD METHODS /////////////////////////// |
|
| 75 | - //////////////////////////////////////////////////////////////////// |
|
| 73 | + //////////////////////////////////////////////////////////////////// |
|
| 74 | + ////////////////////////// FIELD METHODS /////////////////////////// |
|
| 75 | + //////////////////////////////////////////////////////////////////// |
|
| 76 | 76 | |
| 77 | - /** |
|
| 78 | - * Check if the field is a button |
|
| 79 | - * |
|
| 80 | - * @return boolean |
|
| 81 | - */ |
|
| 82 | - public function isButton() |
|
| 83 | - { |
|
| 84 | - return true; |
|
| 85 | - } |
|
| 77 | + /** |
|
| 78 | + * Check if the field is a button |
|
| 79 | + * |
|
| 80 | + * @return boolean |
|
| 81 | + */ |
|
| 82 | + public function isButton() |
|
| 83 | + { |
|
| 84 | + return true; |
|
| 85 | + } |
|
| 86 | 86 | |
| 87 | - /** |
|
| 88 | - * Prepend an icon to the button |
|
| 89 | - * |
|
| 90 | - * @param string $icon |
|
| 91 | - * @param array $attributes |
|
| 92 | - * |
|
| 93 | - * @return self |
|
| 94 | - */ |
|
| 95 | - public function icon($icon, $attributes = array()) |
|
| 96 | - { |
|
| 97 | - $icon = $this->app['former.framework']->createIcon($icon, $attributes); |
|
| 98 | - $this->value = $icon.' '.$this->value; |
|
| 87 | + /** |
|
| 88 | + * Prepend an icon to the button |
|
| 89 | + * |
|
| 90 | + * @param string $icon |
|
| 91 | + * @param array $attributes |
|
| 92 | + * |
|
| 93 | + * @return self |
|
| 94 | + */ |
|
| 95 | + public function icon($icon, $attributes = array()) |
|
| 96 | + { |
|
| 97 | + $icon = $this->app['former.framework']->createIcon($icon, $attributes); |
|
| 98 | + $this->value = $icon.' '.$this->value; |
|
| 99 | 99 | |
| 100 | - return $this; |
|
| 101 | - } |
|
| 100 | + return $this; |
|
| 101 | + } |
|
| 102 | 102 | |
| 103 | - /** |
|
| 104 | - * Hijack Former's Object model value method |
|
| 105 | - * |
|
| 106 | - * @param string $value The new button text |
|
| 107 | - */ |
|
| 108 | - public function value($value) |
|
| 109 | - { |
|
| 110 | - $this->value = Helpers::translate($value); |
|
| 103 | + /** |
|
| 104 | + * Hijack Former's Object model value method |
|
| 105 | + * |
|
| 106 | + * @param string $value The new button text |
|
| 107 | + */ |
|
| 108 | + public function value($value) |
|
| 109 | + { |
|
| 110 | + $this->value = Helpers::translate($value); |
|
| 111 | 111 | |
| 112 | - return $this; |
|
| 113 | - } |
|
| 112 | + return $this; |
|
| 113 | + } |
|
| 114 | 114 | } |
@@ -8,28 +8,28 @@ |
||
| 8 | 8 | */ |
| 9 | 9 | class Checkbox extends Checkable |
| 10 | 10 | { |
| 11 | - /** |
|
| 12 | - * The current checkable type |
|
| 13 | - * |
|
| 14 | - * @var string |
|
| 15 | - */ |
|
| 16 | - protected $checkable = 'checkbox'; |
|
| 11 | + /** |
|
| 12 | + * The current checkable type |
|
| 13 | + * |
|
| 14 | + * @var string |
|
| 15 | + */ |
|
| 16 | + protected $checkable = 'checkbox'; |
|
| 17 | 17 | |
| 18 | - //////////////////////////////////////////////////////////////////// |
|
| 19 | - ////////////////////////// FIELD METHODS /////////////////////////// |
|
| 20 | - //////////////////////////////////////////////////////////////////// |
|
| 18 | + //////////////////////////////////////////////////////////////////// |
|
| 19 | + ////////////////////////// FIELD METHODS /////////////////////////// |
|
| 20 | + //////////////////////////////////////////////////////////////////// |
|
| 21 | 21 | |
| 22 | - /** |
|
| 23 | - * Create a serie of checkboxes |
|
| 24 | - */ |
|
| 25 | - public function checkboxes() |
|
| 26 | - { |
|
| 27 | - if ($this->isGrouped()) { |
|
| 28 | - // Remove any possible items added by the Populator. |
|
| 29 | - $this->items = array(); |
|
| 30 | - } |
|
| 31 | - $this->items(func_get_args()); |
|
| 22 | + /** |
|
| 23 | + * Create a serie of checkboxes |
|
| 24 | + */ |
|
| 25 | + public function checkboxes() |
|
| 26 | + { |
|
| 27 | + if ($this->isGrouped()) { |
|
| 28 | + // Remove any possible items added by the Populator. |
|
| 29 | + $this->items = array(); |
|
| 30 | + } |
|
| 31 | + $this->items(func_get_args()); |
|
| 32 | 32 | |
| 33 | - return $this; |
|
| 34 | - } |
|
| 33 | + return $this; |
|
| 34 | + } |
|
| 35 | 35 | } |
@@ -8,24 +8,24 @@ |
||
| 8 | 8 | */ |
| 9 | 9 | class Radio extends Checkable |
| 10 | 10 | { |
| 11 | - /** |
|
| 12 | - * The current checkable type |
|
| 13 | - * |
|
| 14 | - * @var string |
|
| 15 | - */ |
|
| 16 | - protected $checkable = 'radio'; |
|
| 11 | + /** |
|
| 12 | + * The current checkable type |
|
| 13 | + * |
|
| 14 | + * @var string |
|
| 15 | + */ |
|
| 16 | + protected $checkable = 'radio'; |
|
| 17 | 17 | |
| 18 | - //////////////////////////////////////////////////////////////////// |
|
| 19 | - ////////////////////////// FIELD METHODS /////////////////////////// |
|
| 20 | - //////////////////////////////////////////////////////////////////// |
|
| 18 | + //////////////////////////////////////////////////////////////////// |
|
| 19 | + ////////////////////////// FIELD METHODS /////////////////////////// |
|
| 20 | + //////////////////////////////////////////////////////////////////// |
|
| 21 | 21 | |
| 22 | - /** |
|
| 23 | - * Create a serie of radios |
|
| 24 | - */ |
|
| 25 | - public function radios() |
|
| 26 | - { |
|
| 27 | - $this->items(func_get_args()); |
|
| 22 | + /** |
|
| 23 | + * Create a serie of radios |
|
| 24 | + */ |
|
| 25 | + public function radios() |
|
| 26 | + { |
|
| 27 | + $this->items(func_get_args()); |
|
| 28 | 28 | |
| 29 | - return $this; |
|
| 30 | - } |
|
| 29 | + return $this; |
|
| 30 | + } |
|
| 31 | 31 | } |
@@ -8,20 +8,20 @@ |
||
| 8 | 8 | */ |
| 9 | 9 | class Plaintext extends Field |
| 10 | 10 | { |
| 11 | - //////////////////////////////////////////////////////////////////// |
|
| 12 | - /////////////////////////// CORE METHODS /////////////////////////// |
|
| 13 | - //////////////////////////////////////////////////////////////////// |
|
| 11 | + //////////////////////////////////////////////////////////////////// |
|
| 12 | + /////////////////////////// CORE METHODS /////////////////////////// |
|
| 13 | + //////////////////////////////////////////////////////////////////// |
|
| 14 | 14 | |
| 15 | - /** |
|
| 16 | - * Prints out the current tag |
|
| 17 | - * |
|
| 18 | - * @return string A plain text tag |
|
| 19 | - */ |
|
| 20 | - public function render() |
|
| 21 | - { |
|
| 22 | - $this->addClass($this->app['former.framework']->getPlainTextClasses()); |
|
| 23 | - $this->setId(); |
|
| 15 | + /** |
|
| 16 | + * Prints out the current tag |
|
| 17 | + * |
|
| 18 | + * @return string A plain text tag |
|
| 19 | + */ |
|
| 20 | + public function render() |
|
| 21 | + { |
|
| 22 | + $this->addClass($this->app['former.framework']->getPlainTextClasses()); |
|
| 23 | + $this->setId(); |
|
| 24 | 24 | |
| 25 | - return $this->app['former.framework']->createPlainTextField($this); |
|
| 26 | - } |
|
| 25 | + return $this->app['former.framework']->createPlainTextField($this); |
|
| 26 | + } |
|
| 27 | 27 | } |