Author Topic: Extra fields in "edit identity" form  (Read 5592 times)

Offline marco-shagrat

  • Jr. Member
  • **
  • Posts: 10
Extra fields in "edit identity" form
« on: May 22, 2015, 04:36:17 AM »
Hi all,
  i need to add a custom field to the identity form.

I did a plugin that interacts with "identity_form" hook. All is working well (the extra field is correctly displayed) but i have problems with localization.

My plugin adds a my custom field to the "original form" array:

Code: [Select]
Array
(
    [form] => Array
        (
            [addressing] => Array
                (
                    [name] => Impostazioni
                    [content] => Array
                        (
                            [name] => Array
                                (
                                    [type] => text
                                    [size] => 40
                                )
            .....
            [extra_fields] => Array
                (
                    [name] => Extra fields
                    [content] => Array
                        (
                            [my_extra_field] => Array
                                (
                                    [type] => text
                                    [size] => 40
                                )
.....
)

in the localization folder i added my localization file that contains

Code: [Select]
  ...
  $labels['my_extra_field'] = 'My extra field';
  ...

but in the form the field label is displayed like [my_extra_field]

If i add the $labels['my_extra_field'] = 'My extra field'; row in the general localization file (under program/localization/...) the field label is translated.

How can i solve this problem?

Any help is really appreciated!


Offline SKaero

  • Administrator
  • Hero Member
  • *****
  • Posts: 5,879
    • SKaero - Custom Roundcube development
Re: Extra fields in "edit identity" form
« Reply #1 on: May 23, 2015, 12:54:09 PM »
Are you loading the new localization file?

Offline marco-shagrat

  • Jr. Member
  • **
  • Posts: 10
Re: Extra fields in "edit identity" form
« Reply #2 on: May 23, 2015, 03:06:25 PM »
Yes,
  in the init method.

Code: [Select]
$this->add_texts('localization/', true);


Offline SKaero

  • Administrator
  • Hero Member
  • *****
  • Posts: 5,879
    • SKaero - Custom Roundcube development
Re: Extra fields in "edit identity" form
« Reply #3 on: May 24, 2015, 01:23:19 AM »
What is the file name that the you've put the localization in? How are you using the localized text?

Offline marco-shagrat

  • Jr. Member
  • **
  • Posts: 10
Re: Extra fields in "edit identity" form
« Reply #4 on: May 24, 2015, 10:23:03 AM »
Here the partial code of my plugin (it may help):

Code: [Select]
function init()
{
$this->add_texts('localization/', true); //in this directory there are two files called it_IT.ing and en_US.inc (this is mandatory reading the documentation)

$this->load_config('config.inc.php');

$this->add_hook('identity_form', array($this, 'add_identity_extra_fields'));
}

function add_identity_extra_fields($data)
{
$rcmail = rcmail::get_instance();

$db = $rcmail->db;

$query_params = array($data['record']['user_id']);

$query = '';

$query .= 'SELECT my_extra_field FROM .... ';

$result = $db->query($query, $query_params)->fetchAll();

$my_extra_field_value = count($result) ? $result[0]['my_extra_field'] : '';

$data['form']['extra_fields']['name'] = $this->gettext('extra_fields'); // this label is correctly translated

$data['form']['extra_fields']['content'] =
array('my_extra_field' => array('type' => 'text', 'size' => 40));

$data['record']['my_extra_field'] = $my_extra_field_value;  //the "my_extra_field" label is not translated but the translation exists in it_IT.inc and en_US.inc

return $data;
}


if I put the translation in "program/localization/it_IT/labels.inc" the label is correctly displayed.

Offline JohnDoh

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 2,850
Re: Extra fields in "edit identity" form
« Reply #5 on: May 25, 2015, 03:16:22 AM »
You should put the localization file for you plugin in you plugin folder not append it to the core files. See http://trac.roundcube.net/wiki/Doc_Plugins#Internationalization
Roundcube Plugins: Contextmenu, SpamAssassin Prefs, and moreā€¦

Offline marco-shagrat

  • Jr. Member
  • **
  • Posts: 10
Re: Extra fields in "edit identity" form
« Reply #6 on: May 26, 2015, 12:50:22 PM »
My localization file IS in the localization folder of the plugin but does not work for that specific label
In my previous post there is a description where local plugin localization works and where it does not work.

Offline alec

  • Hero Member
  • *****
  • Posts: 1,365
Re: Extra fields in "edit identity" form
« Reply #7 on: May 27, 2015, 02:34:12 AM »
Try 'plugin_name.my_extra_field' instead.

Offline marco-shagrat

  • Jr. Member
  • **
  • Posts: 10
Re: Extra fields in "edit identity" form
« Reply #8 on: May 27, 2015, 11:20:31 AM »
I already tried this solution. Unfortunately it does not work.

The field name ('<input name="..") changes (this is not a problem) but the label is still displayed in square brackets not translated.