I've added a vocabulary(accommodation_type) in my accommodation module and referenced it to a field that I created in a (accommodation)content type I also created programmatically.
The Content type, the vocabulary AND the referencing field are all created. But when I create a term in the newly found Vocabulary it's not showing up in the dropdown field when I try to add content.
The weird part is: If I manually add a field to the Accommodation content-type. Or switch the Vocabulary of the existing referencing field to a different vocabulary and switch back to the accommodation_type vocabulary it works....
Howcome the terms I've added to my newly found Vocabulary are not showing up in the dropdown field of my content type?
Here's my complete module:
<?php
/**
* Implements hook_install().
*/
function accommodation_install() {
node_types_rebuild();
$types = node_type_get_types();
variable_set('comment_accommodation', '0');
node_add_body_field($types['accommodation']);
accommodation_add_vocabularies();
accommodation_add_custom_fields();
drupal_flush_all_caches();
}
function accommodation_add_vocabularies () {
foreach(_accommodation_get_vocabularies() as $voc) {
$vocabulary = (object) $voc;
taxonomy_vocabulary_save($vocabulary);
// Store the vid so we can delete the vocabulary later.
// Storing the vid is also useful for when we want to programmatically insert terms.
variable_set($vocabulary->machine_name . '_vid', $vocabulary->vid);
}
}
function accommodation_uninstall() {
$ournewtype = 'accommodation';
$sql = 'SELECT nid FROM {node} n WHERE n.type = :type';
$result = db_query($sql, array(':type' => $ournewtype));
$nodeids = array();
foreach ($result as $row) {
$nodeids[] = $row->nid;
}
node_delete_multiple($nodeids);
accommodation_delete_vocabularies();
accommodation_delete_custom_fields();
node_type_delete($ournewtype);
field_purge_batch(500);
}
function _accommodation_get_vocabularies () {
$t = get_t();
return array(
array(
'name' => $t('Accommodation type'),
'machine_name' => 'accommodation_type',
'description' => t('For example: Villa, chalet etc...'),
'module' => 'taxonomy',
),
);
}
function _accommodation_installed_fields() {
$t = get_t();
return array(
'accommodation_price' => array(
'field_name' => 'accommodation_price',
'label' => $t('Price of the accommodation'),
'type' => 'text'
),
'accommodation_type' => array(
'field_name' => 'accommodation_type',
'label' => $t('Accommodation type'),
'type' => 'taxonomy_term_reference',
'instance_settings' => array(
'allowed_values' => array(
array(
'vocabulary' => 'accommodation_type'
),
),
)
),
);
}
function _accommodation_installed_instances() {
$t = get_t();
return array(
'accommodation_price' => array(
'field_name' => 'accommodation_price',
'type' => 'text',
'label' => $t('Price of the accommodation'),
'widget' => array(
'type' => 'text_textfield'
),
'display' => array(
'example_node_list' => array(
'label' => $t('Price of the accommodation'),
'type' => 'text'
)
)
),
'accommodation_type' => array(
'field_name' => 'accommodation_type',
'entity_type' => 'node',
'label' => $t('Accommodation type'),
'bundle' => 'accommodation',
'required' => true,
'widget' => array(
'type' => 'options_select'
)
)
);
}
function accommodation_add_custom_fields() {
foreach (_accommodation_installed_fields() as $field) {
field_create_field($field);
}
foreach (_accommodation_installed_instances() as $fieldinstance) {
$fieldinstance['entity_type'] = 'node';
$fieldinstance['bundle'] = 'accommodation';
field_create_instance($fieldinstance);
}
}