You are here

function auto_nodetitle_form_alter in Automatic Nodetitles 5

Same name and namespace in other branches
  1. 6 auto_nodetitle.module \auto_nodetitle_form_alter()
  2. 7 auto_nodetitle.module \auto_nodetitle_form_alter()

Implementation of hook_form_alter().

File

./auto_nodetitle.module, line 22
Allows hiding of the node title field and automatic title creation

Code

function auto_nodetitle_form_alter($form_id, &$form) {
  if (isset($form['#node_type']) && 'node_type_form' == $form_id) {
    auto_nodetitle_node_settings_form($form);
  }
  else {
    if (isset($form['#node']) && isset($form['#post']) && $form['#node']->type . '_node_form' == $form_id) {

      //this is a node form
      if (auto_nodetitle_get_setting($form['#node']->type) == AUTO_NODETITLE_ENABLED) {

        // we will autogenerate the title later, just hide the title field in the meanwhile
        $form['title']['#value'] = 'ant';
        $form['title']['#type'] = 'value';
        $form['title']['#required'] = FALSE;
      }
      else {
        if (auto_nodetitle_get_setting($form['#node']->type) == AUTO_NODETITLE_OPTIONAL) {

          // we will make the title optional
          $form['title']['#required'] = FALSE;
        }
      }
    }
  }
}