You are here

function hashtags_enable in Hashtags 7

Same name and namespace in other branches
  1. 6.2 hashtags.install \hashtags_enable()
  2. 6 hashtags.install \hashtags_enable()
  3. 7.2 hashtags.install \hashtags_enable()

Implementation of hook_enable().

File

./hashtags.install, line 9
Install, update and uninstall functions for the hashtags module.

Code

function hashtags_enable() {
  $vocabulary = taxonomy_vocabulary_load(variable_get('hashtags_vocabulary', 0));
  if (!$vocabulary) {
    $edit = array(
      'name' => t('Hashtags'),
      'machine_name' => 'hashtags',
      'description' => t('Hashtag vocabulary'),
      'hierarchy' => 1,
      'module' => 'hashtags',
      'weight' => -11,
    );
    $vocabulary = (object) $edit;
    taxonomy_vocabulary_save($vocabulary);
    variable_set('hashtags_vocabulary', $vocabulary->vid);
  }
  $field_name = 'field_' . $vocabulary->machine_name;
  if (!field_info_field($field_name)) {
    $field = array(
      'field_name' => $field_name,
      'type' => 'taxonomy_term_reference',
      // Set cardinality to unlimited for tagging.
      'cardinality' => FIELD_CARDINALITY_UNLIMITED,
      'settings' => array(
        'allowed_values' => array(
          array(
            'vocabulary' => $vocabulary->machine_name,
            'parent' => 0,
          ),
        ),
      ),
    );
    field_create_field($field);
    variable_set('hashtags_terms_field', $field_name);
    hashtags_add_filter();
    drupal_set_message('Hashtags module: go to ' . l(t('hashtags configuration page'), 'admin/config/content/hashtags') . ', check content types that you want Hashtags to work and submit a form');
  }
}