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 implements FieldTypesInterface |
||
| 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 | ]; |
||
| 52 | |||
| 53 | /** |
||
| 54 | * Additional data which can be used to build fields. |
||
| 55 | * |
||
| 56 | * @var array |
||
| 57 | */ |
||
| 58 | protected $data = []; |
||
| 59 | |||
| 60 | /** |
||
| 61 | * Wether errors for each field should be shown when calling form($form) or form_rest($form). |
||
| 62 | * |
||
| 63 | * @var bool |
||
| 64 | */ |
||
| 65 | protected $showFieldErrors = true; |
||
| 66 | |||
| 67 | /** |
||
| 68 | * Enable html5 validation. |
||
| 69 | * |
||
| 70 | * @var bool |
||
| 71 | */ |
||
| 72 | protected $clientValidationEnabled = true; |
||
| 73 | |||
| 74 | /** |
||
| 75 | * Name of the parent form if any. |
||
| 76 | * |
||
| 77 | * @var string|null |
||
| 78 | */ |
||
| 79 | protected $name = null; |
||
| 80 | |||
| 81 | /** |
||
| 82 | * @var FormBuilder |
||
| 83 | */ |
||
| 84 | protected $formBuilder; |
||
| 85 | |||
| 86 | /** |
||
| 87 | * @var ValidatorFactory |
||
| 88 | */ |
||
| 89 | protected $validatorFactory; |
||
| 90 | |||
| 91 | /** |
||
| 92 | * @var Validator |
||
| 93 | */ |
||
| 94 | protected $validator = null; |
||
| 95 | |||
| 96 | /** |
||
| 97 | * @var Request |
||
| 98 | */ |
||
| 99 | protected $request; |
||
| 100 | |||
| 101 | /** |
||
| 102 | * List of fields to not render. |
||
| 103 | * |
||
| 104 | * @var array |
||
| 105 | **/ |
||
| 106 | protected $exclude = []; |
||
| 107 | |||
| 108 | /** |
||
| 109 | * Wether the form is beign rebuild. |
||
| 110 | * |
||
| 111 | * @var bool |
||
| 112 | */ |
||
| 113 | protected $rebuilding = false; |
||
| 114 | |||
| 115 | /** |
||
| 116 | * @var string |
||
| 117 | */ |
||
| 118 | protected $templatePrefix; |
||
| 119 | |||
| 120 | /** |
||
| 121 | * @var string |
||
| 122 | */ |
||
| 123 | protected $languageName; |
||
| 124 | |||
| 125 | /** |
||
| 126 | * @var string |
||
| 127 | */ |
||
| 128 | protected $translationTemplate; |
||
| 129 | |||
| 130 | /** |
||
| 131 | * To filter and mutate request values or not. |
||
| 132 | * |
||
| 133 | * @var bool |
||
| 134 | */ |
||
| 135 | protected $lockFiltering = false; |
||
| 136 | |||
| 137 | /** |
||
| 138 | * Define the error bag name for the form. |
||
| 139 | * |
||
| 140 | * @var string |
||
| 141 | */ |
||
| 142 | protected $errorBag = 'default'; |
||
| 143 | |||
| 144 | /** |
||
| 145 | * Build the form. |
||
| 146 | * |
||
| 147 | * @return mixed |
||
| 148 | */ |
||
| 149 | 3 | public function buildForm() |
|
| 152 | |||
| 153 | /** |
||
| 154 | * Rebuild the form from scratch. |
||
| 155 | * |
||
| 156 | * @return $this |
||
| 157 | */ |
||
| 158 | 19 | public function rebuildForm() |
|
| 176 | |||
| 177 | /** |
||
| 178 | * Create the FormField object. |
||
| 179 | * |
||
| 180 | * @param string $name |
||
| 181 | * @param string $type |
||
| 182 | * @param array $options |
||
| 183 | * @return FormField |
||
| 184 | */ |
||
| 185 | 65 | protected function makeField($name, $type = 'text', array $options = []) |
|
| 199 | |||
| 200 | /** |
||
| 201 | * Create a new field and add it to the form. |
||
| 202 | * |
||
| 203 | * @param string $name |
||
| 204 | * @param string $type |
||
| 205 | * @param array $options |
||
| 206 | * @param bool $modify |
||
| 207 | * @return $this |
||
| 208 | */ |
||
| 209 | 67 | public function add($name, $type = 'text', array $options = [], $modify = false) |
|
| 221 | |||
| 222 | /** |
||
| 223 | * Add a FormField to the form's fields. |
||
| 224 | * |
||
| 225 | * @param FormField $field |
||
| 226 | * @return $this |
||
| 227 | */ |
||
| 228 | 61 | protected function addField(FormField $field, $modify = false) |
|
| 243 | |||
| 244 | /** |
||
| 245 | * Add field before another field. |
||
| 246 | * |
||
| 247 | * @param string $name Name of the field before which new field is added. |
||
| 248 | * @param string $fieldName Field name which will be added. |
||
| 249 | * @param string $type |
||
| 250 | * @param array $options |
||
| 251 | * @param bool $modify |
||
| 252 | * @return $this |
||
| 253 | */ |
||
| 254 | 1 | public function addBefore($name, $fieldName, $type = 'text', $options = [], $modify = false) |
|
| 269 | |||
| 270 | /** |
||
| 271 | * Add field before another field. |
||
| 272 | * |
||
| 273 | * @param string $name Name of the field after which new field is added. |
||
| 274 | * @param string $fieldName Field name which will be added. |
||
| 275 | * @param string $type |
||
| 276 | * @param array $options |
||
| 277 | * @param bool $modify |
||
| 278 | * @return $this |
||
| 279 | */ |
||
| 280 | 1 | public function addAfter($name, $fieldName, $type = 'text', $options = [], $modify = false) |
|
| 295 | |||
| 296 | /** |
||
| 297 | * Take another form and add it's fields directly to this form. |
||
| 298 | * |
||
| 299 | * @param mixed $class Form to merge. |
||
| 300 | * @param array $options |
||
| 301 | * @param boolean $modify |
||
| 302 | * @return $this |
||
| 303 | */ |
||
| 304 | 1 | public function compose($class, array $options = [], $modify = false) |
|
| 332 | |||
| 333 | /** |
||
| 334 | * Remove field with specified name from the form. |
||
| 335 | * |
||
| 336 | * @param $name |
||
| 337 | * @return $this |
||
| 338 | */ |
||
| 339 | 2 | public function remove($name) |
|
| 347 | |||
| 348 | /** |
||
| 349 | * Modify existing field. If it doesn't exist, it is added to form. |
||
| 350 | * |
||
| 351 | * @param string $name |
||
| 352 | * @param string $type |
||
| 353 | * @param array $options |
||
| 354 | * @param bool $overwriteOptions |
||
| 355 | * @return Form |
||
| 356 | */ |
||
| 357 | 1 | public function modify($name, $type = 'text', array $options = [], $overwriteOptions = false) |
|
| 369 | |||
| 370 | /** |
||
| 371 | * Render full form. |
||
| 372 | * |
||
| 373 | * @param array $options |
||
| 374 | * @param bool $showStart |
||
| 375 | * @param bool $showFields |
||
| 376 | * @param bool $showEnd |
||
| 377 | * @return string |
||
| 378 | */ |
||
| 379 | 7 | public function renderForm(array $options = [], $showStart = true, $showFields = true, $showEnd = true) |
|
| 383 | |||
| 384 | /** |
||
| 385 | * Render rest of the form. |
||
| 386 | * |
||
| 387 | * @param bool $showFormEnd |
||
| 388 | * @param bool $showFields |
||
| 389 | * @return string |
||
| 390 | */ |
||
| 391 | 1 | public function renderRest($showFormEnd = true, $showFields = true) |
|
| 397 | |||
| 398 | /** |
||
| 399 | * Renders the rest of the form up until the specified field name. |
||
| 400 | * |
||
| 401 | * @param string $field_name |
||
| 402 | * @param bool $showFormEnd |
||
| 403 | * @param bool $showFields |
||
| 404 | * @return string |
||
| 405 | */ |
||
| 406 | 2 | public function renderUntil($field_name, $showFormEnd = true, $showFields = true) |
|
| 426 | |||
| 427 | /** |
||
| 428 | * Get single field instance from form object. |
||
| 429 | * |
||
| 430 | * @param string $name |
||
| 431 | * @return FormField |
||
| 432 | */ |
||
| 433 | 34 | public function getField($name) |
|
| 441 | |||
| 442 | 101 | public function getErrorBag() |
|
| 446 | |||
| 447 | /** |
||
| 448 | * Check if form has field. |
||
| 449 | * |
||
| 450 | * @param string $name |
||
| 451 | * @return bool |
||
| 452 | */ |
||
| 453 | 61 | public function has($name) |
|
| 457 | |||
| 458 | /** |
||
| 459 | * Get all form options. |
||
| 460 | * |
||
| 461 | * @return array |
||
| 462 | */ |
||
| 463 | 2 | public function getFormOptions() |
|
| 467 | |||
| 468 | /** |
||
| 469 | * Get single form option. |
||
| 470 | * |
||
| 471 | * @param string $option |
||
| 472 | * @param mixed|null $default |
||
| 473 | * @return mixed |
||
| 474 | */ |
||
| 475 | 129 | public function getFormOption($option, $default = null) |
|
| 479 | |||
| 480 | /** |
||
| 481 | * Set single form option on form. |
||
| 482 | * |
||
| 483 | * @param string $option |
||
| 484 | * @param mixed $value |
||
| 485 | * |
||
| 486 | * @return $this |
||
| 487 | */ |
||
| 488 | 2 | public function setFormOption($option, $value) |
|
| 494 | |||
| 495 | /** |
||
| 496 | * Set form options. |
||
| 497 | * |
||
| 498 | * @param array $formOptions |
||
| 499 | * @return $this |
||
| 500 | */ |
||
| 501 | 129 | public function setFormOptions(array $formOptions) |
|
| 515 | |||
| 516 | /** |
||
| 517 | * Get an option from provided options and call method with that value. |
||
| 518 | * |
||
| 519 | * @param string $name |
||
| 520 | * @param string $method |
||
| 521 | */ |
||
| 522 | 129 | protected function pullFromOptions($name, $method) |
|
| 528 | |||
| 529 | /** |
||
| 530 | * Get form http method. |
||
| 531 | * |
||
| 532 | * @return string |
||
| 533 | */ |
||
| 534 | 3 | public function getMethod() |
|
| 538 | |||
| 539 | /** |
||
| 540 | * Set form http method. |
||
| 541 | * |
||
| 542 | * @param string $method |
||
| 543 | * @return $this |
||
| 544 | */ |
||
| 545 | 1 | public function setMethod($method) |
|
| 551 | |||
| 552 | /** |
||
| 553 | * Get form action url. |
||
| 554 | * |
||
| 555 | * @return string |
||
| 556 | */ |
||
| 557 | 3 | public function getUrl() |
|
| 561 | |||
| 562 | /** |
||
| 563 | * Set form action url. |
||
| 564 | * |
||
| 565 | * @param string $url |
||
| 566 | * @return $this |
||
| 567 | */ |
||
| 568 | 1 | public function setUrl($url) |
|
| 574 | |||
| 575 | /** |
||
| 576 | * Returns the name of the form. |
||
| 577 | * |
||
| 578 | * @return string|null |
||
| 579 | */ |
||
| 580 | 69 | public function getName() |
|
| 584 | |||
| 585 | /** |
||
| 586 | * Set the name of the form. |
||
| 587 | * |
||
| 588 | * @param string $name |
||
| 589 | * @param bool $rebuild |
||
| 590 | * @return $this |
||
| 591 | */ |
||
| 592 | 12 | public function setName($name, $rebuild = true) |
|
| 602 | |||
| 603 | /** |
||
| 604 | * Get model that is bind to form object. |
||
| 605 | * |
||
| 606 | * @return mixed |
||
| 607 | */ |
||
| 608 | 96 | public function getModel() |
|
| 612 | |||
| 613 | /** |
||
| 614 | * Set model to form object. |
||
| 615 | * |
||
| 616 | * @param mixed $model |
||
| 617 | * @return $this |
||
| 618 | * @deprecated deprecated since 1.6.31, will be removed in 1.7 - pass model as option when creating a form |
||
| 619 | */ |
||
| 620 | 17 | public function setModel($model) |
|
| 628 | |||
| 629 | /** |
||
| 630 | * Setup model for form, add namespace if needed for child forms. |
||
| 631 | * |
||
| 632 | * @return $this |
||
| 633 | */ |
||
| 634 | 12 | protected function setupModel($model) |
|
| 641 | |||
| 642 | /** |
||
| 643 | * Get all fields. |
||
| 644 | * |
||
| 645 | * @return FormField[] |
||
| 646 | */ |
||
| 647 | 129 | public function getFields() |
|
| 651 | |||
| 652 | /** |
||
| 653 | * Get field dynamically. |
||
| 654 | * |
||
| 655 | * @param string $name |
||
| 656 | * @return FormField |
||
| 657 | */ |
||
| 658 | 20 | public function __get($name) |
|
| 664 | |||
| 665 | /** |
||
| 666 | * Check if field exists when fetched using magic methods. |
||
| 667 | * |
||
| 668 | * @param string $name |
||
| 669 | * @return bool |
||
| 670 | */ |
||
| 671 | public function __isset($name) |
||
| 675 | |||
| 676 | /** |
||
| 677 | * Set the Event Dispatcher to fire Laravel events. |
||
| 678 | * |
||
| 679 | * @param EventDispatcher $eventDispatcher |
||
| 680 | * @return $this |
||
| 681 | */ |
||
| 682 | 129 | public function setEventDispatcher(EventDispatcher $eventDispatcher) |
|
| 688 | |||
| 689 | /** |
||
| 690 | * Set the form helper only on first instantiation. |
||
| 691 | * |
||
| 692 | * @param FormHelper $formHelper |
||
| 693 | * @return $this |
||
| 694 | */ |
||
| 695 | 129 | public function setFormHelper(FormHelper $formHelper) |
|
| 701 | |||
| 702 | /** |
||
| 703 | * Get form helper. |
||
| 704 | * |
||
| 705 | * @return FormHelper |
||
| 706 | */ |
||
| 707 | 101 | public function getFormHelper() |
|
| 711 | |||
| 712 | /** |
||
| 713 | * Add custom field. |
||
| 714 | * |
||
| 715 | * @param $name |
||
| 716 | * @param $class |
||
| 717 | */ |
||
| 718 | 2 | public function addCustomField($name, $class) |
|
| 726 | |||
| 727 | /** |
||
| 728 | * Returns wether form errors should be shown under every field. |
||
| 729 | * |
||
| 730 | * @return bool |
||
| 731 | */ |
||
| 732 | 101 | public function haveErrorsEnabled() |
|
| 736 | |||
| 737 | /** |
||
| 738 | * Enable or disable showing errors under fields |
||
| 739 | * |
||
| 740 | * @param bool $enabled |
||
| 741 | * @return $this |
||
| 742 | */ |
||
| 743 | 1 | public function setErrorsEnabled($enabled) |
|
| 749 | |||
| 750 | /** |
||
| 751 | * Is client validation enabled? |
||
| 752 | * |
||
| 753 | * @return bool |
||
| 754 | */ |
||
| 755 | 101 | public function clientValidationEnabled() |
|
| 759 | |||
| 760 | /** |
||
| 761 | * Enable/disable client validation. |
||
| 762 | * |
||
| 763 | * @param bool $enable |
||
| 764 | * @return $this |
||
| 765 | */ |
||
| 766 | 2 | public function setClientValidationEnabled($enable) |
|
| 772 | |||
| 773 | /** |
||
| 774 | * Add any aditional data that field needs (ex. array of choices). |
||
| 775 | * |
||
| 776 | * @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 |
||
| 777 | * will be switched to protected in 1.7. |
||
| 778 | * @param string $name |
||
| 779 | * @param mixed $data |
||
| 780 | */ |
||
| 781 | 1 | public function setData($name, $data) |
|
| 785 | |||
| 786 | /** |
||
| 787 | * Get single additional data. |
||
| 788 | * |
||
| 789 | * @param string $name |
||
| 790 | * @param null $default |
||
| 791 | * @return mixed |
||
| 792 | */ |
||
| 793 | 20 | public function getData($name = null, $default = null) |
|
| 801 | |||
| 802 | /** |
||
| 803 | * Add multiple peices of data at once. |
||
| 804 | * |
||
| 805 | * @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 |
||
| 806 | * will be switched to protected in 1.7. |
||
| 807 | * @param $data |
||
| 808 | * @return $this |
||
| 809 | **/ |
||
| 810 | 129 | public function addData(array $data) |
|
| 818 | |||
| 819 | /** |
||
| 820 | * Get current request. |
||
| 821 | * |
||
| 822 | * @return \Illuminate\Http\Request |
||
| 823 | */ |
||
| 824 | 129 | public function getRequest() |
|
| 828 | |||
| 829 | /** |
||
| 830 | * Set request on form. |
||
| 831 | * |
||
| 832 | * @param Request $request |
||
| 833 | * @return $this |
||
| 834 | */ |
||
| 835 | 129 | public function setRequest(Request $request) |
|
| 841 | |||
| 842 | /** |
||
| 843 | * Get template prefix that is prepended to all template paths. |
||
| 844 | * |
||
| 845 | * @return string |
||
| 846 | */ |
||
| 847 | 39 | public function getTemplatePrefix() |
|
| 855 | |||
| 856 | /** |
||
| 857 | * Set a template prefix for the form and its fields. |
||
| 858 | * |
||
| 859 | * @param string $prefix |
||
| 860 | * @return $this |
||
| 861 | */ |
||
| 862 | 4 | public function setTemplatePrefix($prefix) |
|
| 868 | |||
| 869 | /** |
||
| 870 | * Get the language name. |
||
| 871 | * |
||
| 872 | * @return string |
||
| 873 | */ |
||
| 874 | 98 | public function getLanguageName() |
|
| 878 | |||
| 879 | /** |
||
| 880 | * Set a language name, used as prefix for translated strings. |
||
| 881 | * |
||
| 882 | * @param string $prefix |
||
| 883 | * @return $this |
||
| 884 | */ |
||
| 885 | 13 | public function setLanguageName($prefix) |
|
| 891 | |||
| 892 | /** |
||
| 893 | * Get the translation template. |
||
| 894 | * |
||
| 895 | * @return string |
||
| 896 | */ |
||
| 897 | 100 | public function getTranslationTemplate() |
|
| 901 | |||
| 902 | /** |
||
| 903 | * Set a translation template, used to determine labels for fields. |
||
| 904 | * |
||
| 905 | * @param string $template |
||
| 906 | * @return $this |
||
| 907 | */ |
||
| 908 | 11 | public function setTranslationTemplate($template) |
|
| 914 | |||
| 915 | /** |
||
| 916 | * Render the form. |
||
| 917 | * |
||
| 918 | * @param array $options |
||
| 919 | * @param string $fields |
||
| 920 | * @param bool $showStart |
||
| 921 | * @param bool $showFields |
||
| 922 | * @param bool $showEnd |
||
| 923 | * @return string |
||
| 924 | */ |
||
| 925 | 9 | protected function render($options, $fields, $showStart, $showFields, $showEnd) |
|
| 941 | |||
| 942 | /** |
||
| 943 | * Get template from options if provided, otherwise fallback to config. |
||
| 944 | * |
||
| 945 | * @return mixed |
||
| 946 | */ |
||
| 947 | 9 | protected function getTemplate() |
|
| 951 | |||
| 952 | /** |
||
| 953 | * Get all fields that are not rendered. |
||
| 954 | * |
||
| 955 | * @return array |
||
| 956 | */ |
||
| 957 | 2 | protected function getUnrenderedFields() |
|
| 970 | |||
| 971 | /** |
||
| 972 | * Prevent adding fields with same name. |
||
| 973 | * |
||
| 974 | * @param string $name |
||
| 975 | * @throws \InvalidArgumentException |
||
| 976 | * @return void |
||
| 977 | */ |
||
| 978 | 61 | protected function preventDuplicate($name) |
|
| 984 | |||
| 985 | /** |
||
| 986 | * Returns and checks the type of the field. |
||
| 987 | * |
||
| 988 | * @param string $type |
||
| 989 | * @return string |
||
| 990 | */ |
||
| 991 | 65 | protected function getFieldType($type) |
|
| 997 | |||
| 998 | /** |
||
| 999 | * Check if form is named form. |
||
| 1000 | * |
||
| 1001 | * @return void |
||
| 1002 | */ |
||
| 1003 | 129 | protected function checkIfNamedForm() |
|
| 1009 | |||
| 1010 | /** |
||
| 1011 | * Set up options on single field depending on form options. |
||
| 1012 | * |
||
| 1013 | * @param string $name |
||
| 1014 | * @param $options |
||
| 1015 | */ |
||
| 1016 | 65 | protected function setupFieldOptions($name, &$options) |
|
| 1020 | |||
| 1021 | /** |
||
| 1022 | * Set namespace to model if form is named so the data is bound properly. |
||
| 1023 | * Returns true if model is changed, otherwise false. |
||
| 1024 | * |
||
| 1025 | * @return bool |
||
| 1026 | */ |
||
| 1027 | 21 | protected function setupNamedModel() |
|
| 1048 | |||
| 1049 | /** |
||
| 1050 | * Set form builder instance on helper so we can use it later. |
||
| 1051 | * |
||
| 1052 | * @param FormBuilder $formBuilder |
||
| 1053 | * @return $this |
||
| 1054 | */ |
||
| 1055 | 129 | public function setFormBuilder(FormBuilder $formBuilder) |
|
| 1061 | |||
| 1062 | /** |
||
| 1063 | * Returns the instance of the FormBuilder. |
||
| 1064 | * |
||
| 1065 | * @return FormBuilder |
||
| 1066 | */ |
||
| 1067 | 12 | public function getFormBuilder() |
|
| 1071 | |||
| 1072 | /** |
||
| 1073 | * Set the Validator instance on this so we can use it later. |
||
| 1074 | * |
||
| 1075 | * @param ValidatorFactory $validator |
||
| 1076 | * @return $this |
||
| 1077 | */ |
||
| 1078 | 129 | public function setValidator(ValidatorFactory $validator) |
|
| 1084 | |||
| 1085 | /** |
||
| 1086 | * Returns the validator instance. |
||
| 1087 | * |
||
| 1088 | * @return Validator |
||
| 1089 | */ |
||
| 1090 | 1 | public function getValidator() |
|
| 1094 | |||
| 1095 | /** |
||
| 1096 | * Exclude some fields from rendering. |
||
| 1097 | * |
||
| 1098 | * @return $this |
||
| 1099 | */ |
||
| 1100 | public function exclude(array $fields) |
||
| 1106 | |||
| 1107 | /** |
||
| 1108 | * If form is named form, modify names to be contained in single key (parent[child_field_name]). |
||
| 1109 | * |
||
| 1110 | * @param string $name |
||
| 1111 | * @return string |
||
| 1112 | */ |
||
| 1113 | 65 | protected function getFieldName($name) |
|
| 1130 | |||
| 1131 | /** |
||
| 1132 | * Disable all fields in a form. |
||
| 1133 | */ |
||
| 1134 | 1 | public function disableFields() |
|
| 1140 | |||
| 1141 | /** |
||
| 1142 | * Enable all fields in a form. |
||
| 1143 | */ |
||
| 1144 | 1 | public function enableFields() |
|
| 1150 | |||
| 1151 | /** |
||
| 1152 | * Validate the form. |
||
| 1153 | * |
||
| 1154 | * @param array $validationRules |
||
| 1155 | * @param array $messages |
||
| 1156 | * @return Validator |
||
| 1157 | */ |
||
| 1158 | 9 | public function validate($validationRules = [], $messages = []) |
|
| 1171 | |||
| 1172 | /** |
||
| 1173 | * Get validation rules for the form. |
||
| 1174 | * |
||
| 1175 | * @param array $overrideRules |
||
| 1176 | * @return array |
||
| 1177 | */ |
||
| 1178 | 1 | public function getRules($overrideRules = []) |
|
| 1184 | |||
| 1185 | /** |
||
| 1186 | * Redirects to a destination when form is invalid. |
||
| 1187 | * |
||
| 1188 | * @param string|null $destination The target url. |
||
| 1189 | * @return HttpResponseException |
||
| 1190 | */ |
||
| 1191 | 3 | public function redirectIfNotValid($destination = null) |
|
| 1205 | |||
| 1206 | /** |
||
| 1207 | * Get all form field attributes, including child forms, in a flat array. |
||
| 1208 | * |
||
| 1209 | * @return array |
||
| 1210 | */ |
||
| 1211 | 3 | public function getAllAttributes() |
|
| 1215 | |||
| 1216 | /** |
||
| 1217 | * Check if the form is valid. |
||
| 1218 | * |
||
| 1219 | * @return bool |
||
| 1220 | */ |
||
| 1221 | 9 | public function isValid() |
|
| 1235 | |||
| 1236 | /** |
||
| 1237 | * Optionally change the validation result, and/or add error messages. |
||
| 1238 | * |
||
| 1239 | * @param Form $mainForm |
||
| 1240 | * @param bool $isValid |
||
| 1241 | * @return void|array |
||
| 1242 | */ |
||
| 1243 | 9 | public function alterValid(Form $mainForm, &$isValid) |
|
| 1247 | |||
| 1248 | /** |
||
| 1249 | * Get validation errors. |
||
| 1250 | * |
||
| 1251 | * @return array |
||
| 1252 | */ |
||
| 1253 | 8 | public function getErrors() |
|
| 1266 | |||
| 1267 | /** |
||
| 1268 | * Get all Request values from all fields, and nothing else. |
||
| 1269 | * |
||
| 1270 | * @param bool $with_nulls |
||
| 1271 | * @return array |
||
| 1272 | */ |
||
| 1273 | 3 | public function getFieldValues($with_nulls = true) |
|
| 1296 | |||
| 1297 | /** |
||
| 1298 | * Optionally mess with this form's $values before it's returned from getFieldValues(). |
||
| 1299 | * |
||
| 1300 | * @param array $values |
||
| 1301 | * @return void |
||
| 1302 | */ |
||
| 1303 | 3 | public function alterFieldValues(array &$values) |
|
| 1306 | |||
| 1307 | /** |
||
| 1308 | * Throw an exception indicating a field does not exist on the class. |
||
| 1309 | * |
||
| 1310 | * @param string $name |
||
| 1311 | * @throws \InvalidArgumentException |
||
| 1312 | * @return void |
||
| 1313 | */ |
||
| 1314 | 2 | protected function fieldDoesNotExist($name) |
|
| 1318 | |||
| 1319 | /** |
||
| 1320 | * Method filterFields used as *Main* method for starting |
||
| 1321 | * filtering and request field mutating process. |
||
| 1322 | * |
||
| 1323 | * @return \Kris\LaravelFormBuilder\Form |
||
| 1324 | */ |
||
| 1325 | 129 | public function filterFields() |
|
| 1351 | |||
| 1352 | /** |
||
| 1353 | * Method getFilters used to return array of all binded filters to form fields. |
||
| 1354 | * |
||
| 1355 | * @return array |
||
| 1356 | */ |
||
| 1357 | 129 | public function getFilters() |
|
| 1366 | |||
| 1367 | /** |
||
| 1368 | * If lockFiltering is set to true then we will not |
||
| 1369 | * filter fields and mutate request data binded to fields. |
||
| 1370 | * |
||
| 1371 | * @return \Kris\LaravelFormBuilder\Form |
||
| 1372 | */ |
||
| 1373 | 1 | public function lockFiltering() |
|
| 1378 | |||
| 1379 | /** |
||
| 1380 | * Unlock fields filtering/mutating. |
||
| 1381 | * |
||
| 1382 | * @return \Kris\LaravelFormBuilder\Form |
||
| 1383 | */ |
||
| 1384 | public function unlockFiltering() |
||
| 1389 | |||
| 1390 | /** |
||
| 1391 | * Method isFilteringLocked used to check |
||
| 1392 | * if current filteringLocked property status is set to true. |
||
| 1393 | * |
||
| 1394 | * @return bool |
||
| 1395 | */ |
||
| 1396 | 129 | public function isFilteringLocked() |
|
| 1400 | |||
| 1401 | /** |
||
| 1402 | * Method getRawValues returns Unfiltered/Unmutated fields -> values. |
||
| 1403 | * |
||
| 1404 | * @return array |
||
| 1405 | */ |
||
| 1406 | public function getRawValues() |
||
| 1415 | } |
||
| 1416 |
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: