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 | ]; |
||
| 52 | |||
| 53 | /** |
||
| 54 | * Form specific configuration. |
||
| 55 | * |
||
| 56 | * @var array |
||
| 57 | */ |
||
| 58 | protected $formConfig = []; |
||
| 59 | |||
| 60 | /** |
||
| 61 | * Additional data which can be used to build fields. |
||
| 62 | * |
||
| 63 | * @var array |
||
| 64 | */ |
||
| 65 | protected $data = []; |
||
| 66 | |||
| 67 | /** |
||
| 68 | * Wether errors for each field should be shown when calling form($form) or form_rest($form). |
||
| 69 | * |
||
| 70 | * @var bool |
||
| 71 | */ |
||
| 72 | protected $showFieldErrors = true; |
||
| 73 | |||
| 74 | /** |
||
| 75 | * Enable html5 validation. |
||
| 76 | * |
||
| 77 | * @var bool |
||
| 78 | */ |
||
| 79 | protected $clientValidationEnabled = true; |
||
| 80 | |||
| 81 | /** |
||
| 82 | * Name of the parent form if any. |
||
| 83 | * |
||
| 84 | * @var string|null |
||
| 85 | */ |
||
| 86 | protected $name = null; |
||
| 87 | |||
| 88 | /** |
||
| 89 | * @var FormBuilder |
||
| 90 | */ |
||
| 91 | protected $formBuilder; |
||
| 92 | |||
| 93 | /** |
||
| 94 | * @var ValidatorFactory |
||
| 95 | */ |
||
| 96 | protected $validatorFactory; |
||
| 97 | |||
| 98 | /** |
||
| 99 | * @var Validator |
||
| 100 | */ |
||
| 101 | protected $validator = null; |
||
| 102 | |||
| 103 | /** |
||
| 104 | * @var Request |
||
| 105 | */ |
||
| 106 | protected $request; |
||
| 107 | |||
| 108 | /** |
||
| 109 | * List of fields to not render. |
||
| 110 | * |
||
| 111 | * @var array |
||
| 112 | **/ |
||
| 113 | protected $exclude = []; |
||
| 114 | |||
| 115 | /** |
||
| 116 | * Wether the form is beign rebuild. |
||
| 117 | * |
||
| 118 | * @var bool |
||
| 119 | */ |
||
| 120 | protected $rebuilding = false; |
||
| 121 | |||
| 122 | /** |
||
| 123 | * @var string |
||
| 124 | */ |
||
| 125 | protected $templatePrefix; |
||
| 126 | |||
| 127 | /** |
||
| 128 | * @var string |
||
| 129 | */ |
||
| 130 | protected $languageName; |
||
| 131 | |||
| 132 | /** |
||
| 133 | * @var string |
||
| 134 | */ |
||
| 135 | protected $translationTemplate; |
||
| 136 | |||
| 137 | /** |
||
| 138 | * To filter and mutate request values or not. |
||
| 139 | * |
||
| 140 | * @var bool |
||
| 141 | */ |
||
| 142 | protected $lockFiltering = false; |
||
| 143 | |||
| 144 | /** |
||
| 145 | * Define the error bag name for the form. |
||
| 146 | * |
||
| 147 | * @var string |
||
| 148 | */ |
||
| 149 | protected $errorBag = 'default'; |
||
| 150 | |||
| 151 | /** |
||
| 152 | * Build the form. |
||
| 153 | * |
||
| 154 | * @return mixed |
||
| 155 | */ |
||
| 156 | 3 | public function buildForm() |
|
| 159 | |||
| 160 | /** |
||
| 161 | * Rebuild the form from scratch. |
||
| 162 | * |
||
| 163 | * @return $this |
||
| 164 | */ |
||
| 165 | 19 | public function rebuildForm() |
|
| 183 | |||
| 184 | /** |
||
| 185 | * Create the FormField object. |
||
| 186 | * |
||
| 187 | * @param string $name |
||
| 188 | * @param string $type |
||
| 189 | * @param array $options |
||
| 190 | * @return FormField |
||
| 191 | */ |
||
| 192 | 65 | protected function makeField($name, $type = 'text', array $options = []) |
|
| 206 | |||
| 207 | /** |
||
| 208 | * Create a new field and add it to the form. |
||
| 209 | * |
||
| 210 | * @param string $name |
||
| 211 | * @param string $type |
||
| 212 | * @param array $options |
||
| 213 | * @param bool $modify |
||
| 214 | * @return $this |
||
| 215 | */ |
||
| 216 | 67 | public function add($name, $type = 'text', array $options = [], $modify = false) |
|
| 228 | |||
| 229 | /** |
||
| 230 | * Add a FormField to the form's fields. |
||
| 231 | * |
||
| 232 | * @param FormField $field |
||
| 233 | * @return $this |
||
| 234 | */ |
||
| 235 | 61 | protected function addField(FormField $field, $modify = false) |
|
| 250 | |||
| 251 | /** |
||
| 252 | * Add field before another field. |
||
| 253 | * |
||
| 254 | * @param string $name Name of the field before which new field is added. |
||
| 255 | * @param string $fieldName Field name which will be added. |
||
| 256 | * @param string $type |
||
| 257 | * @param array $options |
||
| 258 | * @param bool $modify |
||
| 259 | * @return $this |
||
| 260 | */ |
||
| 261 | 1 | public function addBefore($name, $fieldName, $type = 'text', $options = [], $modify = false) |
|
| 276 | |||
| 277 | /** |
||
| 278 | * Add field before another field. |
||
| 279 | * |
||
| 280 | * @param string $name Name of the field after which new field is added. |
||
| 281 | * @param string $fieldName Field name which will be added. |
||
| 282 | * @param string $type |
||
| 283 | * @param array $options |
||
| 284 | * @param bool $modify |
||
| 285 | * @return $this |
||
| 286 | */ |
||
| 287 | 1 | public function addAfter($name, $fieldName, $type = 'text', $options = [], $modify = false) |
|
| 302 | |||
| 303 | /** |
||
| 304 | * Take another form and add it's fields directly to this form. |
||
| 305 | * |
||
| 306 | * @param mixed $class Form to merge. |
||
| 307 | * @param array $options |
||
| 308 | * @param boolean $modify |
||
| 309 | * @return $this |
||
| 310 | */ |
||
| 311 | 1 | public function compose($class, array $options = [], $modify = false) |
|
| 339 | |||
| 340 | /** |
||
| 341 | * Remove field with specified name from the form. |
||
| 342 | * |
||
| 343 | * @param $name |
||
| 344 | * @return $this |
||
| 345 | */ |
||
| 346 | 2 | public function remove($name) |
|
| 354 | |||
| 355 | /** |
||
| 356 | * Modify existing field. If it doesn't exist, it is added to form. |
||
| 357 | * |
||
| 358 | * @param string $name |
||
| 359 | * @param string $type |
||
| 360 | * @param array $options |
||
| 361 | * @param bool $overwriteOptions |
||
| 362 | * @return Form |
||
| 363 | */ |
||
| 364 | 1 | public function modify($name, $type = 'text', array $options = [], $overwriteOptions = false) |
|
| 376 | |||
| 377 | /** |
||
| 378 | * Render full form. |
||
| 379 | * |
||
| 380 | * @param array $options |
||
| 381 | * @param bool $showStart |
||
| 382 | * @param bool $showFields |
||
| 383 | * @param bool $showEnd |
||
| 384 | * @return string |
||
| 385 | */ |
||
| 386 | 7 | public function renderForm(array $options = [], $showStart = true, $showFields = true, $showEnd = true) |
|
| 390 | |||
| 391 | /** |
||
| 392 | * Render rest of the form. |
||
| 393 | * |
||
| 394 | * @param bool $showFormEnd |
||
| 395 | * @param bool $showFields |
||
| 396 | * @return string |
||
| 397 | */ |
||
| 398 | 1 | public function renderRest($showFormEnd = true, $showFields = true) |
|
| 404 | |||
| 405 | /** |
||
| 406 | * Renders the rest of the form up until the specified field name. |
||
| 407 | * |
||
| 408 | * @param string $field_name |
||
| 409 | * @param bool $showFormEnd |
||
| 410 | * @param bool $showFields |
||
| 411 | * @return string |
||
| 412 | */ |
||
| 413 | 2 | public function renderUntil($field_name, $showFormEnd = true, $showFields = true) |
|
| 433 | |||
| 434 | /** |
||
| 435 | * Get single field instance from form object. |
||
| 436 | * |
||
| 437 | * @param string $name |
||
| 438 | * @return FormField |
||
| 439 | */ |
||
| 440 | 35 | public function getField($name) |
|
| 448 | |||
| 449 | 101 | public function getErrorBag() |
|
| 453 | |||
| 454 | /** |
||
| 455 | * Check if form has field. |
||
| 456 | * |
||
| 457 | * @param string $name |
||
| 458 | * @return bool |
||
| 459 | */ |
||
| 460 | 61 | public function has($name) |
|
| 464 | |||
| 465 | /** |
||
| 466 | * Get all form options. |
||
| 467 | * |
||
| 468 | * @return array |
||
| 469 | */ |
||
| 470 | 2 | public function getFormOptions() |
|
| 474 | |||
| 475 | /** |
||
| 476 | * Get single form option. |
||
| 477 | * |
||
| 478 | * @param string $option |
||
| 479 | * @param mixed|null $default |
||
| 480 | * @return mixed |
||
| 481 | */ |
||
| 482 | 129 | public function getFormOption($option, $default = null) |
|
| 486 | |||
| 487 | /** |
||
| 488 | * Set single form option on form. |
||
| 489 | * |
||
| 490 | * @param string $option |
||
| 491 | * @param mixed $value |
||
| 492 | * |
||
| 493 | * @return $this |
||
| 494 | */ |
||
| 495 | 2 | public function setFormOption($option, $value) |
|
| 501 | |||
| 502 | /** |
||
| 503 | * Get the passed config key using the custom |
||
| 504 | * form config, if any. |
||
| 505 | * |
||
| 506 | * @param string $key |
||
| 507 | * @param mixed $default |
||
| 508 | * |
||
| 509 | * @return mixed |
||
| 510 | */ |
||
| 511 | 103 | public function getConfig($key = null, $default = null) |
|
| 515 | |||
| 516 | /** |
||
| 517 | * Set form options. |
||
| 518 | * |
||
| 519 | * @param array $formOptions |
||
| 520 | * @return $this |
||
| 521 | */ |
||
| 522 | 129 | public function setFormOptions(array $formOptions) |
|
| 536 | |||
| 537 | /** |
||
| 538 | * Get an option from provided options and call method with that value. |
||
| 539 | * |
||
| 540 | * @param string $name |
||
| 541 | * @param string $method |
||
| 542 | */ |
||
| 543 | 129 | protected function pullFromOptions($name, $method) |
|
| 549 | |||
| 550 | /** |
||
| 551 | * Get form http method. |
||
| 552 | * |
||
| 553 | * @return string |
||
| 554 | */ |
||
| 555 | 3 | public function getMethod() |
|
| 559 | |||
| 560 | /** |
||
| 561 | * Set form http method. |
||
| 562 | * |
||
| 563 | * @param string $method |
||
| 564 | * @return $this |
||
| 565 | */ |
||
| 566 | 1 | public function setMethod($method) |
|
| 572 | |||
| 573 | /** |
||
| 574 | * Get form action url. |
||
| 575 | * |
||
| 576 | * @return string |
||
| 577 | */ |
||
| 578 | 3 | public function getUrl() |
|
| 582 | |||
| 583 | /** |
||
| 584 | * Set form action url. |
||
| 585 | * |
||
| 586 | * @param string $url |
||
| 587 | * @return $this |
||
| 588 | */ |
||
| 589 | 1 | public function setUrl($url) |
|
| 595 | |||
| 596 | /** |
||
| 597 | * Returns the name of the form. |
||
| 598 | * |
||
| 599 | * @return string|null |
||
| 600 | */ |
||
| 601 | 69 | public function getName() |
|
| 605 | |||
| 606 | /** |
||
| 607 | * Set the name of the form. |
||
| 608 | * |
||
| 609 | * @param string $name |
||
| 610 | * @param bool $rebuild |
||
| 611 | * @return $this |
||
| 612 | */ |
||
| 613 | 12 | public function setName($name, $rebuild = true) |
|
| 623 | |||
| 624 | /** |
||
| 625 | * Get model that is bind to form object. |
||
| 626 | * |
||
| 627 | * @return mixed |
||
| 628 | */ |
||
| 629 | 96 | public function getModel() |
|
| 633 | |||
| 634 | /** |
||
| 635 | * Set model to form object. |
||
| 636 | * |
||
| 637 | * @param mixed $model |
||
| 638 | * @return $this |
||
| 639 | * @deprecated deprecated since 1.6.31, will be removed in 1.7 - pass model as option when creating a form |
||
| 640 | */ |
||
| 641 | 17 | public function setModel($model) |
|
| 649 | |||
| 650 | /** |
||
| 651 | * Setup model for form, add namespace if needed for child forms. |
||
| 652 | * |
||
| 653 | * @return $this |
||
| 654 | */ |
||
| 655 | 12 | protected function setupModel($model) |
|
| 662 | |||
| 663 | /** |
||
| 664 | * Get all fields. |
||
| 665 | * |
||
| 666 | * @return FormField[] |
||
| 667 | */ |
||
| 668 | 129 | public function getFields() |
|
| 672 | |||
| 673 | /** |
||
| 674 | * Get field dynamically. |
||
| 675 | * |
||
| 676 | * @param string $name |
||
| 677 | * @return FormField |
||
| 678 | */ |
||
| 679 | 20 | public function __get($name) |
|
| 685 | |||
| 686 | /** |
||
| 687 | * Check if field exists when fetched using magic methods. |
||
| 688 | * |
||
| 689 | * @param string $name |
||
| 690 | * @return bool |
||
| 691 | */ |
||
| 692 | public function __isset($name) |
||
| 696 | |||
| 697 | /** |
||
| 698 | * Set the Event Dispatcher to fire Laravel events. |
||
| 699 | * |
||
| 700 | * @param EventDispatcher $eventDispatcher |
||
| 701 | * @return $this |
||
| 702 | */ |
||
| 703 | 129 | public function setEventDispatcher(EventDispatcher $eventDispatcher) |
|
| 709 | |||
| 710 | /** |
||
| 711 | * Set the form helper only on first instantiation. |
||
| 712 | * |
||
| 713 | * @param FormHelper $formHelper |
||
| 714 | * @return $this |
||
| 715 | */ |
||
| 716 | 129 | public function setFormHelper(FormHelper $formHelper) |
|
| 722 | |||
| 723 | /** |
||
| 724 | * Get form helper. |
||
| 725 | * |
||
| 726 | * @return FormHelper |
||
| 727 | */ |
||
| 728 | 101 | public function getFormHelper() |
|
| 732 | |||
| 733 | /** |
||
| 734 | * Add custom field. |
||
| 735 | * |
||
| 736 | * @param $name |
||
| 737 | * @param $class |
||
| 738 | */ |
||
| 739 | 2 | public function addCustomField($name, $class) |
|
| 747 | |||
| 748 | /** |
||
| 749 | * Returns wether form errors should be shown under every field. |
||
| 750 | * |
||
| 751 | * @return bool |
||
| 752 | */ |
||
| 753 | 101 | public function haveErrorsEnabled() |
|
| 757 | |||
| 758 | /** |
||
| 759 | * Enable or disable showing errors under fields |
||
| 760 | * |
||
| 761 | * @param bool $enabled |
||
| 762 | * @return $this |
||
| 763 | */ |
||
| 764 | 1 | public function setErrorsEnabled($enabled) |
|
| 770 | |||
| 771 | /** |
||
| 772 | * Is client validation enabled? |
||
| 773 | * |
||
| 774 | * @return bool |
||
| 775 | */ |
||
| 776 | 101 | public function clientValidationEnabled() |
|
| 780 | |||
| 781 | /** |
||
| 782 | * Enable/disable client validation. |
||
| 783 | * |
||
| 784 | * @param bool $enable |
||
| 785 | * @return $this |
||
| 786 | */ |
||
| 787 | 2 | public function setClientValidationEnabled($enable) |
|
| 793 | |||
| 794 | /** |
||
| 795 | * Add any aditional data that field needs (ex. array of choices). |
||
| 796 | * |
||
| 797 | * @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 |
||
| 798 | * will be switched to protected in 1.7. |
||
| 799 | * @param string $name |
||
| 800 | * @param mixed $data |
||
| 801 | */ |
||
| 802 | 1 | public function setData($name, $data) |
|
| 806 | |||
| 807 | /** |
||
| 808 | * Get single additional data. |
||
| 809 | * |
||
| 810 | * @param string $name |
||
| 811 | * @param null $default |
||
| 812 | * @return mixed |
||
| 813 | */ |
||
| 814 | 20 | public function getData($name = null, $default = null) |
|
| 822 | |||
| 823 | /** |
||
| 824 | * Add multiple peices of data at once. |
||
| 825 | * |
||
| 826 | * @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 |
||
| 827 | * will be switched to protected in 1.7. |
||
| 828 | * @param $data |
||
| 829 | * @return $this |
||
| 830 | **/ |
||
| 831 | 129 | public function addData(array $data) |
|
| 839 | |||
| 840 | /** |
||
| 841 | * Get current request. |
||
| 842 | * |
||
| 843 | * @return \Illuminate\Http\Request |
||
| 844 | */ |
||
| 845 | 101 | public function getRequest() |
|
| 849 | |||
| 850 | /** |
||
| 851 | * Set request on form. |
||
| 852 | * |
||
| 853 | * @param Request $request |
||
| 854 | * @return $this |
||
| 855 | */ |
||
| 856 | 129 | public function setRequest(Request $request) |
|
| 862 | |||
| 863 | /** |
||
| 864 | * Get template prefix that is prepended to all template paths. |
||
| 865 | * |
||
| 866 | * @return string |
||
| 867 | */ |
||
| 868 | 39 | public function getTemplatePrefix() |
|
| 876 | |||
| 877 | /** |
||
| 878 | * Set a template prefix for the form and its fields. |
||
| 879 | * |
||
| 880 | * @param string $prefix |
||
| 881 | * @return $this |
||
| 882 | */ |
||
| 883 | 4 | public function setTemplatePrefix($prefix) |
|
| 889 | |||
| 890 | /** |
||
| 891 | * Get the language name. |
||
| 892 | * |
||
| 893 | * @return string |
||
| 894 | */ |
||
| 895 | 98 | public function getLanguageName() |
|
| 899 | |||
| 900 | /** |
||
| 901 | * Set a language name, used as prefix for translated strings. |
||
| 902 | * |
||
| 903 | * @param string $prefix |
||
| 904 | * @return $this |
||
| 905 | */ |
||
| 906 | 13 | public function setLanguageName($prefix) |
|
| 912 | |||
| 913 | /** |
||
| 914 | * Get the translation template. |
||
| 915 | * |
||
| 916 | * @return string |
||
| 917 | */ |
||
| 918 | 100 | public function getTranslationTemplate() |
|
| 922 | |||
| 923 | /** |
||
| 924 | * Set a translation template, used to determine labels for fields. |
||
| 925 | * |
||
| 926 | * @param string $template |
||
| 927 | * @return $this |
||
| 928 | */ |
||
| 929 | 11 | public function setTranslationTemplate($template) |
|
| 935 | |||
| 936 | /** |
||
| 937 | * Render the form. |
||
| 938 | * |
||
| 939 | * @param array $options |
||
| 940 | * @param string $fields |
||
| 941 | * @param bool $showStart |
||
| 942 | * @param bool $showFields |
||
| 943 | * @param bool $showEnd |
||
| 944 | * @return string |
||
| 945 | */ |
||
| 946 | 9 | protected function render($options, $fields, $showStart, $showFields, $showEnd) |
|
| 962 | |||
| 963 | /** |
||
| 964 | * Get template from options if provided, otherwise fallback to config. |
||
| 965 | * |
||
| 966 | * @return mixed |
||
| 967 | */ |
||
| 968 | 9 | protected function getTemplate() |
|
| 972 | |||
| 973 | /** |
||
| 974 | * Get all fields that are not rendered. |
||
| 975 | * |
||
| 976 | * @return array |
||
| 977 | */ |
||
| 978 | 2 | protected function getUnrenderedFields() |
|
| 991 | |||
| 992 | /** |
||
| 993 | * Prevent adding fields with same name. |
||
| 994 | * |
||
| 995 | * @param string $name |
||
| 996 | * @throws \InvalidArgumentException |
||
| 997 | * @return void |
||
| 998 | */ |
||
| 999 | 61 | protected function preventDuplicate($name) |
|
| 1005 | |||
| 1006 | /** |
||
| 1007 | * Returns and checks the type of the field. |
||
| 1008 | * |
||
| 1009 | * @param string $type |
||
| 1010 | * @return string |
||
| 1011 | */ |
||
| 1012 | 65 | protected function getFieldType($type) |
|
| 1018 | |||
| 1019 | /** |
||
| 1020 | * Check if form is named form. |
||
| 1021 | * |
||
| 1022 | * @return void |
||
| 1023 | */ |
||
| 1024 | 129 | protected function checkIfNamedForm() |
|
| 1030 | |||
| 1031 | /** |
||
| 1032 | * Set up options on single field depending on form options. |
||
| 1033 | * |
||
| 1034 | * @param string $name |
||
| 1035 | * @param $options |
||
| 1036 | */ |
||
| 1037 | 65 | protected function setupFieldOptions($name, &$options) |
|
| 1041 | |||
| 1042 | /** |
||
| 1043 | * Set namespace to model if form is named so the data is bound properly. |
||
| 1044 | * Returns true if model is changed, otherwise false. |
||
| 1045 | * |
||
| 1046 | * @return bool |
||
| 1047 | */ |
||
| 1048 | 21 | protected function setupNamedModel() |
|
| 1073 | |||
| 1074 | /** |
||
| 1075 | * Set form builder instance on helper so we can use it later. |
||
| 1076 | * |
||
| 1077 | * @param FormBuilder $formBuilder |
||
| 1078 | * @return $this |
||
| 1079 | */ |
||
| 1080 | 129 | public function setFormBuilder(FormBuilder $formBuilder) |
|
| 1086 | |||
| 1087 | /** |
||
| 1088 | * Returns the instance of the FormBuilder. |
||
| 1089 | * |
||
| 1090 | * @return FormBuilder |
||
| 1091 | */ |
||
| 1092 | 20 | public function getFormBuilder() |
|
| 1096 | |||
| 1097 | /** |
||
| 1098 | * Set the Validator instance on this so we can use it later. |
||
| 1099 | * |
||
| 1100 | * @param ValidatorFactory $validator |
||
| 1101 | * @return $this |
||
| 1102 | */ |
||
| 1103 | 129 | public function setValidator(ValidatorFactory $validator) |
|
| 1109 | |||
| 1110 | /** |
||
| 1111 | * Returns the validator instance. |
||
| 1112 | * |
||
| 1113 | * @return Validator |
||
| 1114 | */ |
||
| 1115 | 1 | public function getValidator() |
|
| 1119 | |||
| 1120 | /** |
||
| 1121 | * Exclude some fields from rendering. |
||
| 1122 | * |
||
| 1123 | * @return $this |
||
| 1124 | */ |
||
| 1125 | public function exclude(array $fields) |
||
| 1131 | |||
| 1132 | /** |
||
| 1133 | * If form is named form, modify names to be contained in single key (parent[child_field_name]). |
||
| 1134 | * |
||
| 1135 | * @param string $name |
||
| 1136 | * @return string |
||
| 1137 | */ |
||
| 1138 | 65 | protected function getFieldName($name) |
|
| 1155 | |||
| 1156 | /** |
||
| 1157 | * Disable all fields in a form. |
||
| 1158 | */ |
||
| 1159 | 1 | public function disableFields() |
|
| 1165 | |||
| 1166 | /** |
||
| 1167 | * Enable all fields in a form. |
||
| 1168 | */ |
||
| 1169 | 1 | public function enableFields() |
|
| 1175 | |||
| 1176 | /** |
||
| 1177 | * Validate the form. |
||
| 1178 | * |
||
| 1179 | * @param array $validationRules |
||
| 1180 | * @param array $messages |
||
| 1181 | * @return Validator |
||
| 1182 | */ |
||
| 1183 | 9 | public function validate($validationRules = [], $messages = []) |
|
| 1196 | |||
| 1197 | /** |
||
| 1198 | * Get validation rules for the form. |
||
| 1199 | * |
||
| 1200 | * @param array $overrideRules |
||
| 1201 | * @return array |
||
| 1202 | */ |
||
| 1203 | 1 | public function getRules($overrideRules = []) |
|
| 1209 | |||
| 1210 | /** |
||
| 1211 | * Redirects to a destination when form is invalid. |
||
| 1212 | * |
||
| 1213 | * @param string|null $destination The target url. |
||
| 1214 | * @return HttpResponseException |
||
| 1215 | */ |
||
| 1216 | 3 | public function redirectIfNotValid($destination = null) |
|
| 1230 | |||
| 1231 | /** |
||
| 1232 | * Get all form field attributes, including child forms, in a flat array. |
||
| 1233 | * |
||
| 1234 | * @return array |
||
| 1235 | */ |
||
| 1236 | 3 | public function getAllAttributes() |
|
| 1240 | |||
| 1241 | /** |
||
| 1242 | * Check if the form is valid. |
||
| 1243 | * |
||
| 1244 | * @return bool |
||
| 1245 | */ |
||
| 1246 | 9 | public function isValid() |
|
| 1260 | |||
| 1261 | /** |
||
| 1262 | * Optionally change the validation result, and/or add error messages. |
||
| 1263 | * |
||
| 1264 | * @param Form $mainForm |
||
| 1265 | * @param bool $isValid |
||
| 1266 | * @return void|array |
||
| 1267 | */ |
||
| 1268 | 9 | public function alterValid(Form $mainForm, &$isValid) |
|
| 1272 | |||
| 1273 | /** |
||
| 1274 | * Get validation errors. |
||
| 1275 | * |
||
| 1276 | * @return array |
||
| 1277 | */ |
||
| 1278 | 8 | public function getErrors() |
|
| 1291 | |||
| 1292 | /** |
||
| 1293 | * Get all Request values from all fields, and nothing else. |
||
| 1294 | * |
||
| 1295 | * @param bool $with_nulls |
||
| 1296 | * @return array |
||
| 1297 | */ |
||
| 1298 | 3 | public function getFieldValues($with_nulls = true) |
|
| 1321 | |||
| 1322 | /** |
||
| 1323 | * Optionally mess with this form's $values before it's returned from getFieldValues(). |
||
| 1324 | * |
||
| 1325 | * @param array $values |
||
| 1326 | * @return void |
||
| 1327 | */ |
||
| 1328 | 3 | public function alterFieldValues(array &$values) |
|
| 1331 | |||
| 1332 | /** |
||
| 1333 | * Throw an exception indicating a field does not exist on the class. |
||
| 1334 | * |
||
| 1335 | * @param string $name |
||
| 1336 | * @throws \InvalidArgumentException |
||
| 1337 | * @return void |
||
| 1338 | */ |
||
| 1339 | 2 | protected function fieldDoesNotExist($name) |
|
| 1343 | |||
| 1344 | /** |
||
| 1345 | * Method filterFields used as *Main* method for starting |
||
| 1346 | * filtering and request field mutating process. |
||
| 1347 | * |
||
| 1348 | * @return \Kris\LaravelFormBuilder\Form |
||
| 1349 | */ |
||
| 1350 | 129 | public function filterFields() |
|
| 1386 | |||
| 1387 | /** |
||
| 1388 | * Method getFilters used to return array of all binded filters to form fields. |
||
| 1389 | * |
||
| 1390 | * @return array |
||
| 1391 | */ |
||
| 1392 | 129 | public function getFilters() |
|
| 1401 | |||
| 1402 | /** |
||
| 1403 | * If lockFiltering is set to true then we will not |
||
| 1404 | * filter fields and mutate request data binded to fields. |
||
| 1405 | * |
||
| 1406 | * @return \Kris\LaravelFormBuilder\Form |
||
| 1407 | */ |
||
| 1408 | 1 | public function lockFiltering() |
|
| 1413 | |||
| 1414 | /** |
||
| 1415 | * Unlock fields filtering/mutating. |
||
| 1416 | * |
||
| 1417 | * @return \Kris\LaravelFormBuilder\Form |
||
| 1418 | */ |
||
| 1419 | public function unlockFiltering() |
||
| 1424 | |||
| 1425 | /** |
||
| 1426 | * Method isFilteringLocked used to check |
||
| 1427 | * if current filteringLocked property status is set to true. |
||
| 1428 | * |
||
| 1429 | * @return bool |
||
| 1430 | */ |
||
| 1431 | 129 | public function isFilteringLocked() |
|
| 1435 | |||
| 1436 | /** |
||
| 1437 | * Method getRawValues returns Unfiltered/Unmutated fields -> values. |
||
| 1438 | * |
||
| 1439 | * @return array |
||
| 1440 | */ |
||
| 1441 | public function getRawValues() |
||
| 1450 | } |
||
| 1451 |
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: