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 | 66 | 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 | 68 | 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 | 62 | 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 | * Take only the given fields from the form. |
||
| 360 | * |
||
| 361 | * @param string|string[] $fieldNames |
||
| 362 | * @return $this |
||
| 363 | */ |
||
| 364 | 1 | public function only($fieldNames) |
|
| 376 | |||
| 377 | /** |
||
| 378 | * Modify existing field. If it doesn't exist, it is added to form. |
||
| 379 | * |
||
| 380 | * @param string $name |
||
| 381 | * @param string $type |
||
| 382 | * @param array $options |
||
| 383 | * @param bool $overwriteOptions |
||
| 384 | * @return Form |
||
| 385 | */ |
||
| 386 | 1 | public function modify($name, $type = 'text', array $options = [], $overwriteOptions = false) |
|
| 398 | |||
| 399 | /** |
||
| 400 | * Render full form. |
||
| 401 | * |
||
| 402 | * @param array $options |
||
| 403 | * @param bool $showStart |
||
| 404 | * @param bool $showFields |
||
| 405 | * @param bool $showEnd |
||
| 406 | * @return string |
||
| 407 | */ |
||
| 408 | 7 | public function renderForm(array $options = [], $showStart = true, $showFields = true, $showEnd = true) |
|
| 412 | |||
| 413 | /** |
||
| 414 | * Render rest of the form. |
||
| 415 | * |
||
| 416 | * @param bool $showFormEnd |
||
| 417 | * @param bool $showFields |
||
| 418 | * @return string |
||
| 419 | */ |
||
| 420 | 1 | public function renderRest($showFormEnd = true, $showFields = true) |
|
| 426 | |||
| 427 | /** |
||
| 428 | * Renders the rest of the form up until the specified field name. |
||
| 429 | * |
||
| 430 | * @param string $field_name |
||
| 431 | * @param bool $showFormEnd |
||
| 432 | * @param bool $showFields |
||
| 433 | * @return string |
||
| 434 | */ |
||
| 435 | 2 | public function renderUntil($field_name, $showFormEnd = true, $showFields = true) |
|
| 455 | |||
| 456 | /** |
||
| 457 | * Get single field instance from form object. |
||
| 458 | * |
||
| 459 | * @param string $name |
||
| 460 | * @return FormField |
||
| 461 | */ |
||
| 462 | 36 | public function getField($name) |
|
| 470 | |||
| 471 | 102 | public function getErrorBag() |
|
| 475 | |||
| 476 | /** |
||
| 477 | * Check if form has field. |
||
| 478 | * |
||
| 479 | * @param string $name |
||
| 480 | * @return bool |
||
| 481 | */ |
||
| 482 | 62 | public function has($name) |
|
| 486 | |||
| 487 | /** |
||
| 488 | * Get all form options. |
||
| 489 | * |
||
| 490 | * @return array |
||
| 491 | */ |
||
| 492 | 2 | public function getFormOptions() |
|
| 496 | |||
| 497 | /** |
||
| 498 | * Get single form option. |
||
| 499 | * |
||
| 500 | * @param string $option |
||
| 501 | * @param mixed|null $default |
||
| 502 | * @return mixed |
||
| 503 | */ |
||
| 504 | 130 | public function getFormOption($option, $default = null) |
|
| 508 | |||
| 509 | /** |
||
| 510 | * Set single form option on form. |
||
| 511 | * |
||
| 512 | * @param string $option |
||
| 513 | * @param mixed $value |
||
| 514 | * |
||
| 515 | * @return $this |
||
| 516 | */ |
||
| 517 | 2 | public function setFormOption($option, $value) |
|
| 523 | |||
| 524 | /** |
||
| 525 | * Get the passed config key using the custom |
||
| 526 | * form config, if any. |
||
| 527 | * |
||
| 528 | * @param string $key |
||
| 529 | * @param mixed $default |
||
| 530 | * |
||
| 531 | * @return mixed |
||
| 532 | */ |
||
| 533 | 104 | public function getConfig($key = null, $default = null) |
|
| 537 | |||
| 538 | /** |
||
| 539 | * Set form options. |
||
| 540 | * |
||
| 541 | * @param array $formOptions |
||
| 542 | * @return $this |
||
| 543 | */ |
||
| 544 | 130 | public function setFormOptions(array $formOptions) |
|
| 558 | |||
| 559 | /** |
||
| 560 | * Get an option from provided options and call method with that value. |
||
| 561 | * |
||
| 562 | * @param string $name |
||
| 563 | * @param string $method |
||
| 564 | */ |
||
| 565 | 130 | protected function pullFromOptions($name, $method) |
|
| 571 | |||
| 572 | /** |
||
| 573 | * Get form http method. |
||
| 574 | * |
||
| 575 | * @return string |
||
| 576 | */ |
||
| 577 | 3 | public function getMethod() |
|
| 581 | |||
| 582 | /** |
||
| 583 | * Set form http method. |
||
| 584 | * |
||
| 585 | * @param string $method |
||
| 586 | * @return $this |
||
| 587 | */ |
||
| 588 | 1 | public function setMethod($method) |
|
| 594 | |||
| 595 | /** |
||
| 596 | * Get form action url. |
||
| 597 | * |
||
| 598 | * @return string |
||
| 599 | */ |
||
| 600 | 3 | public function getUrl() |
|
| 604 | |||
| 605 | /** |
||
| 606 | * Set form action url. |
||
| 607 | * |
||
| 608 | * @param string $url |
||
| 609 | * @return $this |
||
| 610 | */ |
||
| 611 | 1 | public function setUrl($url) |
|
| 617 | |||
| 618 | /** |
||
| 619 | * Returns the name of the form. |
||
| 620 | * |
||
| 621 | * @return string|null |
||
| 622 | */ |
||
| 623 | 70 | public function getName() |
|
| 627 | |||
| 628 | /** |
||
| 629 | * Get dot notation key for the form. |
||
| 630 | * |
||
| 631 | * @return string |
||
| 632 | **/ |
||
| 633 | 13 | public function getNameKey() |
|
| 637 | |||
| 638 | /** |
||
| 639 | * Set the name of the form. |
||
| 640 | * |
||
| 641 | * @param string $name |
||
| 642 | * @param bool $rebuild |
||
| 643 | * @return $this |
||
| 644 | */ |
||
| 645 | 12 | public function setName($name, $rebuild = true) |
|
| 655 | |||
| 656 | /** |
||
| 657 | * Get model that is bind to form object. |
||
| 658 | * |
||
| 659 | * @return mixed |
||
| 660 | */ |
||
| 661 | 97 | public function getModel() |
|
| 665 | |||
| 666 | /** |
||
| 667 | * Set model to form object. |
||
| 668 | * |
||
| 669 | * @param mixed $model |
||
| 670 | * @return $this |
||
| 671 | * @deprecated deprecated since 1.6.31, will be removed in 1.7 - pass model as option when creating a form |
||
| 672 | */ |
||
| 673 | 17 | public function setModel($model) |
|
| 681 | |||
| 682 | /** |
||
| 683 | * Setup model for form, add namespace if needed for child forms. |
||
| 684 | * |
||
| 685 | * @return $this |
||
| 686 | */ |
||
| 687 | 12 | protected function setupModel($model) |
|
| 694 | |||
| 695 | /** |
||
| 696 | * Get all fields. |
||
| 697 | * |
||
| 698 | * @return FormField[] |
||
| 699 | */ |
||
| 700 | 130 | public function getFields() |
|
| 704 | |||
| 705 | /** |
||
| 706 | * Get field dynamically. |
||
| 707 | * |
||
| 708 | * @param string $name |
||
| 709 | * @return FormField |
||
| 710 | */ |
||
| 711 | 20 | public function __get($name) |
|
| 717 | |||
| 718 | /** |
||
| 719 | * Check if field exists when fetched using magic methods. |
||
| 720 | * |
||
| 721 | * @param string $name |
||
| 722 | * @return bool |
||
| 723 | */ |
||
| 724 | public function __isset($name) |
||
| 728 | |||
| 729 | /** |
||
| 730 | * Set the Event Dispatcher to fire Laravel events. |
||
| 731 | * |
||
| 732 | * @param EventDispatcher $eventDispatcher |
||
| 733 | * @return $this |
||
| 734 | */ |
||
| 735 | 130 | public function setEventDispatcher(EventDispatcher $eventDispatcher) |
|
| 741 | |||
| 742 | /** |
||
| 743 | * Set the form helper only on first instantiation. |
||
| 744 | * |
||
| 745 | * @param FormHelper $formHelper |
||
| 746 | * @return $this |
||
| 747 | */ |
||
| 748 | 130 | public function setFormHelper(FormHelper $formHelper) |
|
| 754 | |||
| 755 | /** |
||
| 756 | * Get form helper. |
||
| 757 | * |
||
| 758 | * @return FormHelper |
||
| 759 | */ |
||
| 760 | 102 | public function getFormHelper() |
|
| 764 | |||
| 765 | /** |
||
| 766 | * Add custom field. |
||
| 767 | * |
||
| 768 | * @param $name |
||
| 769 | * @param $class |
||
| 770 | */ |
||
| 771 | 2 | public function addCustomField($name, $class) |
|
| 779 | |||
| 780 | /** |
||
| 781 | * Returns wether form errors should be shown under every field. |
||
| 782 | * |
||
| 783 | * @return bool |
||
| 784 | */ |
||
| 785 | 102 | public function haveErrorsEnabled() |
|
| 789 | |||
| 790 | /** |
||
| 791 | * Enable or disable showing errors under fields |
||
| 792 | * |
||
| 793 | * @param bool $enabled |
||
| 794 | * @return $this |
||
| 795 | */ |
||
| 796 | 1 | public function setErrorsEnabled($enabled) |
|
| 802 | |||
| 803 | /** |
||
| 804 | * Is client validation enabled? |
||
| 805 | * |
||
| 806 | * @return bool |
||
| 807 | */ |
||
| 808 | 102 | public function clientValidationEnabled() |
|
| 812 | |||
| 813 | /** |
||
| 814 | * Enable/disable client validation. |
||
| 815 | * |
||
| 816 | * @param bool $enable |
||
| 817 | * @return $this |
||
| 818 | */ |
||
| 819 | 2 | public function setClientValidationEnabled($enable) |
|
| 825 | |||
| 826 | /** |
||
| 827 | * Add any aditional data that field needs (ex. array of choices). |
||
| 828 | * |
||
| 829 | * @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 |
||
| 830 | * will be switched to protected in 1.7. |
||
| 831 | * @param string $name |
||
| 832 | * @param mixed $data |
||
| 833 | */ |
||
| 834 | 1 | public function setData($name, $data) |
|
| 838 | |||
| 839 | /** |
||
| 840 | * Get single additional data. |
||
| 841 | * |
||
| 842 | * @param string $name |
||
| 843 | * @param null $default |
||
| 844 | * @return mixed |
||
| 845 | */ |
||
| 846 | 20 | public function getData($name = null, $default = null) |
|
| 854 | |||
| 855 | /** |
||
| 856 | * Add multiple peices of data at once. |
||
| 857 | * |
||
| 858 | * @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 |
||
| 859 | * will be switched to protected in 1.7. |
||
| 860 | * @param $data |
||
| 861 | * @return $this |
||
| 862 | **/ |
||
| 863 | 130 | public function addData(array $data) |
|
| 871 | |||
| 872 | /** |
||
| 873 | * Get current request. |
||
| 874 | * |
||
| 875 | * @return \Illuminate\Http\Request |
||
| 876 | */ |
||
| 877 | 102 | public function getRequest() |
|
| 881 | |||
| 882 | /** |
||
| 883 | * Set request on form. |
||
| 884 | * |
||
| 885 | * @param Request $request |
||
| 886 | * @return $this |
||
| 887 | */ |
||
| 888 | 130 | public function setRequest(Request $request) |
|
| 894 | |||
| 895 | /** |
||
| 896 | * Get template prefix that is prepended to all template paths. |
||
| 897 | * |
||
| 898 | * @return string |
||
| 899 | */ |
||
| 900 | 39 | public function getTemplatePrefix() |
|
| 908 | |||
| 909 | /** |
||
| 910 | * Set a template prefix for the form and its fields. |
||
| 911 | * |
||
| 912 | * @param string $prefix |
||
| 913 | * @return $this |
||
| 914 | */ |
||
| 915 | 4 | public function setTemplatePrefix($prefix) |
|
| 921 | |||
| 922 | /** |
||
| 923 | * Get the language name. |
||
| 924 | * |
||
| 925 | * @return string |
||
| 926 | */ |
||
| 927 | 99 | public function getLanguageName() |
|
| 931 | |||
| 932 | /** |
||
| 933 | * Set a language name, used as prefix for translated strings. |
||
| 934 | * |
||
| 935 | * @param string $prefix |
||
| 936 | * @return $this |
||
| 937 | */ |
||
| 938 | 13 | public function setLanguageName($prefix) |
|
| 944 | |||
| 945 | /** |
||
| 946 | * Get the translation template. |
||
| 947 | * |
||
| 948 | * @return string |
||
| 949 | */ |
||
| 950 | 101 | public function getTranslationTemplate() |
|
| 954 | |||
| 955 | /** |
||
| 956 | * Set a translation template, used to determine labels for fields. |
||
| 957 | * |
||
| 958 | * @param string $template |
||
| 959 | * @return $this |
||
| 960 | */ |
||
| 961 | 11 | public function setTranslationTemplate($template) |
|
| 967 | |||
| 968 | /** |
||
| 969 | * Render the form. |
||
| 970 | * |
||
| 971 | * @param array $options |
||
| 972 | * @param string $fields |
||
| 973 | * @param bool $showStart |
||
| 974 | * @param bool $showFields |
||
| 975 | * @param bool $showEnd |
||
| 976 | * @return string |
||
| 977 | */ |
||
| 978 | 9 | protected function render($options, $fields, $showStart, $showFields, $showEnd) |
|
| 996 | |||
| 997 | /** |
||
| 998 | * @param $formOptions |
||
| 999 | * @return array |
||
| 1000 | */ |
||
| 1001 | 9 | protected function buildFormOptionsForFormBuilder($formOptions) |
|
| 1017 | |||
| 1018 | |||
| 1019 | /** |
||
| 1020 | * Get template from options if provided, otherwise fallback to config. |
||
| 1021 | * |
||
| 1022 | * @return mixed |
||
| 1023 | */ |
||
| 1024 | 9 | protected function getTemplate() |
|
| 1028 | |||
| 1029 | /** |
||
| 1030 | * Get all fields that are not rendered. |
||
| 1031 | * |
||
| 1032 | * @return array |
||
| 1033 | */ |
||
| 1034 | 2 | protected function getUnrenderedFields() |
|
| 1047 | |||
| 1048 | /** |
||
| 1049 | * Prevent adding fields with same name. |
||
| 1050 | * |
||
| 1051 | * @param string $name |
||
| 1052 | * @throws \InvalidArgumentException |
||
| 1053 | * @return void |
||
| 1054 | */ |
||
| 1055 | 62 | protected function preventDuplicate($name) |
|
| 1061 | |||
| 1062 | /** |
||
| 1063 | * Returns and checks the type of the field. |
||
| 1064 | * |
||
| 1065 | * @param string $type |
||
| 1066 | * @return string |
||
| 1067 | */ |
||
| 1068 | 66 | protected function getFieldType($type) |
|
| 1074 | |||
| 1075 | /** |
||
| 1076 | * Check if form is named form. |
||
| 1077 | * |
||
| 1078 | * @return void |
||
| 1079 | */ |
||
| 1080 | 130 | protected function checkIfNamedForm() |
|
| 1086 | |||
| 1087 | /** |
||
| 1088 | * Set up options on single field depending on form options. |
||
| 1089 | * |
||
| 1090 | * @param string $name |
||
| 1091 | * @param $options |
||
| 1092 | */ |
||
| 1093 | 66 | protected function setupFieldOptions($name, &$options) |
|
| 1097 | |||
| 1098 | /** |
||
| 1099 | * Set namespace to model if form is named so the data is bound properly. |
||
| 1100 | * Returns true if model is changed, otherwise false. |
||
| 1101 | * |
||
| 1102 | * @return bool |
||
| 1103 | */ |
||
| 1104 | 21 | protected function setupNamedModel() |
|
| 1125 | |||
| 1126 | /** |
||
| 1127 | * Set form builder instance on helper so we can use it later. |
||
| 1128 | * |
||
| 1129 | * @param FormBuilder $formBuilder |
||
| 1130 | * @return $this |
||
| 1131 | */ |
||
| 1132 | 130 | public function setFormBuilder(FormBuilder $formBuilder) |
|
| 1138 | |||
| 1139 | /** |
||
| 1140 | * Returns the instance of the FormBuilder. |
||
| 1141 | * |
||
| 1142 | * @return FormBuilder |
||
| 1143 | */ |
||
| 1144 | 20 | public function getFormBuilder() |
|
| 1148 | |||
| 1149 | /** |
||
| 1150 | * Set the Validator instance on this so we can use it later. |
||
| 1151 | * |
||
| 1152 | * @param ValidatorFactory $validator |
||
| 1153 | * @return $this |
||
| 1154 | */ |
||
| 1155 | 130 | public function setValidator(ValidatorFactory $validator) |
|
| 1161 | |||
| 1162 | /** |
||
| 1163 | * Returns the validator instance. |
||
| 1164 | * |
||
| 1165 | * @return Validator |
||
| 1166 | */ |
||
| 1167 | 1 | public function getValidator() |
|
| 1171 | |||
| 1172 | /** |
||
| 1173 | * Exclude some fields from rendering. |
||
| 1174 | * |
||
| 1175 | * @return $this |
||
| 1176 | */ |
||
| 1177 | public function exclude(array $fields) |
||
| 1183 | |||
| 1184 | /** |
||
| 1185 | * If form is named form, modify names to be contained in single key (parent[child_field_name]). |
||
| 1186 | * |
||
| 1187 | * @param string $name |
||
| 1188 | * @return string |
||
| 1189 | */ |
||
| 1190 | 66 | protected function getFieldName($name) |
|
| 1207 | |||
| 1208 | /** |
||
| 1209 | * Disable all fields in a form. |
||
| 1210 | */ |
||
| 1211 | 1 | public function disableFields() |
|
| 1217 | |||
| 1218 | /** |
||
| 1219 | * Enable all fields in a form. |
||
| 1220 | */ |
||
| 1221 | 1 | public function enableFields() |
|
| 1227 | |||
| 1228 | /** |
||
| 1229 | * Validate the form. |
||
| 1230 | * |
||
| 1231 | * @param array $validationRules |
||
| 1232 | * @param array $messages |
||
| 1233 | * @return Validator |
||
| 1234 | */ |
||
| 1235 | 9 | public function validate($validationRules = [], $messages = []) |
|
| 1248 | |||
| 1249 | /** |
||
| 1250 | * Get validation rules for the form. |
||
| 1251 | * |
||
| 1252 | * @param array $overrideRules |
||
| 1253 | * @return array |
||
| 1254 | */ |
||
| 1255 | 1 | public function getRules($overrideRules = []) |
|
| 1261 | |||
| 1262 | /** |
||
| 1263 | * Redirects to a destination when form is invalid. |
||
| 1264 | * |
||
| 1265 | * @param string|null $destination The target url. |
||
| 1266 | * @return HttpResponseException |
||
| 1267 | */ |
||
| 1268 | 3 | public function redirectIfNotValid($destination = null) |
|
| 1282 | |||
| 1283 | /** |
||
| 1284 | * Get all form field attributes, including child forms, in a flat array. |
||
| 1285 | * |
||
| 1286 | * @return array |
||
| 1287 | */ |
||
| 1288 | 3 | public function getAllAttributes() |
|
| 1292 | |||
| 1293 | /** |
||
| 1294 | * Check if the form is valid. |
||
| 1295 | * |
||
| 1296 | * @return bool |
||
| 1297 | */ |
||
| 1298 | 9 | public function isValid() |
|
| 1312 | |||
| 1313 | /** |
||
| 1314 | * Optionally change the validation result, and/or add error messages. |
||
| 1315 | * |
||
| 1316 | * @param Form $mainForm |
||
| 1317 | * @param bool $isValid |
||
| 1318 | * @return void|array |
||
| 1319 | */ |
||
| 1320 | 9 | public function alterValid(Form $mainForm, &$isValid) |
|
| 1324 | |||
| 1325 | /** |
||
| 1326 | * Get validation errors. |
||
| 1327 | * |
||
| 1328 | * @return array |
||
| 1329 | */ |
||
| 1330 | 8 | public function getErrors() |
|
| 1343 | |||
| 1344 | /** |
||
| 1345 | * Get all Request values from all fields, and nothing else. |
||
| 1346 | * |
||
| 1347 | * @param bool $with_nulls |
||
| 1348 | * @return array |
||
| 1349 | */ |
||
| 1350 | 3 | public function getFieldValues($with_nulls = true) |
|
| 1373 | |||
| 1374 | /** |
||
| 1375 | * Optionally mess with this form's $values before it's returned from getFieldValues(). |
||
| 1376 | * |
||
| 1377 | * @param array $values |
||
| 1378 | * @return void |
||
| 1379 | */ |
||
| 1380 | 3 | public function alterFieldValues(array &$values) |
|
| 1383 | |||
| 1384 | /** |
||
| 1385 | * Throw an exception indicating a field does not exist on the class. |
||
| 1386 | * |
||
| 1387 | * @param string $name |
||
| 1388 | * @throws \InvalidArgumentException |
||
| 1389 | * @return void |
||
| 1390 | */ |
||
| 1391 | 2 | protected function fieldDoesNotExist($name) |
|
| 1395 | |||
| 1396 | /** |
||
| 1397 | * Method filterFields used as *Main* method for starting |
||
| 1398 | * filtering and request field mutating process. |
||
| 1399 | * |
||
| 1400 | * @return \Kris\LaravelFormBuilder\Form |
||
| 1401 | */ |
||
| 1402 | 130 | public function filterFields() |
|
| 1438 | |||
| 1439 | /** |
||
| 1440 | * Method getFilters used to return array of all binded filters to form fields. |
||
| 1441 | * |
||
| 1442 | * @return array |
||
| 1443 | */ |
||
| 1444 | 130 | public function getFilters() |
|
| 1453 | |||
| 1454 | /** |
||
| 1455 | * If lockFiltering is set to true then we will not |
||
| 1456 | * filter fields and mutate request data binded to fields. |
||
| 1457 | * |
||
| 1458 | * @return \Kris\LaravelFormBuilder\Form |
||
| 1459 | */ |
||
| 1460 | 1 | public function lockFiltering() |
|
| 1465 | |||
| 1466 | /** |
||
| 1467 | * Unlock fields filtering/mutating. |
||
| 1468 | * |
||
| 1469 | * @return \Kris\LaravelFormBuilder\Form |
||
| 1470 | */ |
||
| 1471 | public function unlockFiltering() |
||
| 1476 | |||
| 1477 | /** |
||
| 1478 | * Method isFilteringLocked used to check |
||
| 1479 | * if current filteringLocked property status is set to true. |
||
| 1480 | * |
||
| 1481 | * @return bool |
||
| 1482 | */ |
||
| 1483 | 130 | public function isFilteringLocked() |
|
| 1487 | |||
| 1488 | /** |
||
| 1489 | * Method getRawValues returns Unfiltered/Unmutated fields -> values. |
||
| 1490 | * |
||
| 1491 | * @return array |
||
| 1492 | */ |
||
| 1493 | public function getRawValues() |
||
| 1502 | } |
||
| 1503 |
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: