사용하지 않으려는 단일 항목을 빈 항목으로 변환하십시오 <optgroup>.
장점 :
- 이것은
hook_form_alter사용자 정의 양식을 작성할 때 또는 직접 수행 할 수 있으며 theme_select테마에서 기능 을 구현할 필요가 없습니다 .
단점 :
- 결과 DOM에서
value='title'원본과 관련된 속성 을 나타내는 방법은 없습니다 <option>.
- 이미 optgroup과 관련된 옵션을 비활성화하려는 경우 YMMV. 중첩 된 옵트 그룹은 실제로 작동하지만 테스트되지 않았으며 확인되지 않았습니다.
이행:
Drupal의 Optgroup 은 값 자체가 배열 인 쌍으로 #options배열 내부에 표시 key => value됩니다.
우리는 것 OP의 예에서 그래서 값 이동 t('Titles only')가 될를 key후하게 값은 빈 배열합니다.
$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.'),
);
결과 HTML은 다음과 같습니다.
<form>
<div>
<label>Display of XML feed items</label>
<select>
<optgroup>Titles only</optgroup>
<option value="teaser">Titles plus teaser</option>
<option value="fulltext">Full text</option>
</select>
</div>
</form>