You are here

function nodewords_form_alter in Nodewords: D6 Meta Tags 5

Same name and namespace in other branches
  1. 6 nodewords.module \nodewords_form_alter()

Implementation of hook_form_alter().

File

./nodewords.module, line 163
Assign META tags to nodes, vocabularies, terms and pages.

Code

function nodewords_form_alter($form_id, &$form) {
  if ($form_id == 'node_type_form' && isset($form['#node_type'])) {
    $form['workflow']['nodewords'] = array(
      '#type' => 'checkbox',
      '#title' => t('Allow editing of meta tags'),
      '#default_value' => variable_get('nodewords_' . $form['#node_type']->type, 1),
      '#description' => t('Users with the <em>edit meta tags</em> permission will be able to edit the meta tags for this content type.'),
    );
    return;
  }
  if (!user_access('edit meta tags')) {
    return;
  }
  if (isset($form['type']) && $form_id == $form['type']['#value'] . '_node_form') {
    if (variable_get('nodewords_' . $form['type']['#value'], 1)) {
      $type = 'node';
      $id = $form['nid']['#value'];
    }
  }
  elseif ($form_id == 'taxonomy_form_vocabulary') {
    $type = 'vocabulary';
    $id = $form['vid']['#value'];
    $form['submit']['#weight'] = 45;
    $form['delete']['#weight'] = 50;
  }
  elseif ($form_id == 'taxonomy_form_term') {
    $type = 'term';
    $id = $form['tid']['#value'];
    $form['submit']['#weight'] = 45;
    $form['delete']['#weight'] = 50;
  }
  elseif ($form_id == 'panels_edit_form') {
    $type = 'panels';
    $id = $form['did']['#value'];
    $form['submit']['#weight'] = 45;
    $form['#submit']['nodewords_panels_handler'] = array();
  }
  elseif ($form_id == 'panels_delete_confirm') {
    $form['#submit']['nodewords_panels_handler'] = array();
  }
  elseif ($form_id == 'panels_page_edit_form') {
    $panels_page = panels_page_get_current($form);
    $type = 'panels';
    $id = $panels_page['panel_page']['#value']->did;
    $form['submit']['#weight'] = 45;
    $form['#submit']['nodewords_panels_page_handler'] = array();
  }
  elseif ($form_id == 'panels_page_delete_confirm') {
    $form['#submit']['nodewords_panels_page_handler'] = array();
  }
  elseif ($form_id == 'views_edit_view') {
    $type = 'views';
    $id = $form['vid']['#value'];
    $form['save']['#weight'] = 40;
    $form['save_and_edit']['#weight'] = 45;
    if (isset($form['delete'])) {
      $form['delete']['#weight'] = 50;
    }
    $form['cancel']['#weight'] = 55;
    $form['#submit']['nodewords_views_handler'] = array();
  }
  elseif ($form_id == 'views_ui_admin_delete_confirm') {
    $form['#submit'] = array_merge(array(
      'nodewords_views_handler' => array(),
    ), (array) $form['#submit']);
  }
  if (isset($type)) {
    if (isset($id) && is_numeric($id)) {
      $tags = _nodewords_load($type, $id);
    }
    else {
      $tags = array();
    }
    $form['nodewords'] = _nodewords_form($type, $tags, !(isset($id) && is_numeric($id)));
  }
}