You are here

function newsletter_taxonomy_vocabulary_insert in Newsletter 7.2

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

Implements hook_taxonomy_vocabulary_insert().

File

./newsletter.module, line 125
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 = array(
    'field_name' => 'field_' . $vocabulary->machine_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_' . $vocabulary->machine_name,
    'entity_type' => 'newsletter_template',
    'bundle' => 'newsletter_template',
    'label' => $vocabulary->name,
    'widget' => array(
      'weight' => 0,
      'type' => 'options_select',
    ),
  );
  field_create_instance($instance);
}