Complex classes like Form 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 Form, and based on these observations, apply Extract Interface, too.
| 1 | <?php |
||
| 17 | class Form |
||
| 18 | { |
||
| 19 | /** |
||
| 20 | * All fields that are added. |
||
| 21 | * |
||
| 22 | * @var array |
||
| 23 | */ |
||
| 24 | protected $fields = []; |
||
| 25 | |||
| 26 | /** |
||
| 27 | * Model to use. |
||
| 28 | * |
||
| 29 | * @var mixed |
||
| 30 | */ |
||
| 31 | protected $model = []; |
||
| 32 | |||
| 33 | /** |
||
| 34 | * @var EventDispatcher |
||
| 35 | */ |
||
| 36 | protected $eventDispatcher; |
||
| 37 | |||
| 38 | /** |
||
| 39 | * @var FormHelper |
||
| 40 | */ |
||
| 41 | protected $formHelper; |
||
| 42 | |||
| 43 | /** |
||
| 44 | * Form options. |
||
| 45 | * |
||
| 46 | * @var array |
||
| 47 | */ |
||
| 48 | protected $formOptions = [ |
||
| 49 | 'method' => 'GET', |
||
| 50 | 'url' => null, |
||
| 51 | 'attr' => [], |
||
| 52 | ]; |
||
| 53 | |||
| 54 | /** |
||
| 55 | * Form specific configuration. |
||
| 56 | * |
||
| 57 | * @var array |
||
| 58 | */ |
||
| 59 | protected $formConfig = []; |
||
| 60 | |||
| 61 | /** |
||
| 62 | * Additional data which can be used to build fields. |
||
| 63 | * |
||
| 64 | * @var array |
||
| 65 | */ |
||
| 66 | protected $data = []; |
||
| 67 | |||
| 68 | /** |
||
| 69 | * Wether errors for each field should be shown when calling form($form) or form_rest($form). |
||
| 70 | * |
||
| 71 | * @var bool |
||
| 72 | */ |
||
| 73 | protected $showFieldErrors = true; |
||
| 74 | |||
| 75 | /** |
||
| 76 | * Enable html5 validation. |
||
| 77 | * |
||
| 78 | * @var bool |
||
| 79 | */ |
||
| 80 | protected $clientValidationEnabled = true; |
||
| 81 | |||
| 82 | /** |
||
| 83 | * Name of the parent form if any. |
||
| 84 | * |
||
| 85 | * @var string|null |
||
| 86 | */ |
||
| 87 | protected $name = null; |
||
| 88 | |||
| 89 | /** |
||
| 90 | * @var FormBuilder |
||
| 91 | */ |
||
| 92 | protected $formBuilder; |
||
| 93 | |||
| 94 | /** |
||
| 95 | * @var ValidatorFactory |
||
| 96 | */ |
||
| 97 | protected $validatorFactory; |
||
| 98 | |||
| 99 | /** |
||
| 100 | * @var Validator |
||
| 101 | */ |
||
| 102 | protected $validator = null; |
||
| 103 | |||
| 104 | /** |
||
| 105 | * @var Request |
||
| 106 | */ |
||
| 107 | protected $request; |
||
| 108 | |||
| 109 | /** |
||
| 110 | * List of fields to not render. |
||
| 111 | * |
||
| 112 | * @var array |
||
| 113 | **/ |
||
| 114 | protected $exclude = []; |
||
| 115 | |||
| 116 | /** |
||
| 117 | * Wether the form is beign rebuild. |
||
| 118 | * |
||
| 119 | * @var bool |
||
| 120 | */ |
||
| 121 | protected $rebuilding = false; |
||
| 122 | |||
| 123 | /** |
||
| 124 | * @var string |
||
| 125 | */ |
||
| 126 | protected $templatePrefix; |
||
| 127 | |||
| 128 | /** |
||
| 129 | * @var string |
||
| 130 | */ |
||
| 131 | protected $languageName; |
||
| 132 | |||
| 133 | /** |
||
| 134 | * @var string |
||
| 135 | */ |
||
| 136 | protected $translationTemplate; |
||
| 137 | |||
| 138 | /** |
||
| 139 | * To filter and mutate request values or not. |
||
| 140 | * |
||
| 141 | * @var bool |
||
| 142 | */ |
||
| 143 | protected $lockFiltering = false; |
||
| 144 | |||
| 145 | /** |
||
| 146 | * Define the error bag name for the form. |
||
| 147 | * |
||
| 148 | * @var string |
||
| 149 | */ |
||
| 150 | protected $errorBag = 'default'; |
||
| 151 | |||
| 152 | /** |
||
| 153 | * Build the form. |
||
| 154 | * |
||
| 155 | * @return mixed |
||
| 156 | */ |
||
| 157 | 3 | public function buildForm() |
|
| 160 | |||
| 161 | /** |
||
| 162 | * Rebuild the form from scratch. |
||
| 163 | * |
||
| 164 | * @return $this |
||
| 165 | */ |
||
| 166 | 19 | public function rebuildForm() |
|
| 184 | |||
| 185 | /** |
||
| 186 | * Create the FormField object. |
||
| 187 | * |
||
| 188 | * @param string $name |
||
| 189 | * @param string $type |
||
| 190 | * @param array $options |
||
| 191 | * @return FormField |
||
| 192 | */ |
||
| 193 | 65 | protected function makeField($name, $type = 'text', array $options = []) |
|
| 207 | |||
| 208 | /** |
||
| 209 | * Create a new field and add it to the form. |
||
| 210 | * |
||
| 211 | * @param string $name |
||
| 212 | * @param string $type |
||
| 213 | * @param array $options |
||
| 214 | * @param bool $modify |
||
| 215 | * @return $this |
||
| 216 | */ |
||
| 217 | 67 | public function add($name, $type = 'text', array $options = [], $modify = false) |
|
| 229 | |||
| 230 | /** |
||
| 231 | * Add a FormField to the form's fields. |
||
| 232 | * |
||
| 233 | * @param FormField $field |
||
| 234 | * @return $this |
||
| 235 | */ |
||
| 236 | 61 | protected function addField(FormField $field, $modify = false) |
|
| 251 | |||
| 252 | /** |
||
| 253 | * Add field before another field. |
||
| 254 | * |
||
| 255 | * @param string $name Name of the field before which new field is added. |
||
| 256 | * @param string $fieldName Field name which will be added. |
||
| 257 | * @param string $type |
||
| 258 | * @param array $options |
||
| 259 | * @param bool $modify |
||
| 260 | * @return $this |
||
| 261 | */ |
||
| 262 | 1 | public function addBefore($name, $fieldName, $type = 'text', $options = [], $modify = false) |
|
| 277 | |||
| 278 | /** |
||
| 279 | * Add field before another field. |
||
| 280 | * |
||
| 281 | * @param string $name Name of the field after which new field is added. |
||
| 282 | * @param string $fieldName Field name which will be added. |
||
| 283 | * @param string $type |
||
| 284 | * @param array $options |
||
| 285 | * @param bool $modify |
||
| 286 | * @return $this |
||
| 287 | */ |
||
| 288 | 1 | public function addAfter($name, $fieldName, $type = 'text', $options = [], $modify = false) |
|
| 303 | |||
| 304 | /** |
||
| 305 | * Take another form and add it's fields directly to this form. |
||
| 306 | * |
||
| 307 | * @param mixed $class Form to merge. |
||
| 308 | * @param array $options |
||
| 309 | * @param boolean $modify |
||
| 310 | * @return $this |
||
| 311 | */ |
||
| 312 | 1 | public function compose($class, array $options = [], $modify = false) |
|
| 340 | |||
| 341 | /** |
||
| 342 | * Remove field with specified name from the form. |
||
| 343 | * |
||
| 344 | * @param string|string[] $names |
||
| 345 | * @return $this |
||
| 346 | */ |
||
| 347 | 2 | public function remove($names) |
|
| 357 | |||
| 358 | /** |
||
| 359 | * Modify existing field. If it doesn't exist, it is added to form. |
||
| 360 | * |
||
| 361 | * @param string $name |
||
| 362 | * @param string $type |
||
| 363 | * @param array $options |
||
| 364 | * @param bool $overwriteOptions |
||
| 365 | * @return Form |
||
| 366 | */ |
||
| 367 | 1 | public function modify($name, $type = 'text', array $options = [], $overwriteOptions = false) |
|
| 379 | |||
| 380 | /** |
||
| 381 | * Render full form. |
||
| 382 | * |
||
| 383 | * @param array $options |
||
| 384 | * @param bool $showStart |
||
| 385 | * @param bool $showFields |
||
| 386 | * @param bool $showEnd |
||
| 387 | * @return string |
||
| 388 | */ |
||
| 389 | 7 | public function renderForm(array $options = [], $showStart = true, $showFields = true, $showEnd = true) |
|
| 393 | |||
| 394 | /** |
||
| 395 | * Render rest of the form. |
||
| 396 | * |
||
| 397 | * @param bool $showFormEnd |
||
| 398 | * @param bool $showFields |
||
| 399 | * @return string |
||
| 400 | */ |
||
| 401 | 1 | public function renderRest($showFormEnd = true, $showFields = true) |
|
| 407 | |||
| 408 | /** |
||
| 409 | * Renders the rest of the form up until the specified field name. |
||
| 410 | * |
||
| 411 | * @param string $field_name |
||
| 412 | * @param bool $showFormEnd |
||
| 413 | * @param bool $showFields |
||
| 414 | * @return string |
||
| 415 | */ |
||
| 416 | 2 | public function renderUntil($field_name, $showFormEnd = true, $showFields = true) |
|
| 436 | |||
| 437 | /** |
||
| 438 | * Get single field instance from form object. |
||
| 439 | * |
||
| 440 | * @param string $name |
||
| 441 | * @return FormField |
||
| 442 | */ |
||
| 443 | 35 | public function getField($name) |
|
| 451 | |||
| 452 | 101 | public function getErrorBag() |
|
| 456 | |||
| 457 | /** |
||
| 458 | * Check if form has field. |
||
| 459 | * |
||
| 460 | * @param string $name |
||
| 461 | * @return bool |
||
| 462 | */ |
||
| 463 | 61 | public function has($name) |
|
| 467 | |||
| 468 | /** |
||
| 469 | * Get all form options. |
||
| 470 | * |
||
| 471 | * @return array |
||
| 472 | */ |
||
| 473 | 2 | public function getFormOptions() |
|
| 477 | |||
| 478 | /** |
||
| 479 | * Get single form option. |
||
| 480 | * |
||
| 481 | * @param string $option |
||
| 482 | * @param mixed|null $default |
||
| 483 | * @return mixed |
||
| 484 | */ |
||
| 485 | 129 | public function getFormOption($option, $default = null) |
|
| 489 | |||
| 490 | /** |
||
| 491 | * Set single form option on form. |
||
| 492 | * |
||
| 493 | * @param string $option |
||
| 494 | * @param mixed $value |
||
| 495 | * |
||
| 496 | * @return $this |
||
| 497 | */ |
||
| 498 | 2 | public function setFormOption($option, $value) |
|
| 504 | |||
| 505 | /** |
||
| 506 | * Get the passed config key using the custom |
||
| 507 | * form config, if any. |
||
| 508 | * |
||
| 509 | * @param string $key |
||
| 510 | * @param mixed $default |
||
| 511 | * |
||
| 512 | * @return mixed |
||
| 513 | */ |
||
| 514 | 103 | public function getConfig($key = null, $default = null) |
|
| 518 | |||
| 519 | /** |
||
| 520 | * Set form options. |
||
| 521 | * |
||
| 522 | * @param array $formOptions |
||
| 523 | * @return $this |
||
| 524 | */ |
||
| 525 | 129 | public function setFormOptions(array $formOptions) |
|
| 539 | |||
| 540 | /** |
||
| 541 | * Get an option from provided options and call method with that value. |
||
| 542 | * |
||
| 543 | * @param string $name |
||
| 544 | * @param string $method |
||
| 545 | */ |
||
| 546 | 129 | protected function pullFromOptions($name, $method) |
|
| 552 | |||
| 553 | /** |
||
| 554 | * Get form http method. |
||
| 555 | * |
||
| 556 | * @return string |
||
| 557 | */ |
||
| 558 | 3 | public function getMethod() |
|
| 562 | |||
| 563 | /** |
||
| 564 | * Set form http method. |
||
| 565 | * |
||
| 566 | * @param string $method |
||
| 567 | * @return $this |
||
| 568 | */ |
||
| 569 | 1 | public function setMethod($method) |
|
| 575 | |||
| 576 | /** |
||
| 577 | * Get form action url. |
||
| 578 | * |
||
| 579 | * @return string |
||
| 580 | */ |
||
| 581 | 3 | public function getUrl() |
|
| 585 | |||
| 586 | /** |
||
| 587 | * Set form action url. |
||
| 588 | * |
||
| 589 | * @param string $url |
||
| 590 | * @return $this |
||
| 591 | */ |
||
| 592 | 1 | public function setUrl($url) |
|
| 598 | |||
| 599 | /** |
||
| 600 | * Returns the name of the form. |
||
| 601 | * |
||
| 602 | * @return string|null |
||
| 603 | */ |
||
| 604 | 69 | public function getName() |
|
| 608 | |||
| 609 | /** |
||
| 610 | * Set the name of the form. |
||
| 611 | * |
||
| 612 | * @param string $name |
||
| 613 | * @param bool $rebuild |
||
| 614 | * @return $this |
||
| 615 | */ |
||
| 616 | 12 | public function setName($name, $rebuild = true) |
|
| 626 | |||
| 627 | /** |
||
| 628 | * Get model that is bind to form object. |
||
| 629 | * |
||
| 630 | * @return mixed |
||
| 631 | */ |
||
| 632 | 96 | public function getModel() |
|
| 636 | |||
| 637 | /** |
||
| 638 | * Set model to form object. |
||
| 639 | * |
||
| 640 | * @param mixed $model |
||
| 641 | * @return $this |
||
| 642 | * @deprecated deprecated since 1.6.31, will be removed in 1.7 - pass model as option when creating a form |
||
| 643 | */ |
||
| 644 | 17 | public function setModel($model) |
|
| 652 | |||
| 653 | /** |
||
| 654 | * Setup model for form, add namespace if needed for child forms. |
||
| 655 | * |
||
| 656 | * @return $this |
||
| 657 | */ |
||
| 658 | 12 | protected function setupModel($model) |
|
| 665 | |||
| 666 | /** |
||
| 667 | * Get all fields. |
||
| 668 | * |
||
| 669 | * @return FormField[] |
||
| 670 | */ |
||
| 671 | 129 | public function getFields() |
|
| 675 | |||
| 676 | /** |
||
| 677 | * Get field dynamically. |
||
| 678 | * |
||
| 679 | * @param string $name |
||
| 680 | * @return FormField |
||
| 681 | */ |
||
| 682 | 20 | public function __get($name) |
|
| 688 | |||
| 689 | /** |
||
| 690 | * Check if field exists when fetched using magic methods. |
||
| 691 | * |
||
| 692 | * @param string $name |
||
| 693 | * @return bool |
||
| 694 | */ |
||
| 695 | public function __isset($name) |
||
| 699 | |||
| 700 | /** |
||
| 701 | * Set the Event Dispatcher to fire Laravel events. |
||
| 702 | * |
||
| 703 | * @param EventDispatcher $eventDispatcher |
||
| 704 | * @return $this |
||
| 705 | */ |
||
| 706 | 129 | public function setEventDispatcher(EventDispatcher $eventDispatcher) |
|
| 712 | |||
| 713 | /** |
||
| 714 | * Set the form helper only on first instantiation. |
||
| 715 | * |
||
| 716 | * @param FormHelper $formHelper |
||
| 717 | * @return $this |
||
| 718 | */ |
||
| 719 | 129 | public function setFormHelper(FormHelper $formHelper) |
|
| 725 | |||
| 726 | /** |
||
| 727 | * Get form helper. |
||
| 728 | * |
||
| 729 | * @return FormHelper |
||
| 730 | */ |
||
| 731 | 101 | public function getFormHelper() |
|
| 735 | |||
| 736 | /** |
||
| 737 | * Add custom field. |
||
| 738 | * |
||
| 739 | * @param $name |
||
| 740 | * @param $class |
||
| 741 | */ |
||
| 742 | 2 | public function addCustomField($name, $class) |
|
| 750 | |||
| 751 | /** |
||
| 752 | * Returns wether form errors should be shown under every field. |
||
| 753 | * |
||
| 754 | * @return bool |
||
| 755 | */ |
||
| 756 | 101 | public function haveErrorsEnabled() |
|
| 760 | |||
| 761 | /** |
||
| 762 | * Enable or disable showing errors under fields |
||
| 763 | * |
||
| 764 | * @param bool $enabled |
||
| 765 | * @return $this |
||
| 766 | */ |
||
| 767 | 1 | public function setErrorsEnabled($enabled) |
|
| 773 | |||
| 774 | /** |
||
| 775 | * Is client validation enabled? |
||
| 776 | * |
||
| 777 | * @return bool |
||
| 778 | */ |
||
| 779 | 101 | public function clientValidationEnabled() |
|
| 783 | |||
| 784 | /** |
||
| 785 | * Enable/disable client validation. |
||
| 786 | * |
||
| 787 | * @param bool $enable |
||
| 788 | * @return $this |
||
| 789 | */ |
||
| 790 | 2 | public function setClientValidationEnabled($enable) |
|
| 796 | |||
| 797 | /** |
||
| 798 | * Add any aditional data that field needs (ex. array of choices). |
||
| 799 | * |
||
| 800 | * @deprecated deprecated since 1.6.20, will be removed in 1.7 - use 3rd param on create, or 2nd on plain method to pass data |
||
| 801 | * will be switched to protected in 1.7. |
||
| 802 | * @param string $name |
||
| 803 | * @param mixed $data |
||
| 804 | */ |
||
| 805 | 1 | public function setData($name, $data) |
|
| 809 | |||
| 810 | /** |
||
| 811 | * Get single additional data. |
||
| 812 | * |
||
| 813 | * @param string $name |
||
| 814 | * @param null $default |
||
| 815 | * @return mixed |
||
| 816 | */ |
||
| 817 | 20 | public function getData($name = null, $default = null) |
|
| 825 | |||
| 826 | /** |
||
| 827 | * Add multiple peices of data at once. |
||
| 828 | * |
||
| 829 | * @deprecated deprecated since 1.6.12, will be removed in 1.7 - use 3rd param on create, or 2nd on plain method to pass data |
||
| 830 | * will be switched to protected in 1.7. |
||
| 831 | * @param $data |
||
| 832 | * @return $this |
||
| 833 | **/ |
||
| 834 | 129 | public function addData(array $data) |
|
| 842 | |||
| 843 | /** |
||
| 844 | * Get current request. |
||
| 845 | * |
||
| 846 | * @return \Illuminate\Http\Request |
||
| 847 | */ |
||
| 848 | 101 | public function getRequest() |
|
| 852 | |||
| 853 | /** |
||
| 854 | * Set request on form. |
||
| 855 | * |
||
| 856 | * @param Request $request |
||
| 857 | * @return $this |
||
| 858 | */ |
||
| 859 | 129 | public function setRequest(Request $request) |
|
| 865 | |||
| 866 | /** |
||
| 867 | * Get template prefix that is prepended to all template paths. |
||
| 868 | * |
||
| 869 | * @return string |
||
| 870 | */ |
||
| 871 | 39 | public function getTemplatePrefix() |
|
| 879 | |||
| 880 | /** |
||
| 881 | * Set a template prefix for the form and its fields. |
||
| 882 | * |
||
| 883 | * @param string $prefix |
||
| 884 | * @return $this |
||
| 885 | */ |
||
| 886 | 4 | public function setTemplatePrefix($prefix) |
|
| 892 | |||
| 893 | /** |
||
| 894 | * Get the language name. |
||
| 895 | * |
||
| 896 | * @return string |
||
| 897 | */ |
||
| 898 | 98 | public function getLanguageName() |
|
| 902 | |||
| 903 | /** |
||
| 904 | * Set a language name, used as prefix for translated strings. |
||
| 905 | * |
||
| 906 | * @param string $prefix |
||
| 907 | * @return $this |
||
| 908 | */ |
||
| 909 | 13 | public function setLanguageName($prefix) |
|
| 915 | |||
| 916 | /** |
||
| 917 | * Get the translation template. |
||
| 918 | * |
||
| 919 | * @return string |
||
| 920 | */ |
||
| 921 | 100 | public function getTranslationTemplate() |
|
| 925 | |||
| 926 | /** |
||
| 927 | * Set a translation template, used to determine labels for fields. |
||
| 928 | * |
||
| 929 | * @param string $template |
||
| 930 | * @return $this |
||
| 931 | */ |
||
| 932 | 11 | public function setTranslationTemplate($template) |
|
| 938 | |||
| 939 | /** |
||
| 940 | * Render the form. |
||
| 941 | * |
||
| 942 | * @param array $options |
||
| 943 | * @param string $fields |
||
| 944 | * @param bool $showStart |
||
| 945 | * @param bool $showFields |
||
| 946 | * @param bool $showEnd |
||
| 947 | * @return string |
||
| 948 | */ |
||
| 949 | 9 | protected function render($options, $fields, $showStart, $showFields, $showEnd) |
|
| 967 | |||
| 968 | /** |
||
| 969 | * @param $formOptions |
||
| 970 | * @return array |
||
| 971 | */ |
||
| 972 | 9 | protected function buildFormOptionsForFormBuilder($formOptions) |
|
| 981 | |||
| 982 | |||
| 983 | /** |
||
| 984 | * Get template from options if provided, otherwise fallback to config. |
||
| 985 | * |
||
| 986 | * @return mixed |
||
| 987 | */ |
||
| 988 | 9 | protected function getTemplate() |
|
| 992 | |||
| 993 | /** |
||
| 994 | * Get all fields that are not rendered. |
||
| 995 | * |
||
| 996 | * @return array |
||
| 997 | */ |
||
| 998 | 2 | protected function getUnrenderedFields() |
|
| 1011 | |||
| 1012 | /** |
||
| 1013 | * Prevent adding fields with same name. |
||
| 1014 | * |
||
| 1015 | * @param string $name |
||
| 1016 | * @throws \InvalidArgumentException |
||
| 1017 | * @return void |
||
| 1018 | */ |
||
| 1019 | 61 | protected function preventDuplicate($name) |
|
| 1025 | |||
| 1026 | /** |
||
| 1027 | * Returns and checks the type of the field. |
||
| 1028 | * |
||
| 1029 | * @param string $type |
||
| 1030 | * @return string |
||
| 1031 | */ |
||
| 1032 | 65 | protected function getFieldType($type) |
|
| 1038 | |||
| 1039 | /** |
||
| 1040 | * Check if form is named form. |
||
| 1041 | * |
||
| 1042 | * @return void |
||
| 1043 | */ |
||
| 1044 | 129 | protected function checkIfNamedForm() |
|
| 1050 | |||
| 1051 | /** |
||
| 1052 | * Set up options on single field depending on form options. |
||
| 1053 | * |
||
| 1054 | * @param string $name |
||
| 1055 | * @param $options |
||
| 1056 | */ |
||
| 1057 | 65 | protected function setupFieldOptions($name, &$options) |
|
| 1061 | |||
| 1062 | /** |
||
| 1063 | * Set namespace to model if form is named so the data is bound properly. |
||
| 1064 | * Returns true if model is changed, otherwise false. |
||
| 1065 | * |
||
| 1066 | * @return bool |
||
| 1067 | */ |
||
| 1068 | 21 | protected function setupNamedModel() |
|
| 1089 | |||
| 1090 | /** |
||
| 1091 | * Set form builder instance on helper so we can use it later. |
||
| 1092 | * |
||
| 1093 | * @param FormBuilder $formBuilder |
||
| 1094 | * @return $this |
||
| 1095 | */ |
||
| 1096 | 129 | public function setFormBuilder(FormBuilder $formBuilder) |
|
| 1102 | |||
| 1103 | /** |
||
| 1104 | * Returns the instance of the FormBuilder. |
||
| 1105 | * |
||
| 1106 | * @return FormBuilder |
||
| 1107 | */ |
||
| 1108 | 20 | public function getFormBuilder() |
|
| 1112 | |||
| 1113 | /** |
||
| 1114 | * Set the Validator instance on this so we can use it later. |
||
| 1115 | * |
||
| 1116 | * @param ValidatorFactory $validator |
||
| 1117 | * @return $this |
||
| 1118 | */ |
||
| 1119 | 129 | public function setValidator(ValidatorFactory $validator) |
|
| 1125 | |||
| 1126 | /** |
||
| 1127 | * Returns the validator instance. |
||
| 1128 | * |
||
| 1129 | * @return Validator |
||
| 1130 | */ |
||
| 1131 | 1 | public function getValidator() |
|
| 1135 | |||
| 1136 | /** |
||
| 1137 | * Exclude some fields from rendering. |
||
| 1138 | * |
||
| 1139 | * @return $this |
||
| 1140 | */ |
||
| 1141 | public function exclude(array $fields) |
||
| 1147 | |||
| 1148 | /** |
||
| 1149 | * If form is named form, modify names to be contained in single key (parent[child_field_name]). |
||
| 1150 | * |
||
| 1151 | * @param string $name |
||
| 1152 | * @return string |
||
| 1153 | */ |
||
| 1154 | 65 | protected function getFieldName($name) |
|
| 1171 | |||
| 1172 | /** |
||
| 1173 | * Disable all fields in a form. |
||
| 1174 | */ |
||
| 1175 | 1 | public function disableFields() |
|
| 1181 | |||
| 1182 | /** |
||
| 1183 | * Enable all fields in a form. |
||
| 1184 | */ |
||
| 1185 | 1 | public function enableFields() |
|
| 1191 | |||
| 1192 | /** |
||
| 1193 | * Validate the form. |
||
| 1194 | * |
||
| 1195 | * @param array $validationRules |
||
| 1196 | * @param array $messages |
||
| 1197 | * @return Validator |
||
| 1198 | */ |
||
| 1199 | 9 | public function validate($validationRules = [], $messages = []) |
|
| 1212 | |||
| 1213 | /** |
||
| 1214 | * Get validation rules for the form. |
||
| 1215 | * |
||
| 1216 | * @param array $overrideRules |
||
| 1217 | * @return array |
||
| 1218 | */ |
||
| 1219 | 1 | public function getRules($overrideRules = []) |
|
| 1225 | |||
| 1226 | /** |
||
| 1227 | * Redirects to a destination when form is invalid. |
||
| 1228 | * |
||
| 1229 | * @param string|null $destination The target url. |
||
| 1230 | * @return HttpResponseException |
||
| 1231 | */ |
||
| 1232 | 3 | public function redirectIfNotValid($destination = null) |
|
| 1246 | |||
| 1247 | /** |
||
| 1248 | * Get all form field attributes, including child forms, in a flat array. |
||
| 1249 | * |
||
| 1250 | * @return array |
||
| 1251 | */ |
||
| 1252 | 3 | public function getAllAttributes() |
|
| 1256 | |||
| 1257 | /** |
||
| 1258 | * Check if the form is valid. |
||
| 1259 | * |
||
| 1260 | * @return bool |
||
| 1261 | */ |
||
| 1262 | 9 | public function isValid() |
|
| 1276 | |||
| 1277 | /** |
||
| 1278 | * Optionally change the validation result, and/or add error messages. |
||
| 1279 | * |
||
| 1280 | * @param Form $mainForm |
||
| 1281 | * @param bool $isValid |
||
| 1282 | * @return void|array |
||
| 1283 | */ |
||
| 1284 | 9 | public function alterValid(Form $mainForm, &$isValid) |
|
| 1288 | |||
| 1289 | /** |
||
| 1290 | * Get validation errors. |
||
| 1291 | * |
||
| 1292 | * @return array |
||
| 1293 | */ |
||
| 1294 | 8 | public function getErrors() |
|
| 1307 | |||
| 1308 | /** |
||
| 1309 | * Get all Request values from all fields, and nothing else. |
||
| 1310 | * |
||
| 1311 | * @param bool $with_nulls |
||
| 1312 | * @return array |
||
| 1313 | */ |
||
| 1314 | 3 | public function getFieldValues($with_nulls = true) |
|
| 1337 | |||
| 1338 | /** |
||
| 1339 | * Optionally mess with this form's $values before it's returned from getFieldValues(). |
||
| 1340 | * |
||
| 1341 | * @param array $values |
||
| 1342 | * @return void |
||
| 1343 | */ |
||
| 1344 | 3 | public function alterFieldValues(array &$values) |
|
| 1347 | |||
| 1348 | /** |
||
| 1349 | * Throw an exception indicating a field does not exist on the class. |
||
| 1350 | * |
||
| 1351 | * @param string $name |
||
| 1352 | * @throws \InvalidArgumentException |
||
| 1353 | * @return void |
||
| 1354 | */ |
||
| 1355 | 2 | protected function fieldDoesNotExist($name) |
|
| 1359 | |||
| 1360 | /** |
||
| 1361 | * Method filterFields used as *Main* method for starting |
||
| 1362 | * filtering and request field mutating process. |
||
| 1363 | * |
||
| 1364 | * @return \Kris\LaravelFormBuilder\Form |
||
| 1365 | */ |
||
| 1366 | 129 | public function filterFields() |
|
| 1402 | |||
| 1403 | /** |
||
| 1404 | * Method getFilters used to return array of all binded filters to form fields. |
||
| 1405 | * |
||
| 1406 | * @return array |
||
| 1407 | */ |
||
| 1408 | 129 | public function getFilters() |
|
| 1417 | |||
| 1418 | /** |
||
| 1419 | * If lockFiltering is set to true then we will not |
||
| 1420 | * filter fields and mutate request data binded to fields. |
||
| 1421 | * |
||
| 1422 | * @return \Kris\LaravelFormBuilder\Form |
||
| 1423 | */ |
||
| 1424 | 1 | public function lockFiltering() |
|
| 1429 | |||
| 1430 | /** |
||
| 1431 | * Unlock fields filtering/mutating. |
||
| 1432 | * |
||
| 1433 | * @return \Kris\LaravelFormBuilder\Form |
||
| 1434 | */ |
||
| 1435 | public function unlockFiltering() |
||
| 1440 | |||
| 1441 | /** |
||
| 1442 | * Method isFilteringLocked used to check |
||
| 1443 | * if current filteringLocked property status is set to true. |
||
| 1444 | * |
||
| 1445 | * @return bool |
||
| 1446 | */ |
||
| 1447 | 129 | public function isFilteringLocked() |
|
| 1451 | |||
| 1452 | /** |
||
| 1453 | * Method getRawValues returns Unfiltered/Unmutated fields -> values. |
||
| 1454 | * |
||
| 1455 | * @return array |
||
| 1456 | */ |
||
| 1457 | public function getRawValues() |
||
| 1466 | } |
||
| 1467 |
It seems like the type of the argument is not accepted by the function/method which you are calling.
In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.
We suggest to add an explicit type cast like in the following example: