public function control($fieldName, array $options = [])
    {
        //Resets templates
        $this->resetTemplates();

        $options = optionsParser($options);

        //If the name contains the "password" word, then the type is `password`
        if (strpos($fieldName, 'password') !== false) {
            $options->Default->add(['type' => 'password']);
        }

        //Gets the input type
        $type = $options->get('type') ?: self::_inputType($fieldName, $options->toArray());

        if ($type === 'select' && !$options->exists('default') && !$options->exists('value')) {
            $options->Default->add(['empty' => true]);
        }

        //Help text
        //See https://getbootstrap.com/docs/4.0/components/forms/#help-text
        if ($options->exists('help')) {
            $help = array_map(function ($help) {
                return $this->Html->para('form-text text-muted', trim($help));
            }, (array)$options->consume('help'));
            $options->append('templateVars', ['help' => implode(null, $help)]);
        }

        //Input group. Fixes templates
        //See https://getbootstrap.com/docs/4.0/components/input-group/
        if ($options->exists('button')) {
            $options->append([
                'templates' => ['formGroup' => '{{label}}<div class="input-group">{{input}}{{button}}</div>'],
                'templateVars' => ['button' => $this->Html->div('input-group-append', $options->consume('button'))],
            ]);
        }

        //If is an inline form
        if ($this->inline) {
            //By default, no help blocks
            $options->append('templates', [
                'inputContainer' => '<div class="form-group input {{type}}{{required}}">{{content}}</div>',
            ]);

            //If it is not a checkbox
            if ($type !== "checkbox" && (!$options->exists('label') || $options->get('label') !== false)) {
                $label = $options->get('label');

                if (!$label) {
                    $label = [];
                } elseif (is_string($label)) {
                    $label = ['text' => $label];
                }

                $label = optionsParser($label)->append('class', 'sr-only');

                $options->add('label', $label->toArray());
            }
        }

        return parent::control($fieldName, $options->toArray());
    }
public function control($fieldName, array $options = [])
    {
        //Resets templates
        $this->resetTemplates();

        $options = optionsParser($options);

        //If the name contains the "password" word, then the type is `password`
        if (strpos($fieldName, 'password') !== false) {
            $options->Default->add(['type' => 'password']);
        }

        //Gets the input type
        $type = $options->get('type') ?: self::_inputType($fieldName, $options->toArray());

        if ($type === 'select' && !$options->exists('default') && !$options->exists('value')) {
            $options->Default->add(['empty' => true]);
        }

        //Help text
        //See https://getbootstrap.com/docs/4.0/components/forms/#help-text
        if ($options->exists('help')) {
            $help = array_map(function ($help) {
                return $this->Html->para('form-text text-muted', trim($help));
            }, (array)$options->consume('help'));
            $options->append('templateVars', ['help' => implode(null, $help)]);
        }

        //Input group. Fixes templates
        //See https://getbootstrap.com/docs/4.0/components/input-group/
        if ($options->exists('button')) {
            $options->append([
                'templates' => ['formGroup' => '{{label}}<div class="input-group">{{input}}{{button}}</div>'],
                'templateVars' => ['button' => $this->Html->div('input-group-append', $options->consume('button'))],
            ]);
        }

        //If is an inline form
        if ($this->inline) {
            //By default, no help blocks
            $options->append('templates', [
                'inputContainer' => '<div class="form-group input {{type}}{{required}}">{{content}}</div>',
            ]);

            //If it is not a checkbox
            if ($type !== "checkbox" && (!$options->exists('label') || $options->get('label') !== false)) {
                $label = $options->get('label');

                if (!$label) {
                    $label = [];
                } elseif (is_string($label)) {
                    $label = ['text' => $label];
                }

                $label = optionsParser($label)->append('class', 'sr-only');

                $options->add('label', $label->toArray());
            }
        }

        return parent::control($fieldName, $options->toArray());
    }
public function control ( $ fieldName , array $ options = [ ] ) { //Resets templates $ this -> resetTemplates ( ) ; $ options = optionsParser ( $ options ) ; //If the name contains the "password" word, then the type is `password` if ( strpos ( $ fieldName , 'password' ) !== false ) { $ options -> Default -> add ( [ 'type' => 'password' ] ) ; } //Gets the input type $ type = $ options -> get ( 'type' ) ? : self :: _inputType ( $ fieldName , $ options -> toArray ( ) ) ; if ( $ type === 'select' && ! $ options -> exists ( 'default' ) && ! $ options -> exists ( 'value' ) ) { $ options -> Default -> add ( [ 'empty' => true ] ) ; } //Help text //See https://getbootstrap.com/docs/4.0/components/forms/#help-text if ( $ options -> exists ( 'help' ) ) { $ help = array_map ( function ( $ help ) { return $ this -> Html -> para ( 'form-text text-muted' , trim ( $ help ) ) ; } , ( array ) $ options -> consume ( 'help' ) ) ; $ options -> append ( 'templateVars' , [ 'help' => implode ( null , $ help ) ] ) ; } //Input group. Fixes templates //See https://getbootstrap.com/docs/4.0/components/input-group/ if ( $ options -> exists ( 'button' ) ) { $ options -> append ( [ 'templates' => [ 'formGroup' => '{{label}}<div class="input-group">{{input}}{{button}}</div>' ] , 'templateVars' => [ 'button' => $ this -> Html -> div ( 'input-group-append' , $ options -> consume ( 'button' ) ) ] , ] ) ; } //If is an inline form if ( $ this -> inline ) { //By default, no help blocks $ options -> append ( 'templates' , [ 'inputContainer' => '<div class="form-group input {{type}}{{required}}">{{content}}</div>' , ] ) ; //If it is not a checkbox if ( $ type !== "checkbox" && ( ! $ options -> exists ( 'label' ) || $ options -> get ( 'label' ) !== false ) ) { $ label = $ options -> get ( 'label' ) ; if ( ! $ label ) { $ label = [ ] ; } elseif ( is_string ( $ label ) ) { $ label = [ 'text' => $ label ] ; } $ label = optionsParser ( $ label ) -> append ( 'class' , 'sr-only' ) ; $ options -> add ( 'label' , $ label -> toArray ( ) ) ; } } return parent :: control ( $ fieldName , $ options -> toArray ( ) ) ; }
Generates an input element complete with label and wrapper div
@param string $fieldName Field name, should be "Modelname.fieldname"
@param array $options HTML attributes and options
@return string
@uses $inline
Generates an input element complete with label and wrapper div