Convert the one single item you want to disable into an empty
- This can be done in a
hook_form_alter or directly when building your custom form, there is no need to implement a
theme_select function in your theme.
- There's no way to represent the
value='title' attribute associated with the original
<option> in the resulting DOM.
- YMMV if you're trying to disable an option that already pertains to an optgroup. Nested optgroups might indeed work, but this is untested and unconfirmed.
Optgroups in Drupal are denoted inside the
#options array as any
key => value pairs where the value is itself an array.
So from the example in the OP we would move the value of
t('Titles only') to become the
key and then make the value be an empty array.
$form['feed'] = array(
'#type' => 'select',
'#title' => t('Display of XML feed items'),
'#options' => array(
t('Titles only') => array(), // This one becomes disabled as an empty optgroup
'teaser' => t('Titles plus teaser'),
'fulltext' => t('Full text'),
'#description' => t('Global setting for the length of XML feed items that are output by default.'),
The resulting HTML will look something like this:
<label>Display of XML feed items</label>
<option value="teaser">Titles plus teaser</option>
<option value="fulltext">Full text</option>