You are here

function flag_lists_form_alter in Flag Lists 6

Same name and namespace in other branches
  1. 8 flag_lists.module \flag_lists_form_alter()
  2. 7.3 flag_lists.module \flag_lists_form_alter()
  3. 7 flag_lists.module \flag_lists_form_alter()
  4. 4.0.x flag_lists.module \flag_lists_form_alter()

Implementation of hook_form_alter().

File

./flag_lists.module, line 246
The Flag Lists module.

Code

function flag_lists_form_alter(&$form, $form_state, $form_id) {
  switch ($form_id) {
    case 'flag_form':

      // A template flag should always have a record in the flag_lists_types table.
      $result = db_query("SELECT * FROM {flag_lists_types}");
      while ($type = db_fetch_array($result)) {
        $types[$type['name']] = $type['type'];
      }
      if (isset($types[$form['name']['#default_value']])) {
        $form['name']['#type'] = 'value';
        $form['global']['#type'] = 'value';
        $form['title']['#description'] = t('A short, descriptive title for this template. It will be used in administrative interfaces to refer to this template.');

        // Warn about types that already have a template.
        foreach ($form['access']['types']['#options'] as $option => $value) {
          if (in_array($option, $types) && $form['access']['types']['#default_value'] != $option) {
            $form['access']['types']['#options'][$option] .= '<span class="description">' . t(' (Already has a template.) ') . '</span>';
          }
        }
        $form['access']['types']['#description'] .= t(' A type may only be selected in one list template.');

        // Unset anon permissions for now. @todo allow anon listing.
        unset($form['access']['roles']['flag']['#options'][1]);
        unset($form['access']['roles']['unflag']['#options'][1]);
        foreach (element_children($form['display']) as $display) {
          $form['display'][$display]['#type'] = 'value';
        }
        $form['display']['link_type']['#default_value'] = 'fl_template';
        $form['display']['#description'] = t('Unlike normal flags, lists are only displayed in a block provided by this module or in views blocks. See <a href="/admin/build/block/list">the block admin page</a> to place the block.');
        $form['#validate'][] = 'flag_lists_template_validate';
        $form['#submit'][] = 'flag_lists_template_submit';
      }
      break;
  }
}