Complex classes like FormBuilder often do a lot of different things. To break such a class down, we need to identify a cohesive component within that class. A common approach to find such a component is to look for fields/methods that share the same prefixes, or suffixes. You can also have a look at the cohesion graph to spot any un-connected, or weakly-connected components.
Once you have determined the fields that belong together, you can apply the Extract Class refactoring. If the component makes sense as a sub-class, Extract Subclass is also a candidate, and is often faster.
While breaking up the class, it is a good idea to analyze how other classes use FormBuilder, and based on these observations, apply Extract Interface, too.
| 1 | <?php namespace Arcanedev\LaravelHtml; |
||
| 21 | class FormBuilder extends Builder implements FormBuilderContract |
||
| 22 | { |
||
| 23 | /* ----------------------------------------------------------------- |
||
| 24 | | Properties |
||
| 25 | | ----------------------------------------------------------------- |
||
| 26 | */ |
||
| 27 | |||
| 28 | /** |
||
| 29 | * The HTML builder instance. |
||
| 30 | * |
||
| 31 | * @var \Arcanedev\LaravelHtml\Contracts\HtmlBuilder |
||
| 32 | */ |
||
| 33 | protected $html; |
||
| 34 | |||
| 35 | /** |
||
| 36 | * The URL generator instance. |
||
| 37 | * |
||
| 38 | * @var \Illuminate\Contracts\Routing\UrlGenerator |
||
| 39 | */ |
||
| 40 | protected $url; |
||
| 41 | |||
| 42 | /** |
||
| 43 | * The CSRF token used by the form builder. |
||
| 44 | * |
||
| 45 | * @var string |
||
| 46 | */ |
||
| 47 | protected $csrfToken; |
||
| 48 | |||
| 49 | /** |
||
| 50 | * The session store implementation. |
||
| 51 | * |
||
| 52 | * @var \Illuminate\Contracts\Session\Session|\Illuminate\Session\Store |
||
| 53 | */ |
||
| 54 | protected $session; |
||
| 55 | |||
| 56 | /** |
||
| 57 | * The current model instance for the form. |
||
| 58 | * |
||
| 59 | * @var \Illuminate\Database\Eloquent\Model|null |
||
| 60 | */ |
||
| 61 | protected $model; |
||
| 62 | |||
| 63 | /** |
||
| 64 | * An array of label names we've created. |
||
| 65 | * |
||
| 66 | * @var array |
||
| 67 | */ |
||
| 68 | protected $labels = []; |
||
| 69 | |||
| 70 | /** |
||
| 71 | * The reserved form open attributes. |
||
| 72 | * |
||
| 73 | * @var array |
||
| 74 | */ |
||
| 75 | protected $reserved = ['method', 'url', 'route', 'action', 'files']; |
||
| 76 | |||
| 77 | /** |
||
| 78 | * The form methods that should be spoofed, in uppercase. |
||
| 79 | * |
||
| 80 | * @var array |
||
| 81 | */ |
||
| 82 | protected $spoofedMethods = ['DELETE', 'PATCH', 'PUT']; |
||
| 83 | |||
| 84 | /** |
||
| 85 | * The types of inputs to not fill values on by default. |
||
| 86 | * |
||
| 87 | * @var array |
||
| 88 | */ |
||
| 89 | protected $skipValueTypes = ['file', 'password', 'checkbox', 'radio']; |
||
| 90 | |||
| 91 | /* ----------------------------------------------------------------- |
||
| 92 | | Constructor |
||
| 93 | | ----------------------------------------------------------------- |
||
| 94 | */ |
||
| 95 | |||
| 96 | /** |
||
| 97 | * Create a new form builder instance. |
||
| 98 | * |
||
| 99 | * @param \Arcanedev\LaravelHtml\Contracts\HtmlBuilder $html |
||
| 100 | * @param \Illuminate\Contracts\Routing\UrlGenerator $url |
||
| 101 | * @param \Illuminate\Contracts\Session\Session $session |
||
| 102 | */ |
||
| 103 | 321 | public function __construct(Contracts\HtmlBuilder $html, UrlGenerator $url, Session $session) |
|
| 104 | { |
||
| 105 | 321 | $this->url = $url; |
|
| 106 | 321 | $this->html = $html; |
|
| 107 | 321 | $this->csrfToken = $session->token(); |
|
| 108 | |||
| 109 | 321 | $this->setSessionStore($session); |
|
| 110 | 321 | } |
|
| 111 | |||
| 112 | /* ----------------------------------------------------------------- |
||
| 113 | | Getters & Setters |
||
| 114 | | ----------------------------------------------------------------- |
||
| 115 | */ |
||
| 116 | |||
| 117 | /** |
||
| 118 | * Get the session store implementation. |
||
| 119 | * |
||
| 120 | * @return \Illuminate\Contracts\Session\Session |
||
| 121 | */ |
||
| 122 | 3 | public function getSessionStore() |
|
| 123 | { |
||
| 124 | 3 | return $this->session; |
|
| 125 | } |
||
| 126 | |||
| 127 | /** |
||
| 128 | * Set the session store implementation. |
||
| 129 | * |
||
| 130 | * @param \Illuminate\Contracts\Session\Session $session |
||
| 131 | * |
||
| 132 | * @return self |
||
| 133 | */ |
||
| 134 | 321 | public function setSessionStore(Session $session) |
|
| 135 | { |
||
| 136 | 321 | $this->session = $session; |
|
| 137 | |||
| 138 | 321 | return $this; |
|
| 139 | } |
||
| 140 | |||
| 141 | /** |
||
| 142 | * Set the model instance on the form builder. |
||
| 143 | * |
||
| 144 | * @param \Illuminate\Database\Eloquent\Model|null $model |
||
| 145 | * |
||
| 146 | * @return self |
||
| 147 | */ |
||
| 148 | 36 | public function setModel($model) |
|
| 149 | { |
||
| 150 | 36 | $this->model = $model; |
|
| 151 | |||
| 152 | 36 | return $this; |
|
| 153 | } |
||
| 154 | |||
| 155 | /** |
||
| 156 | * Get the model instance on the form builder. |
||
| 157 | * |
||
| 158 | * @return \Illuminate\Database\Eloquent\Model |
||
| 159 | */ |
||
| 160 | 138 | public function getModel() |
|
| 161 | { |
||
| 162 | 138 | return $this->model; |
|
| 163 | } |
||
| 164 | |||
| 165 | /** |
||
| 166 | * Get the ID attribute for a field name. |
||
| 167 | * |
||
| 168 | * @param string $name |
||
| 169 | * @param array $attributes |
||
| 170 | * |
||
| 171 | * @return string |
||
| 172 | */ |
||
| 173 | 249 | public function getIdAttribute($name, array $attributes) |
|
| 174 | { |
||
| 175 | 249 | if (array_key_exists('id', $attributes)) |
|
| 176 | 21 | return $attributes['id']; |
|
| 177 | |||
| 178 | 237 | if (in_array($name, $this->labels)) |
|
| 179 | 6 | return $name; |
|
| 180 | |||
| 181 | 231 | return null; |
|
| 182 | } |
||
| 183 | |||
| 184 | /** |
||
| 185 | * Get the value that should be assigned to the field. |
||
| 186 | * |
||
| 187 | * @param string $name |
||
| 188 | * @param mixed $value |
||
| 189 | * |
||
| 190 | * @return mixed |
||
| 191 | */ |
||
| 192 | 234 | public function getValueAttribute($name, $value = null) |
|
| 193 | { |
||
| 194 | 234 | if (is_null($name)) |
|
| 195 | 6 | return $value; |
|
| 196 | |||
| 197 | 228 | if ( ! is_null($this->old($name)) && $name !== '_method') |
|
| 198 | 15 | return $this->old($name); |
|
| 199 | |||
| 200 | 222 | if ( ! is_null($value)) |
|
| 201 | 129 | return $value; |
|
| 202 | |||
| 203 | 123 | return $this->getModelValueAttribute($name); |
|
| 204 | } |
||
| 205 | |||
| 206 | /** |
||
| 207 | * Get the model value that should be assigned to the field. |
||
| 208 | * |
||
| 209 | * @param string $name |
||
| 210 | * @param \Illuminate\Database\Eloquent\Model $model |
||
| 211 | * |
||
| 212 | * @return mixed |
||
| 213 | */ |
||
| 214 | 132 | private function getModelValueAttribute($name, $model = null) |
|
| 215 | { |
||
| 216 | 132 | $model = $model ?: $this->getModel(); |
|
| 217 | |||
| 218 | 132 | $key = self::transformKey($name); |
|
| 219 | |||
| 220 | 132 | if (strpos($key, '.') !== false) { |
|
| 221 | 15 | $keys = explode('.', $key, 2); |
|
| 222 | |||
| 223 | 15 | return $this->getModelValueAttribute( |
|
| 224 | 15 | $keys[1], |
|
| 225 | 15 | $this->getModelValueAttribute($keys[0], $model) |
|
| 226 | ); |
||
| 227 | } |
||
| 228 | |||
| 229 | 132 | return method_exists($model, 'getFormValue') |
|
| 230 | 3 | ? $model->getFormValue($key) |
|
| 231 | 132 | : data_get($model, $key); |
|
| 232 | } |
||
| 233 | |||
| 234 | /** |
||
| 235 | * Get a value from the session's old input. |
||
| 236 | * |
||
| 237 | * @param string $name |
||
| 238 | * |
||
| 239 | * @return mixed |
||
| 240 | */ |
||
| 241 | 237 | public function old($name) |
|
| 242 | { |
||
| 243 | 237 | return ! is_null($this->session) |
|
| 244 | 237 | ? $this->session->getOldInput(self::transformKey($name)) |
|
| 245 | 237 | : null; |
|
| 246 | } |
||
| 247 | |||
| 248 | /** |
||
| 249 | * Transform key from array to dot syntax. |
||
| 250 | * |
||
| 251 | * @param string $key |
||
| 252 | * |
||
| 253 | * @return string |
||
| 254 | */ |
||
| 255 | 237 | private static function transformKey($key) |
|
| 256 | { |
||
| 257 | 237 | return str_replace( |
|
| 258 | 237 | ['.', '[]', '[', ']'], |
|
| 259 | 237 | ['_', '', '.', ''], |
|
| 260 | 158 | $key |
|
| 261 | ); |
||
| 262 | } |
||
| 263 | |||
| 264 | /** |
||
| 265 | * Determine if the old input is empty. |
||
| 266 | * |
||
| 267 | * @return bool |
||
| 268 | */ |
||
| 269 | 12 | public function oldInputIsEmpty() |
|
| 270 | { |
||
| 271 | 12 | return ! is_null($this->session) |
|
| 272 | 12 | && (count($this->session->getOldInput()) === 0); |
|
| 273 | } |
||
| 274 | |||
| 275 | /* ----------------------------------------------------------------- |
||
| 276 | | Main Methods |
||
| 277 | | ----------------------------------------------------------------- |
||
| 278 | */ |
||
| 279 | |||
| 280 | /** |
||
| 281 | * Open up a new HTML form. |
||
| 282 | * |
||
| 283 | * @param array $attributes |
||
| 284 | * |
||
| 285 | * @return \Illuminate\Support\HtmlString |
||
| 286 | */ |
||
| 287 | 57 | public function open(array $attributes = []) |
|
| 288 | { |
||
| 289 | 57 | $method = strtoupper(Arr::pull($attributes, 'method', 'POST')); |
|
| 290 | |||
| 291 | 57 | return Form::make() |
|
| 292 | 57 | ->method($method !== 'GET' ? 'POST' : $method) |
|
| 293 | 57 | ->action($this->getAction($attributes)) |
|
| 294 | 57 | ->attributes(array_merge( |
|
| 295 | 57 | ['accept-charset' => 'UTF-8'], |
|
| 296 | 57 | Arr::except($attributes, $this->reserved) |
|
| 297 | )) |
||
| 298 | ->if(Arr::pull($attributes, 'files', false), function (Form $form) { |
||
| 299 | 6 | return $form->acceptsFiles(); |
|
| 300 | 57 | }) |
|
| 301 | ->if(in_array($method, $this->spoofedMethods), function (Form $form) use ($method) { |
||
| 302 | 6 | return $form->addChild($this->hidden('_method', $method)); |
|
| 303 | 57 | }) |
|
| 304 | ->if($method !== 'GET', function (Form $form) { |
||
| 305 | 30 | return $form->addChild($this->token()); |
|
| 306 | 57 | }) |
|
| 307 | 57 | ->open(); |
|
| 308 | } |
||
| 309 | |||
| 310 | /** |
||
| 311 | * Create a new model based form builder. |
||
| 312 | * |
||
| 313 | * @param mixed $model |
||
| 314 | * @param array $attributes |
||
| 315 | * |
||
| 316 | * @return \Illuminate\Support\HtmlString |
||
| 317 | */ |
||
| 318 | 15 | public function model($model, array $attributes = []) |
|
| 319 | { |
||
| 320 | 15 | return $this->setModel($model)->open($attributes); |
|
| 321 | } |
||
| 322 | |||
| 323 | /** |
||
| 324 | * Close the current form. |
||
| 325 | * |
||
| 326 | * @return \Illuminate\Support\HtmlString |
||
| 327 | */ |
||
| 328 | 6 | public function close() |
|
| 335 | |||
| 336 | /** |
||
| 337 | * Generate a hidden field with the current CSRF token. |
||
| 338 | * |
||
| 339 | * @return \Illuminate\Support\HtmlString |
||
| 340 | */ |
||
| 341 | 30 | public function token() |
|
| 348 | |||
| 349 | /** |
||
| 350 | * Create a form label element. |
||
| 351 | * |
||
| 352 | * @param string $name |
||
| 353 | * @param string|mixed $value |
||
| 354 | * @param array $attributes |
||
| 355 | * @param bool $escaped |
||
| 356 | * |
||
| 357 | * @return \Illuminate\Support\HtmlString |
||
| 358 | */ |
||
| 359 | 15 | public function label($name, $value = null, array $attributes = [], $escaped = true) |
|
| 371 | |||
| 372 | /** |
||
| 373 | * Create a form input field. |
||
| 374 | * |
||
| 375 | * @param string $type |
||
| 376 | * @param string $name |
||
| 377 | * @param string|mixed $value |
||
| 378 | * @param array $attributes |
||
| 379 | * |
||
| 380 | * @return \Illuminate\Support\HtmlString |
||
| 381 | */ |
||
| 382 | 186 | public function input($type, $name, $value = null, array $attributes = []) |
|
| 383 | { |
||
| 384 | 186 | if ( ! in_array($type, $this->skipValueTypes)) |
|
| 395 | |||
| 396 | /** |
||
| 397 | * Create a text input field. |
||
| 398 | * |
||
| 399 | * @param string $name |
||
| 400 | * @param string|mixed $value |
||
| 401 | * @param array $attributes |
||
| 402 | * |
||
| 403 | * @return \Illuminate\Support\HtmlString |
||
| 404 | */ |
||
| 405 | 21 | public function text($name, $value = null, array $attributes = []) |
|
| 409 | |||
| 410 | /** |
||
| 411 | * Create a password input field. |
||
| 412 | * |
||
| 413 | * @param string $name |
||
| 414 | * @param array $attributes |
||
| 415 | * |
||
| 416 | * @return \Illuminate\Support\HtmlString |
||
| 417 | */ |
||
| 418 | 9 | public function password($name, array $attributes = []) |
|
| 422 | |||
| 423 | /** |
||
| 424 | * Create a hidden input field. |
||
| 425 | * |
||
| 426 | * @param string $name |
||
| 427 | * @param string|mixed $value |
||
| 428 | * @param array $attributes |
||
| 429 | * |
||
| 430 | * @return \Illuminate\Support\HtmlString |
||
| 431 | */ |
||
| 432 | 39 | public function hidden($name, $value = null, array $attributes = []) |
|
| 436 | |||
| 437 | /** |
||
| 438 | * Create an e-mail input field. |
||
| 439 | * |
||
| 440 | * @param string $name |
||
| 441 | * @param string|mixed $value |
||
| 442 | * @param array $attributes |
||
| 443 | * |
||
| 444 | * @return \Illuminate\Support\HtmlString |
||
| 445 | */ |
||
| 446 | 9 | public function email($name, $value = null, array $attributes = []) |
|
| 450 | |||
| 451 | /** |
||
| 452 | * Create a tel input field. |
||
| 453 | * |
||
| 454 | * @param string $name |
||
| 455 | * @param string|mixed $value |
||
| 456 | * @param array $attributes |
||
| 457 | * |
||
| 458 | * @return \Illuminate\Support\HtmlString |
||
| 459 | */ |
||
| 460 | 9 | public function tel($name, $value = null, array $attributes = []) |
|
| 464 | |||
| 465 | /** |
||
| 466 | * Create a number input field. |
||
| 467 | * |
||
| 468 | * @param string $name |
||
| 469 | * @param string|mixed $value |
||
| 470 | * @param array $attributes |
||
| 471 | * |
||
| 472 | * @return \Illuminate\Support\HtmlString |
||
| 473 | */ |
||
| 474 | 9 | public function number($name, $value = null, array $attributes = []) |
|
| 478 | |||
| 479 | /** |
||
| 480 | * Create a date input field. |
||
| 481 | * |
||
| 482 | * @param string $name |
||
| 483 | * @param string $value |
||
| 484 | * @param array $attributes |
||
| 485 | * |
||
| 486 | * @return \Illuminate\Support\HtmlString |
||
| 487 | */ |
||
| 488 | 12 | public function date($name, $value = null, array $attributes = []) |
|
| 495 | |||
| 496 | /** |
||
| 497 | * Create a datetime input field. |
||
| 498 | * |
||
| 499 | * @param string $name |
||
| 500 | * @param string|mixed $value |
||
| 501 | * @param array $attributes |
||
| 502 | * |
||
| 503 | * @return \Illuminate\Support\HtmlString |
||
| 504 | */ |
||
| 505 | 12 | public function datetime($name, $value = null, array $attributes = []) |
|
| 512 | |||
| 513 | /** |
||
| 514 | * Create a datetime-local input field. |
||
| 515 | * |
||
| 516 | * @param string $name |
||
| 517 | * @param string|mixed $value |
||
| 518 | * @param array $attributes |
||
| 519 | * |
||
| 520 | * @return \Illuminate\Support\HtmlString |
||
| 521 | */ |
||
| 522 | 12 | public function datetimeLocal($name, $value = null, array $attributes = []) |
|
| 529 | |||
| 530 | /** |
||
| 531 | * Create a time input field. |
||
| 532 | * |
||
| 533 | * @param string $name |
||
| 534 | * @param string|mixed $value |
||
| 535 | * @param array $attributes |
||
| 536 | * |
||
| 537 | * @return \Illuminate\Support\HtmlString |
||
| 538 | */ |
||
| 539 | 9 | public function time($name, $value = null, array $attributes = []) |
|
| 543 | |||
| 544 | /** |
||
| 545 | * Create a url input field. |
||
| 546 | * |
||
| 547 | * @param string $name |
||
| 548 | * @param string $value |
||
| 549 | * @param array $attributes |
||
| 550 | * |
||
| 551 | * @return \Illuminate\Support\HtmlString |
||
| 552 | */ |
||
| 553 | 6 | public function url($name, $value = null, array $attributes = []) |
|
| 557 | |||
| 558 | /** |
||
| 559 | * Create a file input field. |
||
| 560 | * |
||
| 561 | * @param string $name |
||
| 562 | * @param array $attributes |
||
| 563 | * |
||
| 564 | * @return \Illuminate\Support\HtmlString |
||
| 565 | */ |
||
| 566 | 9 | public function file($name, array $attributes = []) |
|
| 570 | |||
| 571 | /** |
||
| 572 | * Create a textarea input field. |
||
| 573 | * |
||
| 574 | * @param string $name |
||
| 575 | * @param string $value |
||
| 576 | * @param array $attributes |
||
| 577 | * |
||
| 578 | * @return \Illuminate\Support\HtmlString |
||
| 579 | */ |
||
| 580 | 18 | public function textarea($name, $value = null, array $attributes = []) |
|
| 596 | |||
| 597 | /** |
||
| 598 | * Create a select box field. |
||
| 599 | * |
||
| 600 | * @param string $name |
||
| 601 | * @param array|\Illuminate\Support\Collection $list |
||
| 602 | * @param string|bool $selected |
||
| 603 | * @param array $attributes |
||
| 604 | * @param array $optionsAttributes |
||
| 605 | * @param array $optgroupsAttributes |
||
| 606 | * |
||
| 607 | * @return \Illuminate\Support\HtmlString |
||
| 608 | */ |
||
| 609 | 45 | public function select( |
|
| 625 | |||
| 626 | /** |
||
| 627 | * Create a select range field. |
||
| 628 | * |
||
| 629 | * @param string $name |
||
| 630 | * @param string $begin |
||
| 631 | * @param string $end |
||
| 632 | * @param string $selected |
||
| 633 | * @param array $attributes |
||
| 634 | * |
||
| 635 | * @return \Illuminate\Support\HtmlString |
||
| 636 | */ |
||
| 637 | 6 | public function selectRange($name, $begin, $end, $selected = null, array $attributes = []) |
|
| 643 | |||
| 644 | /** |
||
| 645 | * Create a select year field. |
||
| 646 | * |
||
| 647 | * @param string $name |
||
| 648 | * @param string $begin |
||
| 649 | * @param string $end |
||
| 650 | * @param string $selected |
||
| 651 | * @param array $attributes |
||
| 652 | * |
||
| 653 | * @return \Illuminate\Support\HtmlString |
||
| 654 | */ |
||
| 655 | 3 | public function selectYear($name, $begin, $end, $selected = null, array $attributes = []) |
|
| 659 | |||
| 660 | /** |
||
| 661 | * Create a select month field. |
||
| 662 | * |
||
| 663 | * @param string $name |
||
| 664 | * @param string $selected |
||
| 665 | * @param array $attributes |
||
| 666 | * @param string $format |
||
| 667 | * |
||
| 668 | * @return \Illuminate\Support\HtmlString |
||
| 669 | */ |
||
| 670 | 3 | public function selectMonth($name, $selected = null, array $attributes = [], $format = '%B') |
|
| 680 | |||
| 681 | /** |
||
| 682 | * Create a checkbox input field. |
||
| 683 | * |
||
| 684 | * @param string $name |
||
| 685 | * @param mixed $value |
||
| 686 | * @param bool|null $checked |
||
| 687 | * @param array $attributes |
||
| 688 | * |
||
| 689 | * @return \Illuminate\Support\HtmlString |
||
| 690 | */ |
||
| 691 | 12 | public function checkbox($name, $value = 1, $checked = null, array $attributes = []) |
|
| 695 | |||
| 696 | /** |
||
| 697 | * Create a radio button input field. |
||
| 698 | * |
||
| 699 | * @param string $name |
||
| 700 | * @param mixed $value |
||
| 701 | * @param bool $checked |
||
| 702 | * @param array $attributes |
||
| 703 | * |
||
| 704 | * @return \Illuminate\Support\HtmlString |
||
| 705 | */ |
||
| 706 | 6 | public function radio($name, $value = null, $checked = null, array $attributes = []) |
|
| 710 | |||
| 711 | /** |
||
| 712 | * Create a HTML reset input element. |
||
| 713 | * |
||
| 714 | * @param string|mixed $value |
||
| 715 | * @param array $attributes |
||
| 716 | * |
||
| 717 | * @return \Illuminate\Support\HtmlString |
||
| 718 | */ |
||
| 719 | 3 | public function reset($value, array $attributes = []) |
|
| 723 | |||
| 724 | /** |
||
| 725 | * Create a HTML image input element. |
||
| 726 | * |
||
| 727 | * @param string $url |
||
| 728 | * @param string|null $name |
||
| 729 | * @param array $attributes |
||
| 730 | * |
||
| 731 | * @return \Illuminate\Support\HtmlString |
||
| 732 | */ |
||
| 733 | 3 | public function image($url, $name = null, array $attributes = []) |
|
| 739 | |||
| 740 | /** |
||
| 741 | * Create a submit button element. |
||
| 742 | * |
||
| 743 | * @param string|mixed $value |
||
| 744 | * @param array $attributes |
||
| 745 | * |
||
| 746 | * @return \Illuminate\Support\HtmlString |
||
| 747 | */ |
||
| 748 | 3 | public function submit($value = null, array $attributes = []) |
|
| 752 | |||
| 753 | /** |
||
| 754 | * Create a button element. |
||
| 755 | * |
||
| 756 | * @param string|mixed $value |
||
| 757 | * @param array $attributes |
||
| 758 | * |
||
| 759 | * @return \Illuminate\Support\HtmlString |
||
| 760 | */ |
||
| 761 | 3 | public function button($value = null, array $attributes = []) |
|
| 769 | |||
| 770 | /** |
||
| 771 | * Create a color input field. |
||
| 772 | * |
||
| 773 | * @param string $name |
||
| 774 | * @param string|mixed $value |
||
| 775 | * @param array $attributes |
||
| 776 | * |
||
| 777 | * @return \Illuminate\Support\HtmlString |
||
| 778 | */ |
||
| 779 | 9 | public function color($name, $value = null, array $attributes = []) |
|
| 783 | |||
| 784 | /* ----------------------------------------------------------------- |
||
| 785 | | Other Methods |
||
| 786 | | ----------------------------------------------------------------- |
||
| 787 | */ |
||
| 788 | |||
| 789 | /** |
||
| 790 | * Create a checkable input field. |
||
| 791 | * |
||
| 792 | * @param string $type |
||
| 793 | * @param string $name |
||
| 794 | * @param mixed $value |
||
| 795 | * @param bool|null $checked |
||
| 796 | * @param array $attributes |
||
| 797 | * |
||
| 798 | * @return \Illuminate\Support\HtmlString |
||
| 799 | */ |
||
| 800 | 21 | protected function checkable($type, $name, $value, $checked, array $attributes) |
|
| 809 | |||
| 810 | /** |
||
| 811 | * Get the check state for a checkable input. |
||
| 812 | * |
||
| 813 | * @param string $type |
||
| 814 | * @param string $name |
||
| 815 | * @param mixed $value |
||
| 816 | * @param bool|null $checked |
||
| 817 | * |
||
| 818 | * @return bool |
||
| 819 | */ |
||
| 820 | 21 | private function getCheckedState($type, $name, $value, $checked) |
|
| 833 | |||
| 834 | /** |
||
| 835 | * Get the check state for a checkbox input. |
||
| 836 | * |
||
| 837 | * @param string $name |
||
| 838 | * @param mixed $value |
||
| 839 | * @param bool|null $checked |
||
| 840 | * |
||
| 841 | * @return bool |
||
| 842 | */ |
||
| 843 | 12 | private function getCheckboxCheckedState($name, $value, $checked) |
|
| 865 | |||
| 866 | /** |
||
| 867 | * Get the check state for a radio input. |
||
| 868 | * |
||
| 869 | * @param string $name |
||
| 870 | * @param mixed $value |
||
| 871 | * @param bool|null $checked |
||
| 872 | * |
||
| 873 | * @return bool |
||
| 874 | */ |
||
| 875 | 6 | private function getRadioCheckedState($name, $value, $checked) |
|
| 881 | |||
| 882 | /** |
||
| 883 | * Determine if old input or model input exists for a key. |
||
| 884 | * |
||
| 885 | * @param string $name |
||
| 886 | * |
||
| 887 | * @return bool |
||
| 888 | */ |
||
| 889 | 18 | private function missingOldAndModel($name) |
|
| 894 | |||
| 895 | /** |
||
| 896 | * Get the form action from the options. |
||
| 897 | * |
||
| 898 | * @param array $attributes |
||
| 899 | * |
||
| 900 | * @return string |
||
| 901 | */ |
||
| 902 | 57 | private function getAction(array $attributes) |
|
| 915 | |||
| 916 | /** |
||
| 917 | * Get the action for a "url" option. |
||
| 918 | * |
||
| 919 | * @param array|string $attribute |
||
| 920 | * |
||
| 921 | * @return string |
||
| 922 | */ |
||
| 923 | 18 | private function getUrlAction($attribute) |
|
| 929 | |||
| 930 | /** |
||
| 931 | * Get the action for a "route" option. |
||
| 932 | * |
||
| 933 | * @param array|string $attribute |
||
| 934 | * |
||
| 935 | * @return string |
||
| 936 | */ |
||
| 937 | 6 | private function getRouteAction($attribute) |
|
| 943 | |||
| 944 | /** |
||
| 945 | * Get the action for an "action" option. |
||
| 946 | * |
||
| 947 | * @param array|string $attribute |
||
| 948 | * |
||
| 949 | * @return string |
||
| 950 | */ |
||
| 951 | 6 | private function getControllerAction($attribute) |
|
| 957 | } |
||
| 958 |