zendframework/zf2 — pull request #1708 by bakura10 (2012-07-02 21:42:53+00:00)
Title: Use options in Forms (BC)

While creating new and more complex elements for Forms, I realized that we ended to set everything (from label, to captcha or even element) in the attributes array, which does not make sense as attributes imply attributes in the term of HTML attributes, and it was hard to maintain.

This PR makes the attributes array to be used only for HTML attributes, while options have to be set in an option array. The only exception is when using label for options in multi element as it would make it hard to use.

Here are the BC it implies :

1) Two elements were created (MultiCheckbox and Radio), and you have to use these elements explicitly (and not Element) as the view helpers for these elements relies on options that are not set in the base Element.

Therefore, this does not work anymore :

$this->add(array(
'name' => 'radio',
'attributes' => array(
'options' => array(...)
)
);

and has to be replaced by :

$this->add(array(
'type' => 'Zend\Form\Element\Radio',
'name' => 'oneRadio',
'options' => array(
'label' => 'One Radio',
'use_hidden_element' => false,
'unchecked_value' => 'none',
'label_attributes' => array('class' => 'toto')
),
'attributes' => array(...)
)

The same for MultiCheckbox.

2) Label have to be set either through the setLabel function, or using the factory :

$this->add(array(
'name' => 'element',
'options' => array(
'label' => 'One label'
),
'attributes' => array(
// Only HTML attributes
'class' => 'one two',
'type' => 'email'
)

4) Most of the keys have been updated to use underscore (labelAttributes becomes label_attributes, targetElement becomes target_element...).

And question : I wonder if hydrator, fieldsets and elements should be options for Form/Fieldset ?