You are here

function hashtags_form_field_ui_field_edit_form_alter in Hashtags 7

Implementation of hook_form_field_ui_field_edit_form_alter().

File

./hashtags.module, line 57

Code

function hashtags_form_field_ui_field_edit_form_alter(&$form, &$form_state) {
  $field_name = variable_get('hashtags_terms_field', 'field_hashtags');

  // Extract the instance info from the form.
  $instance = $form['#instance'];
  $entity_type = $instance['entity_type'];
  $bundle = $instance['bundle'];

  // for comments we check bundle of node that attached
  // to this comments
  if ($entity_type == 'comment') {
    $entity_type = 'node';

    // remove comment_node_ substring at the beginning
    $bundle = substr($bundle, 13);
  }

  // field module = 'text' + field_hashtags exists
  if ($form['#field']['module'] != 'text' || !_hashtags_is_field_exists($field_name, $entity_type, $bundle)) {
    return;
  }
  $hashtag_value = isset($instance['hashtag_settings']['hashtag_field']) ? $instance['hashtag_settings']['hashtag_field'] : FALSE;
  $form['instance']['hashtag_settings'] = array(
    '#type' => 'fieldset',
    '#title' => t('Hashtag settings'),
    '#description' => t('Track hashtags for this field'),
    '#weight' => 5,
    '#collapsible' => FALSE,
  );
  $form['instance']['hashtag_settings']['hashtag_field'] = array(
    '#type' => 'checkbox',
    '#title' => t('Enable this field for tracking hashtags'),
    '#default_value' => $hashtag_value,
  );
}