I'm using ExpressionEngine for a multi-language website with products. I used Transcribe for controlling the multi-language. Products have the same title in different languages, and this gives me some problems selecting the correct product in a relationship field.
The builder of this site did not use the title
for a unique name in the back-end only, but also displayed it everywhere in the front-end.
Dropdown example:
I found that the dropdown information is filled in /system/expressionengine/fieldtypes/rel/ft.rel.php
from line 59
/**
* Display Relationship Field
*
* @access public
* @param string
* @return string
*/
function display_field($data)
{
if ($this->settings['field_related_orderby'] == 'date')
{
$this->settings['field_related_orderby'] = 'entry_date';
}
$this->EE->db->select('entry_id, title');
$this->EE->db->where('channel_id', $this->settings['field_related_id']);
$this->EE->db->order_by($this->settings['field_related_orderby'], $this->settings['field_related_sort']);
if ($this->settings['field_related_max'] > 0)
{
$this->EE->db->limit($this->settings['field_related_max']);
}
$relquery = $this->EE->db->get('channel_titles');
if ($relquery->num_rows() == 0)
{
return $this->EE->lang->line('no_related_entries');
}
else
{
if ( ! isset($_POST[$this->field_name]))
{
$this->EE->db->select('rel_child_id');
$relentry = $this->EE->db->get_where('relationships', array('rel_id' => $data));
if ($relentry->num_rows() == 1)
{
$data = $relentry->row('rel_child_id') ;
}
}
$field_options[''] = '--';
foreach ($relquery->result_array() as $relrow)
{
$field_options[$relrow['entry_id']] = $relrow['title'];
}
return form_dropdown($this->field_name, $field_options, $data, 'id="field_id_'.$this->field_id.'"');
}
}
How can I add the language name to the dropdown at line 98 ($field_options[$relrow['entry_id']] = $relrow['title'];)
?
Transcribe did not found any possibilities in Expression Engine 2.5. I created a workaround and added the url_title in the dropdown menu. It is not the best solution, but in this case it is workable.
$this->EE->db->select('entry_id, title');
changed into
$this->EE->db->select('entry_id, title, url_title');
And changed
$field_options[$relrow['entry_id']] = $relrow['title'];
into
$field_options[$relrow['entry_id']] = $relrow['title'] . " - " . $relrow['url_title'];