function uc_catalog_add_node_type in Ubercart 7.3
Same name and namespace in other branches
- 8.4 uc_catalog/uc_catalog.module \uc_catalog_add_node_type()
- 6.2 uc_catalog/uc_catalog.module \uc_catalog_add_node_type()
Adds a catalog taxonomy reference field to the specified node type.
4 calls to uc_catalog_add_node_type()
- uc_catalog_enable in uc_catalog/
uc_catalog.install - Implements hook_enable().
- uc_catalog_repair_field in uc_catalog/
uc_catalog.admin.inc - Repairs the catalog taxonomy field if it is lost or deleted.
- uc_catalog_uc_product_class in uc_catalog/
uc_catalog.module - Implements hook_uc_product_class().
- uc_product_kit_enable in uc_product_kit/
uc_product_kit.install - Implements hook_enable().
File
- uc_catalog/
uc_catalog.module, line 551 - Ubercart Catalog module.
Code
function uc_catalog_add_node_type($type) {
$vid = variable_get('uc_catalog_vid', 0);
if (!$vid) {
$vid = db_query("SELECT vid FROM {taxonomy_vocabulary} WHERE machine_name = 'catalog'")
->fetchField();
if (!$vid) {
$vocabulary = new stdClass();
$vocabulary->name = t('Catalog');
$vocabulary->description = '';
$vocabulary->hierarchy = 1;
$vocabulary->module = 'uc_catalog';
$vocabulary->machine_name = 'catalog';
taxonomy_vocabulary_save($vocabulary);
$vid = $vocabulary->vid;
}
variable_set('uc_catalog_vid', $vid);
}
$vocabulary = taxonomy_vocabulary_load($vid);
$field = field_info_field('taxonomy_catalog');
if (!$field) {
$field = array(
'field_name' => 'taxonomy_catalog',
'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 = field_info_instance('node', 'taxonomy_catalog', $type);
if (!$instance) {
$instance = array(
'field_name' => 'taxonomy_catalog',
'entity_type' => 'node',
'bundle' => $type,
'label' => t('Catalog'),
);
field_create_instance($instance);
}
}