function _scald_create_author_vocabulary in Scald: Media Management made easy 7
Create a vocabulary for storing Scald Authors, and the matching fields.
1 call to _scald_create_author_vocabulary()
- scald_enable in ./
scald.install - Implements hook_enable().
File
- ./
scald.install, line 366
Code
function _scald_create_author_vocabulary() {
field_associate_fields('taxonomy');
// Create the atom vocabulary if it does not exist.
$name = variable_get('scald_author_vocabulary', 'scald_authors');
$vocabulary = taxonomy_vocabulary_machine_name_load($name);
if (!$vocabulary) {
$edit = array(
'name' => t('Authors'),
'machine_name' => $name,
'description' => t('Scald authors vocabulary'),
'hierachy' => 0,
'module' => 'scald',
'weight' => -5,
);
$vocabulary = (object) $edit;
taxonomy_vocabulary_save($vocabulary);
variable_set('scald_author_vocabulary', $name);
// Create a URL field on the taxonomy terms of the Scald Authors
// bundle.
$field = array(
'field_name' => 'scald_author_url',
'type' => 'text',
'label' => t('URL'),
'locked' => TRUE,
);
field_create_field($field);
$instance = array(
'field_name' => 'scald_author_url',
'label' => t('URL'),
'entity_type' => 'taxonomy_term',
'bundle' => $name,
'required' => FALSE,
'description' => 'Homepage of the Author',
);
field_create_instance($instance);
}
// Create the scald_authors field.
if (!field_info_field('scald_authors')) {
$field = array(
'title' => t('Authors'),
'cardinality' => FIELD_CARDINALITY_UNLIMITED,
'field_name' => 'scald_authors',
'type' => 'taxonomy_term_reference',
'settings' => array(
'allowed_values' => array(
array(
'vocabulary' => $vocabulary->machine_name,
'parent' => 0,
),
),
),
);
field_create_field($field);
}
}