function _quotes_taxonomy_fields in Quotes 7
Install a default vocabulary for quotes.
2 calls to _quotes_taxonomy_fields()
- quotes_install in ./
quotes.install - Implements hook_install().
- quotes_update_7001 in ./
quotes.install - Update taxonomy or add a default vocabulary for quotes.
File
- ./
quotes.install, line 385 - Handles installation and updates for the quotes module.
Code
function _quotes_taxonomy_fields() {
// Create a default vocabulary named "Quotes" for our content.
$description = st('A Collection of Quotes.');
$help = st('Enter a single or comma-separated list of words to categorize this quote.');
// Get only the quotes module vocabulary.
$vid = db_query('SELECT vid FROM {taxonomy_vocabulary} WHERE name = :name', array(
':name' => 'quotes',
))
->fetchField();
if ($vid) {
db_update('taxonomy_vocabulary')
->fields(array(
'name' => st('Quotes'),
'description' => $description,
'machine_name' => 'quotes',
))
->condition('vid', $vid)
->execute();
// Get our vocabulary by our new machine_name.
$vocabulary = taxonomy_vocabulary_machine_name_load('quotes');
}
else {
$vocabulary = (object) array(
'name' => st('Quotes'),
'description' => $description,
'machine_name' => 'quotes',
'help' => $help,
);
taxonomy_vocabulary_save($vocabulary);
}
$field = array(
'field_name' => 'taxonomy_' . $vocabulary->machine_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);
$instance = array(
'field_name' => 'taxonomy_' . $vocabulary->machine_name,
'entity_type' => 'node',
'label' => 'Category',
'bundle' => 'quotes',
'description' => $help,
'widget' => array(
'type' => 'taxonomy_autocomplete',
'weight' => -4,
),
'display' => array(
'default' => array(
'type' => 'taxonomy_term_reference_link',
'weight' => 10,
),
'teaser' => array(
'type' => 'taxonomy_term_reference_link',
'weight' => 10,
),
),
);
field_create_instance($instance);
}