From 0aa4fdbbb7eea7aa84e9f5dac009cb5fa8a745a1 Mon Sep 17 00:00:00 2001 From: Mikael Capelle Date: Tue, 31 Jan 2017 18:00:53 +0000 Subject: [PATCH 001/168] Start cleaning documentation. --- src/View/Helper/BootstrapFormHelper.php | 211 +++++++++++++------ src/View/Helper/BootstrapHtmlHelper.php | 130 +++++++----- src/View/Helper/BootstrapNavbarHelper.php | 36 ++-- src/View/Helper/BootstrapPaginatorHelper.php | 2 +- src/View/Helper/BootstrapTrait.php | 21 +- 5 files changed, 243 insertions(+), 157 deletions(-) diff --git a/src/View/Helper/BootstrapFormHelper.php b/src/View/Helper/BootstrapFormHelper.php index a1a0fa5..cbdf7da 100644 --- a/src/View/Helper/BootstrapFormHelper.php +++ b/src/View/Helper/BootstrapFormHelper.php @@ -105,7 +105,18 @@ class BootstrapFormHelper extends FormHelper { '_default' => ['Cake\View\Widget\BasicWidget'], ]; + /** + * Horizontal mode enabled/disabled. + * + * @var bool + */ public $horizontal = false; + + /** + * Inline mode enabled/disabled. + * + * @var bool + */ public $inline = false; /** @@ -113,11 +124,11 @@ class BootstrapFormHelper extends FormHelper { * Replace the templates with the ones specified by newTemplates, call the * specified function with the specified parameters, and then restore the old templates. * - * @params $templates The new templates - * @params $callback The function to call - * @params $params The arguments for the $callback function + * @params array $templates The new templates + * @params callable $callback The function to call + * @params array $params The arguments for the $callback function * - * @return The return value of $callback + * @return mixed The return value of $callback * **/ protected function _wrapTemplates ($templates, $callback, $params) { @@ -134,9 +145,9 @@ protected function _wrapTemplates ($templates, $callback, $params) { * * Try to match the specified HTML code with a button or a input with submit type. * - * @param $html The HTML code to check + * @param string $html The HTML code to check * - * @return true if the HTML code contains a button + * @return bool true if the HTML code contains a button * **/ protected function _matchButton ($html) { @@ -155,10 +166,10 @@ protected function _getDefaultTemplateVars (&$options) { 'h_formGroup_start' => '
', 'h_formGroup_end' => '
', 'h_checkboxContainer_start' => '
', + .' '.$this->_getColClass('input').'">', 'h_checkboxContainer_end' => '
', 'h_radioContainer_start' => '
', + .' '.$this->_getColClass('input').'">', 'h_radioContainer_end' => '
', 'h_submitContainer_start' => '
', 'h_submitContainer_end' => '
', @@ -187,23 +198,39 @@ protected function _inputContainerTemplate($options) { } /** + * Returns an HTML form element. * - * Create a Twitter Bootstrap like form. - * - * New options available: - * - horizontal: boolean, specify if the form is horizontal - * - inline: boolean, specify if the form is inline - * - search: boolean, specify if the form is a search form - * - * Unusable options: - * - inputDefaults - * - * @param $model The model corresponding to the form - * @param $options Options to customize the form - * - * @return The HTML tags corresponding to the openning of the form + * ### Options: * - **/ + * - `type` Form method defaults to autodetecting based on the form context. If + * the form context's isCreate() method returns false, a PUT request will be done. + * - `method` Set the form's method attribute explicitly. + * - `action` The controller action the form submits to, (optional). Use this option if you + * don't need to change the controller from the current request's controller. Deprecated since 3.2, use `url`. + * - `url` The URL the form submits to. Can be a string or a URL array. If you use 'url' + * you should leave 'action' undefined. + * - `encoding` Set the accept-charset encoding for the form. Defaults to `Configure::read('App.encoding')` + * - `enctype` Set the form encoding explicitly. By default `type => file` will set `enctype` + * to `multipart/form-data`. + * - `templates` The templates you want to use for this form. Any templates will be merged on top of + * the already loaded templates. This option can either be a filename in /config that contains + * the templates you want to load, or an array of templates to use. + * - `context` Additional options for the context class. For example the EntityContext accepts a 'table' + * option that allows you to set the specific Table class the form should be based on. + * - `idPrefix` Prefix for generated ID attributes. + * - `templateVars` Provide template variables for the formStart template. + * + * - `horizontal` - Boolean specifying if the form should be horizontal. + * - `inline` - Boolean specifying if the form should be inlined. + * - `search` - Boolean specifying if the form is a search form. + * + * @param mixed $model The context for which the form is being defined. Can + * be an ORM entity, ORM resultset, or an array of meta data. You can use false or null + * to make a model-less form. + * @param array $options An array of html attributes and options. + * @return string An formatted opening FORM tag. + * @link http://book.cakephp.org/3.0/en/views/helpers/form.html#Cake\View\Helper\FormHelper::create + */ public function create($model = null, Array $options = array()) { $options += [ 'columns' => $this->config('columns'), @@ -228,6 +255,11 @@ public function create($model = null, Array $options = array()) { * * Return the col size class for the specified column (label, input or error). * + * @param string $what + * @param bool $offset Add the offset prefix. + * + * @return string + * **/ protected function _getColClass ($what, $offset = false) { if ($what === 'error' @@ -251,12 +283,12 @@ protected function _wrapInputGroup ($addonOrButtons) { if (is_string($addonOrButtons)) { $addonOrButtons = $this->_makeIcon($addonOrButtons); $addonOrButtons = ''.$addonOrButtons.''; + ($this->_matchButton($addonOrButtons) ? + 'btn' : 'addon').'">'.$addonOrButtons.''; } else if ($addonOrButtons !== false) { $addonOrButtons = '' - .implode('', $addonOrButtons).''; + .implode('', $addonOrButtons).''; } } return $addonOrButtons; @@ -287,16 +319,37 @@ protected function _wrap ($input, $prepend, $append) { } /** - * - * Create & return an input block (Twitter Boostrap Like). - * - * New options: - * - prepend: - * -> string: Add before the input - * -> array: Add elements in array before inputs - * - append: Same as prepend except it add elements after input - * - **/ + * Generates a form input element complete with label and wrapper div + * + * ### Options + * + * See each field type method for more information. Any options that are part of + * $attributes or $options for the different **type** methods can be included in `$options` for input(). + * Additionally, any unknown keys that are not in the list below, or part of the selected type's options + * will be treated as a regular HTML attribute for the generated input. + * + * - `type` - Force the type of widget you want. e.g. `type => 'select'` + * - `label` - Either a string label, or an array of options for the label. See FormHelper::label(). + * - `options` - For widgets that take options e.g. radio, select. + * - `error` - Control the error message that is produced. Set to `false` to disable any kind of error reporting (field + * error and error messages). + * - `empty` - String or boolean to enable empty select box options. + * - `nestedInput` - Used with checkbox and radio inputs. Set to false to render inputs outside of label + * elements. Can be set to true on any input to force the input inside the label. If you + * enable this option for radio buttons you will also need to modify the default `radioWrapper` template. + * - `templates` - The templates you want to use for this input. Any templates will be merged on top of + * the already loaded templates. This option can either be a filename in /config that contains + * the templates you want to load, or an array of templates to use. + * - `prepend` - String or array of elements to prepend. + * - `append` - String or array of elements to append. + * - `help` - String containing an help message for the input. + * - `inline` + * + * @param string $fieldName This should be "modelname.fieldname" + * @param array $options Each type of input takes different options. + * @return string Completed form widget. + * @link http://book.cakephp.org/3.0/en/views/helpers/form.html#creating-form-inputs + */ public function input($fieldName, array $options = array()) { $options += [ @@ -424,7 +477,7 @@ public function file($fieldName, array $options = []) { ]; } } - + $fakeInput = $this->text($fieldName, array_merge($fakeInputCustomOptions, [ 'name' => $fieldName.'-text', 'readonly' => 'readonly', @@ -550,14 +603,21 @@ protected function _createButtonOptions (array $options = []) { } /** + * Creates a `