FormHelper.php 1.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556
  1. <?php
  2. namespace Tools\View\Helper;
  3. use Cake\Core\Configure;
  4. use Cake\Utility\Hash;
  5. use Cake\View\Helper\FormHelper as CakeFormHelper;
  6. use Cake\View\View;
  7. /**
  8. * Overwrite
  9. *
  10. * @property \Cake\View\Helper\UrlHelper $Url
  11. * @property \Cake\View\Helper\HtmlHelper $Html
  12. */
  13. class FormHelper extends CakeFormHelper {
  14. /**
  15. * @var array<string, mixed>
  16. */
  17. protected $_defaultConfigExt = [
  18. 'novalidate' => false,
  19. ];
  20. /**
  21. * Construct the widgets and binds the default context providers
  22. *
  23. * @param \Cake\View\View $View The View this helper is being attached to.
  24. * @param array $config Configuration settings for the helper.
  25. */
  26. public function __construct(View $View, array $config = []) {
  27. $this->_defaultConfig += $this->_defaultConfigExt;
  28. $defaultConfig = (array)Configure::read('FormConfig');
  29. if ($defaultConfig) {
  30. $this->_defaultConfig = Hash::merge($this->_defaultConfig, $defaultConfig);
  31. }
  32. parent::__construct($View, $config);
  33. }
  34. /**
  35. * Overwrite to allow FormConfig Configure settings to be applied.
  36. *
  37. * @param mixed $model The context for which the form is being defined. Can
  38. * be an ORM entity, ORM resultset, or an array of meta data. You can use false or null
  39. * to make a model-less form.
  40. * @param array $options An array of html attributes and options.
  41. * @return string An formatted opening FORM tag.
  42. */
  43. public function create($model = null, array $options = []): string {
  44. $defaults = ['novalidate' => $this->_defaultConfig['novalidate']];
  45. $options += $defaults;
  46. return parent::create($model, $options);
  47. }
  48. }