You are here

function ctm_form_alter in Menu Settings per Content Type 5

Same name and namespace in other branches
  1. 6.2 ctm.module \ctm_form_alter()
  2. 6 ctm.module \ctm_form_alter()

Implementation of hook_form_alter(). Menu Settings for Content Type.

File

./ctm.module, line 11

Code

function ctm_form_alter($form_id, &$form) {

  // Menu Setting for content types - Content Type Form
  if ($form_id == 'node_type_form') {
    $form['menu_settings'] = array(
      '#type' => 'fieldset',
      '#title' => t('Menu Settings'),
      '#description' => t('Enable Menu Settings for this content type.'),
      '#collapsible' => TRUE,
    );
    $default_values = variable_get($form['#node_type']->type . '_menu_settings', array());
    $options = menu_get_root_menus();
    $form['menu_settings']['menu'] = array(
      '#type' => 'checkboxes',
      '#title' => t('Enable the Menus you want to be available for this Content Type'),
      '#default_value' => $default_values,
      '#options' => $options,
    );
    $form['#submit']['ctm_node_type_form_submit'] = array();
  }
  elseif (isset($form['#node']) && $form['#node']->type . '_node_form' == $form_id) {
    $menu_settings = variable_get($form['#node']->type . '_menu_settings', array());
    if ($menu_settings) {
      $menus = array_intersect_key(menu_get_root_menus(), $menu_settings);
      $options = array();
      foreach ($menus as $key => $value) {
        $options += menu_parent_options($form['menu']['mid']['#value'], $key);
      }
      $form['menu']['pid']['#options'] = $options;
    }
    else {
      unset($form['menu']);
    }
  }
  elseif ($form_id == 'node_type_delete_confirm') {
    $form['#submit']['ctm_node_type_delete_confirm'] = array();
  }
}