You are here

function newsletter_taxonomy_vocabulary_insert in Newsletter 7

Same name and namespace in other branches
  1. 7.2 newsletter.module \newsletter_taxonomy_vocabulary_insert()

Implements hook_taxonomy_vocabulary_insert().

File

./newsletter.module, line 421
Defines menu items for newsletter administration, permissions and basic drupal hooks.

Code

function newsletter_taxonomy_vocabulary_insert($vocabulary) {

  // Avoid conflict with standard installation profile.
  // Also don't create field for the Newsletter Categories vocabulary.
  if ($vocabulary->machine_name == 'tags' && $vocabulary->vid == 2 || $vocabulary->machine_name == 'newsletter_categories') {
    return;
  }

  // Field names have 32 char limit.
  $field_name = 'field_' . substr($vocabulary->machine_name, 0, 26);
  $field = array(
    'field_name' => $field_name,
    'type' => 'taxonomy_term_reference',
    'cardinality' => FIELD_CARDINALITY_UNLIMITED,
    'settings' => array(
      'allowed_values' => array(
        array(
          'vocabulary' => $vocabulary->machine_name,
          'parent' => 0,
        ),
      ),
    ),
  );
  field_create_field($field);
  $instance = array(
    'field_name' => $field_name,
    'entity_type' => 'newsletter_template',
    'bundle' => 'newsletter_template',
    'label' => $vocabulary->name,
    'widget' => array(
      'weight' => 0,
      'type' => 'options_select',
    ),
  );
  field_create_instance($instance);
}