You are here

function auto_menutitle_form_alter in Auto Menu Title 6.2

Implementation of hook_form_alter().

File

./auto_menutitle.module, line 24
Allows the menu title field to be automatically populated with the contents written into the node Title field

Code

function auto_menutitle_form_alter(&$form, $form_state, $form_id) {
  if (isset($form['#node_type']) && 'node_type_form' == $form_id) {
    auto_menutitle_node_settings_form($form);
  }
  elseif (isset($form['#node']) && isset($form['#method']) && $form['#node']->type . '_node_form' == $form_id) {
    $default_option = auto_menutitle_get_default_setting($form['#node']->type);
    $option = auto_menutitle_get_setting($form['#node']);
    $form['menu']['#collapsed'] = variable_get('amt_collapsed_' . $form['#node']->type, FALSE);
    if (!empty($default_option) && $default_option != AUTO_MENUTITLE_DISABLED) {
      $form['menu']['fixtitle'] = array(
        '#type' => 'checkbox',
        '#default_value' => $default_option == AUTO_MENUTITLE_ENABLED_ON || $default_option == AUTO_MENUTITLE_ENABLED_PATTERN_ON || $option,
        '#weight' => -1,
        '#title' => t('Automatically update Menu Title'),
        '#description' => t('To allow editing of the Menu title, simply un-check this option.'),
      );
      $form['menu']['link_title']['#weight'] = -2;
      if ($option == AUTO_MENUTITLE_ENABLED_ON || $option == AUTO_MENUTITLE_ENABLED_PATTERN_ON) {
        $form['menu']['link_title']['#attributes'] = array(
          'readonly' => 'readonly',
        );
      }

      // if we're on a node edit form and the automenu state is off or the setting has been set off for this menu item, then lets disable everything
      if (!empty($form['nid']['#value']) && !$form['#node']->menu['automenu_state'] && !$option) {
        $form['menu']['fixtitle']['#default_value'] = FALSE;
        $form['menu']['link_title']['#attributes'] = array();
      }
      $form['#after_build'][] = 'auto_menutitle_after_build';
    }
  }
}