Created
February 6, 2013 15:19
-
-
Save opi/4723213 to your computer and use it in GitHub Desktop.
Drupal: Mimic menu_attributes behavior to add a "CSS classes" textfield to menu item form.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| <?php | |
| /** | |
| * Implements hook_form_FORM_ID_alter(). | |
| * | |
| * Adds menu 'class' attribute options to the edit menu item form. | |
| */ | |
| function mymodule_form_menu_edit_item_alter(&$form, $form_state) { | |
| // Get item | |
| $item = $form['original_item']['#value']; | |
| // Get class default value | |
| if (isset($item['options']['attributes']) && isset($item['options']['attributes']['class'])) { | |
| $default_value = $item['options']['attributes']['class']; | |
| } | |
| else {$default_value = '';} | |
| // Change 'options' type | |
| $form['options'] = array( | |
| '#type' => 'item', | |
| '#tree' => TRUE, | |
| '#weight' => 50 | |
| ); | |
| // Create attributes item | |
| $form['options']['attributes'] = array('#type' => 'item', '#tree' => TRUE); | |
| // Add class textfield & item | |
| $form['options']['attributes']['class'] = array( | |
| '#type' => 'textfield', | |
| '#title' => t("CSS classes"), | |
| '#default_value' => $default_value, | |
| '#description' => t("Enter CSS classes, separated by spaces.") | |
| ); | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment