ZF-8252: Allow for id attribute on optgroup elements
Zend_View_Helper_FormSelect does not allow optgroup elements to have an id attribute. Here is a patch that should allow for the following use case but should still be backwards compatible. This is not necessarily the best way to do this and could probably be a lot better: I put it together very quickly. The existing code doesn't seem to follow the Zend Framework coding standards so I kept my new code similar to the code that's already there. Again, this could be a lot more extensible than it is (e.g. it only allows for id and not class or other arbitrary decorators).
Here is the desired output:
Option AOption BOption COption D
Here is the use case that will give the desired output (with the patch applied):
$optgroupTest = new Zend_Form_Element_Select('optgroup_test'); $options = array ( array( 'id' => 'option_group_1', 'label' => 'Option Group 1', 'options' => array ( 'A' => 'Option A', 'B' => 'Option B', 'C' => 'Option C', ), ), array( 'id' => 'option_group_2', 'label' => 'Option Group 2', 'options' => array ( 'D' => 'Option D', ), ), ); $optgroupTest ->setLabel('Optgroup Test') ->addMultiOptions( $options ) ;