Hi guys!
I have a content type, and that gots a field with organisation_name. This is a taxonomy_term vocabulary.
I also have a field in that content type with choose_own_name. There you can fill in your organisation if organisation_name == 'other'.
This is not the hard part for me. The real issue is: when rendering the page, i want to know if organisation_name == 'other'. If its false, then do nothing and display the taxonomy_term chosen. If its TRUE, then display on the position where the taxonomy_term should be, the value of choose_own_name.
Anyone some idea's? I already got a piece of code:
function youwe_diff_organisation_preprocess_node(&$variables){
if($variables['type'] == 'agenda_item') {
$field_organisator = $variables['field_organisator'][0]['taxonomy_term']->name;
if(strtolower($field_organisator) == 'other'){
//Do something like below and display it on the position where taxonomy should be standing
$variables['field_organisator'][0]['taxonomy_term']->name = $variables['field_andere_organisatie'][0]['value'];
} else {
//Do nothing and display the value of $field_organisator on its original place
}
}
}
Solution:
function youwe_diff_organisation_preprocess_field(&$variables){
if($variables['element']['#field_name'] == 'field_organisator'){
if(strtolower($variables['items'][0]['#markup']) == 'anders'){
$node_id = node_load($variables['element']['#object']->nid);
$new_value = $node_id->field_other_organisation['und'][0]['value'];
$variables['items'][0]['#markup'] = $new_value;
}
}
}
Comments
Why not simply use an auto
Why not simply use an auto complete widget for the taxonomy term and allow users to add organizations to the vocabulary.
We asked the client that too
We asked the client that too but they dont want that.
In that case I would not use
In that case I would not use a vocabulary and use the Select (or other) module.
This is the way the client
This is the way the client wants it, so i keep it like this. Its also good for practicing.
So how can i change it?