hook_form_alter #attributes and #disabled I'm using Drupal 7 and Advanced forum. 

The users when will create a new topic will be able to select the forum container and forums, but if they select a container, an error will be showed. I want to avoid this by altering that taxonomy options with adding an #attribute or #disabled to specific forum container.

As I inspect the elements, this is the option that I want to change:

$form['taxonomy_forums']['und']['#options'][334];

First of all I've tried to test by adding a class for that option like this:

$form['taxonomy_forums']['und']['#options'][334]['#attributes'] = array('class' =&gt; array('test-class'));


but that didn't worked, it simply erases the title of that option.

With #disabled it didn't work too.

From https://api.drupal.org/api/drupal/developer!topics!forms_api_reference.html/7#attributes

I can see a good example, but also a note:


  Note: If you are altering an existing form via hook_form_alter() or a
  similar means, be careful with this property! You will probably want
  to add to the existing array rather than writing over it, so don't
  follow this usage example exactly.


It's kind a confusing, so how can I add an #attribute or #disabled to option with hook_form_alter?

EDIT: This is a part from my code:

&lt;?php
function custom_alter_form_alter (&amp;$form, &amp;$form_state, $form_id) {
   switch ($form_id) {

        case 'forum_node_form';


        $form['taxonomy_forums']['und']['#process'][] = 'custom_alter_process_checkboxes';
        krumo ($form);
        break;
    }

}

function custom_alter_process_checkboxes($element) {
  $element[334]['#attributes']['class'][] = 'test-class';
  $element[334]['#disabled'] = TRUE;
  return $element;
  krumo ($element);
}
Checkboxes are converted to their individual form elements in form_process_checkboxes (), so you'll need a process function:

// In the form alter...
$form['taxonomy_forums']['und']['#process'][] = 'MYMODULE_process_checkboxes';

function MYMODULE_process_checkboxes($element) {
  $element[334]['#attributes']['class'][] = 'test-class';
  $element[334]['#disabled'] = TRUE;
  return $element;
}