Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

FormHelper - merge $_inputDefaults with options['inputDefaults'] #1928

Closed
ghost opened this issue Oct 11, 2013 · 6 comments
Closed

FormHelper - merge $_inputDefaults with options['inputDefaults'] #1928

ghost opened this issue Oct 11, 2013 · 6 comments

Comments

@ghost
Copy link

ghost commented Oct 11, 2013

Created by Ricky Dunlop, 5th Jan 2012. (originally Lighthouse ticket #2438):


What I did

I extended the FormHelper in order to set inputDefaults for every form so that I don't have to pass the settings in the view each time.

In my helper I have the following

    protected $_inputDefaults = array(
        'div' => 'control-group',
        'between' => '<div class="controls">',
        'after' => '</div>'
    );

What happened

The inputDefaults were not merged

In order to get this to work I had to copy the entire create method from the FormHelper to my helper and change line 363 from

$this->_inputDefaults = $options['inputDefaults'];

to

$this->_inputDefaults = array_merge($this->_inputDefaults, $options['inputDefaults']);
@ghost
Copy link
Author

ghost commented Oct 11, 2013

5th Jan 2012, Tigran Gabrielyan said:


You could have done

public function create($model = null, $options = array()) {
    if (isset($options['inputDefaults'])) {
         $options['inputDefaults'] = array_merge($this->_inputDefaults, $options['inputDefaults']);
    }

    return parent::create($model, $options);
}

No need to copy the whole method over.

@ghost
Copy link
Author

ghost commented Oct 11, 2013

5th Jan 2012, Tigran Gabrielyan said:


I think you need something more like:

public function create($model = null, $options = array()) {
    if (!isset($options['inputDefaults'])) {
        $options['inputDefaults'] = array();
    }

    $options['inputDefaults'] = array_merge($this->_inputDefaults, $options['inputDefaults']);

    return parent::create($model, $options);
}

.. you get the idea :P

@ghost
Copy link
Author

ghost commented Oct 11, 2013

5th Feb 2013, Charles Gold said:


After following the "patch" advice from Tigran...

I am getting the following error in my view, any help?
Notice (8): Array to string conversion [CORE\Cake\View\Helper.php, line 486]

See attached customized "MyFormHelper.php"

@ravage84
Copy link
Member

The FormHelper has been improved vastly in 3.0 and as probably nobody is motivated to implement that patch into the core, we can close this issue.

@ADmad
Copy link
Member

ADmad commented Mar 19, 2014

You can use FormHelper::inputDefaults() with merge param true to achieve similar result.

@ADmad ADmad closed this as completed Mar 19, 2014
@ravage84
Copy link
Member

😫 shouldn't work on issues deep in the night ;-)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants