tests/user_relationships_test.info | 4 +
tests/user_relationships_test.module | 7 +
.../templates/user_relationships-block.tpl.php | 10 +-
.../user_relationships-pending_block.tpl.php | 6 +-
.../user_relationship_blocks.module | 16 +-
.../user_relationship_defaults.module | 11 +-
.../user_relationship_implications.module | 9 +-
.../user_relationship_invites.module | 2 +-
.../user_relationship_node_access.module | 6 +-
.../user_relationship_privatemsg.module | 4 +-
.../user_relationship_views.module | 2 +-
user_relationships.admin.inc | 156 +++++++++++++-------
user_relationships.author-pane.inc | 8 +-
user_relationships.i18n.inc | 64 ++++++++
user_relationships.install | 74 +++++++++-
user_relationships.module | 131 ++++++++++------
user_relationships.test | 52 +++++++
.../user_relationships_ui.forms.inc | 26 ++--
user_relationships_ui/user_relationships_ui.module | 31 ++--
.../user_relationships_ui.pages.inc | 8 +-
.../user_relationships_ui.theme.inc | 2 +-
21 files changed, 450 insertions(+), 179 deletions(-)
diff --git a/tests/user_relationships_test.info b/tests/user_relationships_test.info
new file mode 100644
index 0000000..e6eebf3
--- /dev/null
+++ b/tests/user_relationships_test.info
@@ -0,0 +1,4 @@
+name = User Relationships Test module
+description = Contains test hooks and soft dependencies for tests.
+
+dependencies[]=i18n
\ No newline at end of file
diff --git a/tests/user_relationships_test.module b/tests/user_relationships_test.module
new file mode 100644
index 0000000..3e558ca
--- /dev/null
+++ b/tests/user_relationships_test.module
@@ -0,0 +1,7 @@
+
diff --git a/user_relationship_blocks/templates/user_relationships-block.tpl.php b/user_relationship_blocks/templates/user_relationships-block.tpl.php
index 25a0449..2c1e3cd 100644
--- a/user_relationship_blocks/templates/user_relationships-block.tpl.php
+++ b/user_relationship_blocks/templates/user_relationships-block.tpl.php
@@ -8,16 +8,14 @@ if ($relationships) {
$showing_all_types = $settings->rtid == UR_BLOCK_ALL_TYPES;
$rows = array();
foreach ($relationships as $rtid => $relationship) {
- $tt_rel_name = ur_tt("user_relationships:rtid:$rtid:name", $relationship->name);
- $tt_rel_plural_name = ur_tt("user_relationships:rtid:$rtid:plural_name", $relationship->plural_name);
if ($the_other_uid == $relationship->requester_id) {
- $rtype_heading = $relationship->is_oneway ?
- t("@rel_name of", array('@rel_name' => $tt_rel_name, '@rel_plural_name' => $tt_rel_plural_name)) :
- t("@rel_plural_name", array('@rel_name' => $tt_rel_name, '@rel_plural_name' => $tt_rel_plural_name));
+ $rtype_heading = $relationship->is_oneway ?
+ t("@rel_name of", user_relationships_type_translations($relationship)) :
+ t("@rel_plural_name", user_relationships_type_translations($relationship, TRUE));
$relatee = $relationship->requestee;
}
else {
- $rtype_heading = t("@rel_plural_name", array('@rel_name' => $tt_rel_name, '@rel_plural_name' => $tt_rel_plural_name));
+ $rtype_heading = t("@rel_plural_name", user_relationships_type_translations($relationship));
$relatee = $relationship->requester;
}
diff --git a/user_relationship_blocks/templates/user_relationships-pending_block.tpl.php b/user_relationship_blocks/templates/user_relationships-pending_block.tpl.php
index 383add5..45c5200 100644
--- a/user_relationship_blocks/templates/user_relationships-pending_block.tpl.php
+++ b/user_relationship_blocks/templates/user_relationships-pending_block.tpl.php
@@ -7,12 +7,10 @@
if ($relationships) {
$list = array();
foreach ($relationships as $rtid => $relationship) {
- $tt_rel_name = ur_tt("user_relationships:rtid:$rtid:name", $relationship->name);
- $tt_rel_plural_name = ur_tt("user_relationships:rtid:$rtid:plural_name", $relationship->plural_name);
if ($user->uid == $relationship->requester_id) {
$relation_to =& $relationship->requestee;
$controls = theme('user_relationships_pending_request_cancel_link', array('uid' => $account->uid, 'rid' => $relationship->rid));
- $line = t('@rel_name to !username (!controls)', array('@rel_name' => $tt_rel_name, '!username' => theme('username', array('account' => $relation_to)), '!controls' => $controls));
+ $line = t('@rel_name to !username (!controls)', array('!username' => theme('username', array('account' => $relation_to)), '!controls' => $controls) + user_relationships_type_translations($relationship));
$key = t('Sent requests');
}
else {
@@ -20,7 +18,7 @@ if ($relationships) {
$controls =
theme('user_relationships_pending_request_approve_link', array('uid' => $account->uid, 'rid' => $relationship->rid)).'|'.
theme('user_relationships_pending_request_disapprove_link', array('uid' => $account->uid, 'rid' => $relationship->rid));
- $line = t('@rel_name from !username (!controls)', array('@rel_name' => $tt_rel_name, '!username' => theme('username', array('account' => $relation_to)), '!controls' => $controls));
+ $line = t('@rel_name from !username (!controls)', array('!username' => theme('username', array('account' => $relation_to)), '!controls' => $controls) + user_relationships_type_translations($relationship));
$key = t('Received requests');
}
$list[$key][] = $line;
diff --git a/user_relationship_blocks/user_relationship_blocks.module b/user_relationship_blocks/user_relationship_blocks.module
index 4fbc90a..e9b6328 100644
--- a/user_relationship_blocks/user_relationship_blocks.module
+++ b/user_relationship_blocks/user_relationship_blocks.module
@@ -73,10 +73,10 @@ function theme_user_relationship_block_subject($variables) {
global $user;
$rtype = user_relationships_type_load($rtid);
if ($account->uid == $user->uid) {
- return t('I am a @rel_name of', array('@rel_name' => ur_tt("user_relationships:rtid:$rtid:name", $rtype->name), '@rel_plural_name' => $rtype->plural_name));
+ return t('I am a @rel_name of', user_relationships_type_translations($rtype));
}
else {
- return t('@username is a @rel_name of', array('@username' => format_username($account), '@rel_name' => ur_tt("user_relationships:rtid:$rtid:name", $rtype->name), '@rel_plural_name' => $rtype->plural_name));
+ return t('@username is a @rel_name of', array('@username' => format_username($account)) + user_relationships_type_translations($rtype));
}
}
else {
@@ -87,8 +87,8 @@ function theme_user_relationship_block_subject($variables) {
else {
$rtype = user_relationships_type_load($rtid);
$output = ($account->uid == $user->uid)
- ? t('My @relationships', array('@relationships' => ur_tt("user_relationships:rtid:$rtid:plural_name", $rtype->plural_name)))
- : t("@username's @relationships", array('@username' => format_username($account), '@relationships' => ur_tt("user_relationships:rtid:$rtid:plural_name", $rtype->plural_name)));
+ ? t('My @rel_name', user_relationships_type_translations($rtype))
+ : t("@username's @rel_name", array('@username' => format_username($account)) + user_relationships_type_translations($rtype));
}
return $output;
}
@@ -129,7 +129,7 @@ function user_relationship_blocks_block_configure($delta) {
}
else {
$type = user_relationships_type_load($rtid);
- $relationship_name = ur_tt("user_relationships:rtid:$rtid:name", $type->name);
+ $relationship_name = user_relationships_type_get_name($type);
}
$form['size'] = array(
@@ -146,7 +146,7 @@ function user_relationship_blocks_block_configure($delta) {
);
$user_identifier = ($block == UR_BLOCK_MY) ? t('currently logged in user') : t('author whose node is being viewed');
- $msg = t("NOTE: This block displays @relationship_name relationships of the @user_identifier.", array('@relationship_name' => ur_tt("user_relationships:rtid:$rtid:name", $relationship_name), '@user_identifier' => $user_identifier));
+ $msg = t("NOTE: This block displays @rel_name relationships of the @user_identifier.", array('@rel_name' => $relationship_name, '@user_identifier' => $user_identifier));
if ($extra) {
$relation = $extra == 'you_to_them' ? t('requester') : t('requestee');
@@ -287,8 +287,8 @@ function user_relationship_blocks_block_info() {
foreach ($extras as $token => $extra) {
$block_types = array(
- "{$my_delta}{$token}" => t('My Relationships: @type @extra', array('@type' => $type->plural_name, '@extra' => $extra)),
- "{$usr_delta}{$token}" => t('User Relationships: @type @extra', array('@type' => $type->plural_name, '@extra' => $extra)),
+ "{$my_delta}{$token}" => t('My Relationships: @rel_name_plural @extra', array('@extra' => $extra) + user_relationships_type_translations($type)),
+ "{$usr_delta}{$token}" => t('User Relationships: @rel_name_plural @extra', array('@extra' => $extra) + user_relationships_type_translations($type)),
);
foreach ($block_types as $bid => $title) {
$blocks[$bid] = array(
diff --git a/user_relationship_defaults/user_relationship_defaults.module b/user_relationship_defaults/user_relationship_defaults.module
index cdd9ac5..cf59ce0 100644
--- a/user_relationship_defaults/user_relationship_defaults.module
+++ b/user_relationship_defaults/user_relationship_defaults.module
@@ -175,7 +175,7 @@ function user_relationship_defaults_add_form_submit($form, &$form_state) {
$message_p = array(
'%username' => $user->name,
- '%relationship_name' => ur_tt("user_relationships:rtid:$relationship_type->rtid:name", $relationship_type->name),
+ '%relationship_name' => user_relationships_type_get_name($relationship_type),
);
drupal_set_message(t('Default relationship %relationship_name of %username has been added.', $message_p));
watchdog('u_relationship', 'Default relationship %relationship_name of %username has been added.', $message_p, WATCHDOG_NOTICE, l(t('view'), 'admin/config/people/relationships'));
@@ -195,10 +195,7 @@ function user_relationship_defaults_delete_form($form, &$form_state, $default_re
$form = confirm_form(
$form,
- t('Are you sure you want to delete the default relationship %relationship of %name?', array(
- '%relationship' => ur_tt('user_relationships:rtid:' . $default_relationship->relationship_type->rtid . ':name', $default_relationship->relationship_type->name),
- '%name' => $default_relationship->user->name,
- )),
+ t('Are you sure you want to delete the default relationship %rel_name of %name?', array('%name' => $default_relationship->user->name) + user_relationships_type_translations($default_relationship)),
'admin/config/people/relationships',
t('This action cannot be undone.'),
t('Delete'), t('Cancel')
@@ -218,7 +215,7 @@ function user_relationship_defaults_delete_form_submit($form, &$form_state) {
->execute();
$message_p = array(
'%name' => $default_relationship->user_name,
- '%relationship' => ur_tt("user_relationships:rtid:$default_relationship->rtid:name", $default_relationship->name),
+ '%relationship' => user_relationships_type_get_name($default_relationship),
);
drupal_set_message(t('Default relationship %relationship of %name has been deleted.', $message_p));
watchdog('u_relationship', 'Default relationship %relationship of %name has been deleted.', $message_p, WATCHDOG_NOTICE);
@@ -273,7 +270,7 @@ function user_relationship_defaults_user_relationships_types_list_alter(&$page)
$default_rows = array();
foreach ($defaults as $default) {
$default_rows[] = array(
- $default->relationship_type->name,
+ user_relationships_type_get_name($default->relationship_type),
theme('username', array('account' => $default->user)),
l(t('delete'), "admin/config/people/relationships/defaults/{$default->rdid}/delete"),
);
diff --git a/user_relationship_implications/user_relationship_implications.module b/user_relationship_implications/user_relationship_implications.module
index 3ba48a9..c812225 100644
--- a/user_relationship_implications/user_relationship_implications.module
+++ b/user_relationship_implications/user_relationship_implications.module
@@ -50,7 +50,7 @@ function user_relationship_implications_form_user_relationships_admin_type_edit_
if (!isset($relationship_type) || $type->rtid != $relationship_type->rtid && !in_array($type->rtid, $implied_by)) {
$imp_name = "implies_{$type->rtid}";
$form['implications']['opts'][$type->rtid][$imp_name] = array(
- '#title' => t('@type_name', array('@type_name' => $type->name)),
+ '#title' => t('@rel_name', user_relationships_type_translations($type)),
'#type' => 'checkbox',
'#return_value' => $type->rtid,
'#default_value' => isset($form['#post'][$imp_name]) || isset($values[$type->rtid]),
@@ -322,10 +322,7 @@ function theme_user_relationship_implications_page($variables) {
$output .= theme('pager');
- drupal_set_title(t("%username's %relationships", array(
- '%username' => $viewed_user->name,
- '%relationships' => $relationship->plural_name ? $relationship->plural_name : t('relationships')
- )));
+ drupal_set_title(t("%username's @rel_name_plural", array('%username' => format_username($viewed_user)) + user_relationships_type_translations($relationship)));
return $output;
}
@@ -337,7 +334,7 @@ function _user_relationship_implications_load_relationship_names($relationships,
$output = array();
foreach ($relationships as $relationship) {
if ($relationship->requester_id == $uid || $relationship->requestee_id == $uid) {
- $output[] = $relationship->name;
+ $output[] = user_relationships_type_get_name($relationship);
}
}
return $output;
diff --git a/user_relationship_invites/user_relationship_invites.module b/user_relationship_invites/user_relationship_invites.module
index 00b48cd..5ef4a8f 100644
--- a/user_relationship_invites/user_relationship_invites.module
+++ b/user_relationship_invites/user_relationship_invites.module
@@ -112,7 +112,7 @@ function user_relationship_invites_form_user_register_form_alter(&$form, &$form_
if (!$relationship_type->is_oneway || $relationship_type->requires_approval) {
$form['relationship_invite_approve'] = array(
'#type' => 'radios',
- '#title' => t('Please confirm the %relationship_name request from !name', array('!name' => theme('username', array('account' => $inviter)), '%relationship_name' => $relationship_type->name)),
+ '#title' => t('Please confirm the @rel_name request from !name', array('!name' => theme('username', array('account' => $inviter))) + user_relationships_type_translations($relationship_type)),
'#default_value' => 'approve',
'#options' => array(
'approve' => t('Yes'),
diff --git a/user_relationship_node_access/user_relationship_node_access.module b/user_relationship_node_access/user_relationship_node_access.module
index 4b6036a..6a99be7 100644
--- a/user_relationship_node_access/user_relationship_node_access.module
+++ b/user_relationship_node_access/user_relationship_node_access.module
@@ -172,11 +172,11 @@ function _user_relationship_node_access_permission_form($object_type, $object) {
foreach ($types as $rtid => $type) {
unset($types[$rtid]);
if ($type->is_oneway) {
- $types["{$rtid}_yt"] = t('Post to @type (you to them)', array('@type' => $type->plural_name));
- $types["{$rtid}_ty"] = t('Post to @type (them to you)', array('@type' => $type->plural_name));
+ $types["{$rtid}_yt"] = t('Post to @rel_name', user_relationships_type_translations($type));
+ $types["{$rtid}_ty"] = t('Post to @rel_name_reverse', user_relationships_type_translations($type));
}
else {
- $types[$rtid] = t('Post to @type', array('@type' => $type->plural_name));
+ $types[$rtid] = t('Post to @rel_name', user_relationships_type_translations($type));
}
}
asort($types);
diff --git a/user_relationship_privatemsg/user_relationship_privatemsg.module b/user_relationship_privatemsg/user_relationship_privatemsg.module
index ee88d81..2b2cd91 100644
--- a/user_relationship_privatemsg/user_relationship_privatemsg.module
+++ b/user_relationship_privatemsg/user_relationship_privatemsg.module
@@ -83,9 +83,9 @@ function theme_user_relationship_privatemsg_format($variables) {
if ($relationship->account->uid == $user->uid) {
- return t('your %relationship', array('%relationship' => $relationship->plural_name, '@url' => url('relationships/' . $relationship->rtid)));
+ return t('your @rel_name_plural', array('@url' => url('relationships/' . $relationship->rtid)) + user_relationships_type_translations($relationship));
}
- $name = t('%relationship of @username', array('%relationship' => $relationship->plural_name, '@username' => format_username($relationship->account)));
+ $name = t('@rel_name_plural of @username', array('@username' => format_username($relationship->account)) + user_relationships_type_translations($relationship));
if (user_relationships_ui_check_access(array('user'), $relationship->account)) {
return l($name, 'user/' . $relationship->account->uid . '/relationships/' . $relationship->rtid, array('html' => TRUE));
}
diff --git a/user_relationship_views/user_relationship_views.module b/user_relationship_views/user_relationship_views.module
index 33b8215..254d446 100644
--- a/user_relationship_views/user_relationship_views.module
+++ b/user_relationship_views/user_relationship_views.module
@@ -53,7 +53,7 @@ function user_relationship_views_ajax_autocomplete_relationships_type($string =
if (strpos($rtype->name, ',') !== FALSE || strpos($rtype->name, '"') !== FALSE) {
$n = '"'. str_replace('"', '""', $rtype->name) .'"';
}
- $matches[$prefix . $n] = check_plain(ur_tt("user_relationships:rtid:$rtype->rtid:name", $rtype->name));
+ $matches[$prefix . $n] = check_plain(user_relationships_type_get_name($rtype));
}
}
}
diff --git a/user_relationships.admin.inc b/user_relationships.admin.inc
index 835a91d..93b7440 100644
--- a/user_relationships.admin.inc
+++ b/user_relationships.admin.inc
@@ -155,12 +155,6 @@ function user_relationships_admin_settings() {
function user_relationships_admin_type_edit($form, &$form_state, $relationship_type = NULL) {
if (!$relationship_type) {
drupal_set_title(t('Add relationship type'));
- $relationship_type = (object) array(
- 'name' => '',
- 'plural_name' => '',
- 'is_oneway' => FALSE,
- 'is_reciprocal' => FALSE,
- );
}
else {
drupal_set_title(t('Edit @name relationship type', array('@name' => $relationship_type->name)));
@@ -179,15 +173,6 @@ function user_relationships_admin_type_edit($form, &$form_state, $relationship_t
'#required' => TRUE,
'#weight' => -10,
);
- $form['plural_name'] = array(
- '#type' => 'textfield',
- '#title' => t('Plural name'),
- '#maxlength' => 255,
- '#default_value' => isset($relationship_type) ? $relationship_type->plural_name : NULL,
- '#description' => t("Example: buddies, friends, coworkers, spouses."),
- '#required' => TRUE,
- '#weight' => -9,
- );
$form['requires_approval'] = array(
'#type' => 'checkbox',
'#title' => t('Requires Approval'),
@@ -229,6 +214,91 @@ function user_relationships_admin_type_edit($form, &$form_state, $relationship_t
),
);
+ $form['branding'] = array(
+ '#type' => 'fieldset',
+ '#title' => t('Branding'),
+ '#group' => 'tabs',
+ );
+
+ $form['branding']['plural_name'] = array(
+ '#type' => 'textfield',
+ '#title' => t('Plural name'),
+ '#maxlength' => 255,
+ '#default_value' => isset($relationship_type->plural_name) ? $relationship_type->plural_name : NULL,
+ '#description' => t("Example: buddies, friends, coworkers, spouses."),
+ '#weight' => 2,
+ );
+
+ $form['branding']['name_capitalized'] = array(
+ '#type' => 'textfield',
+ '#title' => t('Capitalized name'),
+ '#maxlength' => 255,
+ '#default_value' => isset($relationship_type) ? $relationship_type->name_capitalized : NULL,
+ '#description' => t("Example: buddies, friends, coworkers, spouses."),
+ '#weight' => 6,
+ );
+
+ $form['branding']['plural_name_capitalized'] = array(
+ '#type' => 'textfield',
+ '#title' => t('Capitalized plural name'),
+ '#maxlength' => 255,
+ '#default_value' => isset($relationship_type) ? $relationship_type->plural_name_capitalized : NULL,
+ '#description' => t("Example: buddies, friends, coworkers, spouses."),
+ '#weight' => 10,
+ );
+
+ // #states doesn't work on a vertical tab fieldset, hide each input element
+ // separately.
+ $form['reverse_branding'] = array(
+ '#type' => 'fieldset',
+ '#title' => t('One-way reverse branding'),
+ '#group' => 'tabs',
+ '#description' => t('One-way reversed branding is only used when this relationship type only goes one way. Then, these names are used when displaying relationships initiated by other users.'),
+ // Doesn't work properly yet.
+ '#states' => array(
+ 'visible' => array(
+ ':input[name=is_oneway]' => array('checked' => TRUE),
+ ),
+ ),
+ );
+
+ $form['reverse_branding']['reverse_name'] = array(
+ '#type' => 'textfield',
+ '#title' => t('Name'),
+ '#maxlength' => 255,
+ '#default_value' => isset($relationship_type) ? $relationship_type->reverse_name : NULL,
+ '#description' => t("Example: buddies, friends, coworkers, spouses."),
+ '#weight' => 0,
+ );
+
+ $form['reverse_branding']['reverse_plural_name'] = array(
+ '#type' => 'textfield',
+ '#title' => t('Plural name'),
+ '#maxlength' => 255,
+ '#default_value' => isset($relationship_type) ? $relationship_type->reverse_plural_name : NULL,
+ '#description' => t("Example: buddies, friends, coworkers, spouses."),
+ '#weight' => 4,
+ );
+
+ $form['reverse_branding']['reverse_name_capitalized'] = array(
+ '#type' => 'textfield',
+ '#title' => t('Capitalized name'),
+ '#maxlength' => 255,
+ '#default_value' => isset($relationship_type) ? $relationship_type->reverse_name_capitalized : NULL,
+ '#description' => t("Example: buddies, friends, coworkers, spouses."),
+ '#weight' => 8,
+ );
+
+ $form['reverse_branding']['reverse_plural_name_capitalized'] = array(
+ '#type' => 'textfield',
+ '#title' => t('Capitalized plural name'),
+ '#maxlength' => 255,
+ '#default_value' => isset($relationship_type) ? $relationship_type->reverse_plural_name_capitalized : NULL,
+ '#description' => t("Example: buddies, friends, coworkers, spouses."),
+ '#weight' => 12,
+ );
+
+
$form['rtid'] = array(
'#type' => 'value',
'#value' => isset($relationship_type->rtid) ? (int)$relationship_type->rtid : NULL,
@@ -238,11 +308,21 @@ function user_relationships_admin_type_edit($form, &$form_state, $relationship_t
'#value' => (isset($relationship_type->rtid) ? 'edit' : 'add'),
);
- $form['submit'] = array(
+ $form['actions'] = array('#type' => 'actions');
+ $form['actions']['submit'] = array(
'#type' => 'submit',
'#value' => (isset($relationship_type->rtid) ? t('Save relationship type') : t('Add relationship type')),
- '#weight' => 10,
+ '#weight' => 0,
);
+ if (module_exists('i18n_string')) {
+ $form['actions']['translate'] = array(
+ '#type' => 'submit',
+ '#name' => 'save_translate',
+ '#value' => (isset($relationship_type->rtid) ? t('Save and translate') : t('Add and translate')),
+ '#weight' => 5,
+ );
+ }
+
return $form;
}
@@ -260,7 +340,7 @@ function user_relationships_admin_type_delete($form, &$form_state, $relationship
return confirm_form(
$form,
- t('Are you sure you want to delete %name?', array('%name' => ur_tt("user_relationships:rtid:$relationship_type->rtid:name", $relationship_type->name))),
+ t('Are you sure you want to delete %rel_name?', user_relationships_type_translations($relationship_type)),
'admin/config/people/relationships',
t('This action cannot be undone.'),
t('Delete'), t('Cancel')
@@ -297,19 +377,10 @@ function user_relationships_admin_type_edit_validate($form, &$form_state) {
*/
function user_relationships_admin_type_edit_submit($form, &$form_state) {
$relationship_type = (object)$form_state['values'];
- if ($form_state['values']['action'] == 'add') {
- //#348025 when editing a type, make sure that two-way relationships are not left as reciprocal, just in case, as the UI allows it.
- if (!$relationship_type->is_oneway) {
- $relationship_type->is_reciprocal = 0;
- }
- drupal_write_record('user_relationship_types', $relationship_type);
-
- // Update strings for translation
- _user_relationships_update_translations($relationship_type);
- $form_state['values']['rtid'] = $relationship_type->rtid;
- module_invoke_all('user_relationships_type_insert', $relationship_type);
+ user_relationships_type_save($relationship_type);
+ if ($form_state['values']['action'] == 'add') {
drupal_set_message(t('Relationship %name has been added.', array('%name' => $relationship_type->name)));
watchdog(
'u_relationship',
@@ -319,16 +390,6 @@ function user_relationships_admin_type_edit_submit($form, &$form_state) {
);
}
else {
- //#348025 when editing a type, make sure that two-way relationships are not left as reciprocal, just in case, as the UI allows it.
- if (!$relationship_type->is_oneway) {
- $relationship_type->is_reciprocal = 0;
- }
- drupal_write_record('user_relationship_types', $relationship_type, 'rtid');
-
- // Update strings for translation
- _user_relationships_update_translations($relationship_type);
- module_invoke_all('user_relationships_type_update', $relationship_type);
-
drupal_set_message(t('Relationship %name has been updated.', array('%name' => $relationship_type->name)));
watchdog(
'u_relationship',
@@ -338,10 +399,10 @@ function user_relationships_admin_type_edit_submit($form, &$form_state) {
);
}
- user_relationships_types_load(TRUE);
- menu_rebuild();
-
$form_state['redirect'] = 'admin/config/people/relationships';
+ if (module_exists('i18n_string') && $form_state['triggering_element']['#name'] == 'save_translate') {
+ $form_state['redirect'] = 'admin/config/people/relationships/' . $relationship_type->rtid . '/translate';
+ }
}
@@ -368,17 +429,6 @@ function user_relationships_admin_type_delete_submit($form, &$form_state) {
}
/**
- * Make relationship type available to translation by i18nstrings.module
- */
-function _user_relationships_update_translations(&$relationship_type) {
- if (function_exists('i18nstrings_update') && $relationship_type->rtid) {
- i18nstrings_update("user_relationships:rtid:$relationship_type->rtid:name", $relationship_type->name);
- i18nstrings_update("user_relationships:rtid:$relationship_type->rtid:plural_name", $relationship_type->plural_name);
- }
-}
-
-
-/**
* Relationship Types List
*/
function user_relationships_admin_types_list_page() {
diff --git a/user_relationships.author-pane.inc b/user_relationships.author-pane.inc
index fed60a2..359cb2a 100644
--- a/user_relationships.author-pane.inc
+++ b/user_relationships.author-pane.inc
@@ -44,7 +44,7 @@ function user_relationships_preprocess_author_pane(&$variables) {
// Existing relationship; need remove icon/link. (Despite the foreach,
// there should only be one.)
foreach ($relationships as $relationship) {
- $link_label = t('Remove @name from @rel_plural_name', array('@name' => format_username($account), '@rel_plural_name' => $relationship->plural_name));
+ $link_label = t('Remove @name from @rel_plural_name', array('@name' => format_username($account)) + user_relationships_type_translations($relationship));
$css_class = array(str_replace(' ', '-', $relationship->name), 'author-pane-link', 'user_relationships_popup_link', 'author-relationship-remove-icon');
//link to remove
if (!isset($variables['user_relationships'])) {
@@ -52,7 +52,7 @@ function user_relationships_preprocess_author_pane(&$variables) {
}
$variables['user_relationships'] .= '
';
$variables['user_relationships'] .=
- l('
' . t('Remove @rel_name', array('@name' => format_username($account), '@rel_name' => ur_tt("user_relationships:rtid:$relationship->rtid:name", $relationship->name))) . '',
+ l('
' . t('Remove @rel_name', array('@name' => format_username($account)) + user_relationships_type_translations($relationship)) . '',
"user/{$user->uid}/relationships/{$relationship->rid}/remove",
array(
'query' => drupal_get_destination(),
@@ -74,13 +74,13 @@ function user_relationships_preprocess_author_pane(&$variables) {
}
$variables['user_relationships'] .= '
';
$variables['user_relationships'] .=
- l('' . t('Add @rel_name', array('@name' => format_username($account), '@rel_name' => ur_tt("user_relationships:rtid:$rtype->rtid:name", $rtype->name))) . '',
+ l('' . t('Add @rel_name', array('@name' => format_username($account)) + user_relationships_type_translations($relationship)) . '',
"relationship/{$account->uid}/request/{$rtype->rtid}",
array(
'query' => drupal_get_destination(),
'html' => TRUE,
'attributes' => array(
- 'title' => t('Become @name\'s @rel_name', array('@name' => format_username($account), '@rel_name' => ur_tt("user_relationships:rtid:$rtype->rtid:name", $rtype->name))),
+ 'title' => t('Become @name\'s @rel_name', array('@name' => format_username($account)) + user_relationships_type_translations($rtype)),
'class' => $css_class
),
)
diff --git a/user_relationships.i18n.inc b/user_relationships.i18n.inc
new file mode 100644
index 0000000..f22b4ba
--- /dev/null
+++ b/user_relationships.i18n.inc
@@ -0,0 +1,64 @@
+ array(
+ 'title' => t('User Relationships'),
+ 'description' => t('Translations for relationship type names'),
+ 'format' => FALSE,
+ 'list' => TRUE,
+ ),
+ );
+}
+
+/**
+ * Implements hook_i18n_object_info().
+ */
+function user_relationships_i18n_object_info() {
+ $info['user_relationships_type'] = array(
+ // Generic object title.
+ 'title' => t('Relationship type'),
+ // The object key field.
+ 'key' => 'rtid',
+ // The object load callback.
+ 'load callback' => 'user_relationships_type_load',
+ // Placeholders for automatic paths.
+ 'placeholders' => array(
+ '%user_relationships_type' => 'rtid',
+ ),
+ // To produce edit links automatically.
+ 'edit path' => 'admin/config/people/relationships/%user_relationships_type/edit',
+ // Auto-generate translate tab.
+ 'translate tab' => 'admin/config/people/relationships/%user_relationships_type/translate',
+ // Properties for string translation.
+ 'string translation' => array(
+ // Text group that will handle this object's strings.
+ 'textgroup' => 'user_relationships',
+ // Object type property for string translation.
+ 'type' => 'type',
+ // Table where the object is stored, to automate string lists
+ 'table' => 'user_relationship_types',
+ // Translatable properties of these objects.
+ 'properties' => array(
+ 'name' => t('Name'),
+ 'plural_name' => t('Plural name'),
+ 'name_capitalized' => t('Capitalized name'),
+ 'plural_name_capitalized' => t('Plural capitalized name'),
+ 'reverse_name' => t('Reversed name'),
+ 'reverse_plural_name' => t('Reversed plural name'),
+ 'reverse_name_capitalized' => t('Reversed capitalized name'),
+ 'reverse_plural_name_capitalized' => t('Reversed capitalized plural name'),
+ ),
+ // Path to translate strings to every language.
+ 'translate path' => 'admin/config/people/relationships/%user_relationships_type/translate/%i18n_language',
+ )
+ );
+ return $info;
+}
\ No newline at end of file
diff --git a/user_relationships.install b/user_relationships.install
index df435cc..952bd84 100644
--- a/user_relationships.install
+++ b/user_relationships.install
@@ -32,11 +32,41 @@ function user_relationships_schema() {
'fields' => array(
'rtid' => array('type' => 'serial', 'unsigned' => TRUE, 'not null' => TRUE),
'name' => array('type' => 'varchar', 'length' => 255, 'not null' => TRUE, 'default' => ''),
- 'plural_name' => array('type' => 'varchar', 'length' => 255, 'not null' => TRUE, 'default' => ''),
+ 'plural_name' => array('type' => 'varchar', 'length' => 255, 'default' => ''),
'is_oneway' => array('type' => 'int', 'unsigned' => TRUE, 'not null' => TRUE, 'default' => 0, 'size' => 'tiny'),
'is_reciprocal' => array('type' => 'int', 'unsigned' => TRUE, 'not null' => TRUE, 'default' => 0, 'size' => 'tiny'),
'requires_approval' => array('type' => 'int', 'unsigned' => TRUE, 'not null' => TRUE, 'default' => 0, 'size' => 'tiny'),
'expires_val' => array('type' => 'int', 'unsigned' => TRUE, 'not null' => TRUE, 'default' => 0),
+ 'reverse_name' => array(
+ 'type' => 'varchar',
+ 'length' => 255,
+ 'default' => '',
+ ),
+ 'name_capitalized' => array(
+ 'type' => 'varchar',
+ 'length' => 255,
+ 'default' => '',
+ ),
+ 'plural_name_capitalized' => array(
+ 'type' => 'varchar',
+ 'length' => 255,
+ 'default' => '',
+ ),
+ 'reverse_name_capitalized' => array(
+ 'type' => 'varchar',
+ 'length' => 255,
+ 'default' => '',
+ ),
+ 'reverse_plural_name' => array(
+ 'type' => 'varchar',
+ 'length' => 255,
+ 'default' => '',
+ ),
+ 'reverse_plural_name_capitalized' => array(
+ 'type' => 'varchar',
+ 'length' => 255,
+ 'default' => '',
+ ),
),
'unique keys' => array(
'name' => array('name'),
@@ -128,3 +158,45 @@ function user_relationships_update_7004() {
db_drop_index('user_relationships', 'rtid');
db_add_index('user_relationships', 'relationship', array('requester_id', 'requestee_id'));
}
+
+/*
+ * Add table columns for reversed and capitalized names.
+ */
+function user_relationships_update_7005() {
+ $fields = array(
+ 'reverse_name' => array(
+ 'type' => 'varchar',
+ 'length' => 255,
+ 'default' => '',
+ ),
+ 'name_capitalized' => array(
+ 'type' => 'varchar',
+ 'length' => 255,
+ 'default' => '',
+ ),
+ 'plural_name_capitalized' => array(
+ 'type' => 'varchar',
+ 'length' => 255,
+ 'default' => '',
+ ),
+ 'reverse_name_capitalized' => array(
+ 'type' => 'varchar',
+ 'length' => 255,
+ 'default' => '',
+ ),
+ 'reverse_plural_name' => array(
+ 'type' => 'varchar',
+ 'length' => 255,
+ 'default' => '',
+ ),
+ 'reverse_plural_name_capitalized' => array(
+ 'type' => 'varchar',
+ 'length' => 255,
+ 'default' => '',
+ ),
+ );
+
+ foreach ($fields as $field => $definition) {
+ db_add_field('user_relationship_types', $field, $definition);
+ }
+}
diff --git a/user_relationships.module b/user_relationships.module
index 1a00c9d..7b1f9fc 100644
--- a/user_relationships.module
+++ b/user_relationships.module
@@ -11,6 +11,10 @@
define('UR_OK', 0x0);
define('UR_BANNED', 0x1);
+define('USER_RELATIONSHIPS_NAME_PLURAL', 1);
+define('USER_RELATIONSHIPS_NAME_CAPITAL', 2);
+define('USER_RELATIONSHIPS_NAME_REVERSE', 4);
+
function user_relationships_menu() {
$items['admin/config/people/relationships'] = array(
'title' => 'Relationships',
@@ -50,7 +54,7 @@ function user_relationships_menu() {
'page arguments' => array('user_relationships_admin_type_delete', 4),
'access arguments' => array('administer user relationships'),
'file' => 'user_relationships.admin.inc',
- 'weight' => 10,
+ 'weight' => 15,
);
$items['admin/config/people/relationships/settings'] = array(
'title' => 'Settings',
@@ -91,6 +95,7 @@ function user_relationships_setting_validation($element, $validations) {
}
}
+
/**
* Helper function to generate the main and count queries from a list of parameters and options
*/
@@ -351,18 +356,6 @@ function user_relationships_user_cancel($edit, $account, $method) {
}
/**
- * Wrapper function for tt() if i18nstrings enabled.
- */
-function ur_tt($name, $string, $langcode = NULL, $update = FALSE) {
- if (module_exists('i18nstrings')) {
- return tt($name, $string, $langcode, $update);
- }
- else {
- return $string;
- }
-}
-
-/**
* Implements hook_activity_info().
*/
function user_relationships_activity_info() {
@@ -461,17 +454,27 @@ function user_relationships_types_load($reset = FALSE) {
* A User Relationship type object
*/
function user_relationships_type_save($rtype) {
+
+ // #348025 when editing a type, make sure that two-way relationships are not
+ // left as reciprocal, just in case, as the UI allows it.
+ if (empty($rtype->is_oneway)) {
+ $rtype->is_reciprocal = 0;
+ }
+
+ // Ensure "expires_val" is numeric and not negative.
+ if (!isset($rtype->expires_val) || !is_numeric($rtype->expires_val) || $rtype->expires_val < 0) {
+ $rtype->expires_val = 0;
+ }
+
module_invoke_all('user_relationships_type_presave', $rtype);
$op = (isset($rtype->rtid) && $rtype->rtid) ? 'update' : 'insert';
- // find a relationship type with the name we're trying to save
+ // Find a relationship type with the name we're trying to save
// if it's an update action check to see that the rtypes match
- // otherwise it's just invalid
- if (
- ($found_rt = user_relationships_type_load(array('name' => $rtype->name))) &&
- ($op == 'update' ? $found_rt->rtid != $rtype->rtid : TRUE)
- ) {
+ // otherwise it's just invalid.
+ $found_rt = user_relationships_type_load(array('name' => $rtype->name));
+ if ($found_rt && (($op == 'update' && $found_rt->rtid != $rtype->rtid) || $op == 'insert')) {
return FALSE;
}
@@ -483,6 +486,11 @@ function user_relationships_type_save($rtype) {
drupal_write_record('user_relationship_types', $rtype, ($op == 'update' ? 'rtid' : array()));
module_invoke_all('user_relationships_type_' . $op, $rtype);
+ if (module_exists('i18n_string')) {
+ i18n_string_object_update('user_relationships_type', $rtype);
+ }
+ user_relationships_types_load(TRUE);
+ menu_rebuild();
}
@@ -506,6 +514,9 @@ function user_relationships_type_delete($rtid) {
user_relationships_types_load(TRUE);
module_invoke_all('user_relationships_type_delete', $rtype);
+ if (module_exists('i18n_string')) {
+ i18n_string_object_remove('user_relationships_type', $rtype);
+ }
}
@@ -547,14 +558,14 @@ function user_relationships_request_relationship($requester, $requestee = NULL,
//check requester is allowed to create this rtype
if (!user_relationships_can_request($requester, $type)) {
- watchdog('user_relationships', 'User %user has no suitable roles to request a %rtype relationship', array('%user' => format_username($requester), '%rtype' => $type->name), WATCHDOG_WARNING);
+ watchdog('user_relationships', 'User %user has no suitable roles to request a %rtype relationship', array('%user' => format_username($requester), '%rtype' => user_relationships_type_get_name($type)), WATCHDOG_WARNING);
//it would be good to return a reason why save is denied, but it's the API portion, it does not expose anything user-visible
return FALSE;
}
//check requestee is allowed to receive this rtype
if (!user_relationships_can_receive($requestee, $type)) {
- watchdog('user_relationships', 'User %user has no suitable roles to receive a %rtype relationship', array('%user' => format_username($requestee), '%rtype' => $type->name), WATCHDOG_WARNING);
+ watchdog('user_relationships', 'User %user has no suitable roles to receive a %rtype relationship', array('%user' => format_username($requestee), '%rtype' => user_relationships_type_get_name($type)), WATCHDOG_WARNING);
//it would be good to return a reason why save is denied, but it's the API portion, it does not expose anything user-visible
return FALSE;
}
@@ -930,19 +941,10 @@ function user_relationships_get_message($key, $relationship = NULL, $replacement
if (!isset($relationship->requestee)) {
$relationship->requestee = user_load($relationship->requestee_id);
}
- if (!(isset($relationship->name) || isset($relationship->type))) {
- $relationship->type = user_relationships_type_load($relationship->rtid);
- }
- $replaceables = array(
+ $replaceables = user_relationships_type_translations(user_relationships_type_load($relationship->rtid)) + array(
'!requester' => theme('username', array('account' => $relationship->requester)),
'!requestee' => theme('username', array('account' => $relationship->requestee)),
- '%relationship_name' => isset($relationship->name)
- ? ur_tt("user_relationships:rtid:$relationship->rtid:name", $relationship->name)
- : ur_tt("user_relationships:rtid:$relationship->rtid:name", $relationship->type->name),
- '%relationship_plural_name' => isset($relationship->plural_name)
- ? ur_tt("user_relationships:rtid:$relationship->rtid:plural_name", $relationship->plural_name)
- : ur_tt("user_relationships:rtid:$relationship->rtid:plural_name", $relationship->type->plural_name),
);
$replacements = array_merge($replaceables, $replacements);
}
@@ -966,27 +968,27 @@ function user_relationships_get_message($key, $relationship = NULL, $replacement
function _user_relationships_default_messages($replacements) {
return array(
'informational' => array(
- 'submitted' => t('Your %relationship_name request has been sent to !requestee.', $replacements),
- 'accepted' => t("!requester's %relationship_name request has been approved.", $replacements),
- 'disapproved' => t("!requester has declined your %relationship_name request.", $replacements),
- 'disapprove' => t("!requester's %relationship_name request has been declined.", $replacements),
- 'cancel' => t('Your %relationship_name request to !requestee has been canceled.', $replacements),
+ 'submitted' => t('Your @rel_name request has been sent to !requestee.', $replacements),
+ 'accepted' => t("!requester's @rel_name request has been approved.", $replacements),
+ 'disapproved' => t("!requester has declined your @rel_name request.", $replacements),
+ 'disapprove' => t("!requester's @rel_name request has been declined.", $replacements),
+ 'cancel' => t('Your @rel_name request to !requestee has been canceled.', $replacements),
'default' => t('No action has been taken.'),
- 'removed' => t('The %relationship_name relationship between !requester and !requestee has been deleted.', $replacements),
- 'pending' => t('!requester has requested to be your %relationship_name. View your !pending_relationship_requests to approve or decline.', $replacements),
- 'pre_approved' => t("You are !requestee's newest %relationship_name.", $replacements),
+ 'removed' => t('The @rel_name relationship between !requester and !requestee has been deleted.', $replacements),
+ 'pending' => t('!requester has requested to be your @rel_name. View your !pending_relationship_requests to approve or decline.', $replacements),
+ 'pre_approved' => t("You are !requestee's newest @rel_name.", $replacements),
),
'error' => array(
'too_many_relationships' => t('You are not permitted to create any more relationships with this user.'),
- 'existing_request' => t('There is already an earlier %relationship_name request sent to !requestee.', $replacements),
- 'existing_relationship' => t('There is already an existing %relationship_name relationship with !requestee.', $replacements),
+ 'existing_request' => t('There is already an earlier @rel_name request sent to !requestee.', $replacements),
+ 'existing_relationship' => t('There is already an existing @rel_name relationship with !requestee.', $replacements),
'not_accepting_requests' => t('This user does not accept relationship requests.'),
'self_request' => t('You cannot create a relationship with yourself.'),
'non_existent_user' => t('This user does not exist.'),
'non_existent_type' => t('This relationship type does not exist.'),
'unknown_error' => t('An error has occurred. Please contact the site administrator.'),
'relationship_type_not_set' => t('Please choose the type of relationship.'),
- 'relationship_type_not_allowed' => t('You may not create %relationship_name relationships.', $replacements),
+ 'relationship_type_not_allowed' => t('You may not create @rel_name relationships.', $replacements),
),
);
}
@@ -1037,13 +1039,44 @@ function _user_relationships_get_from_array($needle, &$haystack) {
}
/**
- * Implements hook_locale().
+ * Gets the relationship type name.
*/
-function user_relationships_ui_locale($op = 'groups') {
- switch ($op) {
- case 'groups':
- return array('user_relationships' => t('User Relationships'));
+function user_relationships_type_get_name($type, $plural = FALSE, $reversed = FALSE, $capitalized = FALSE) {
+ // Start with just name as the name and then add suffixes and prefixes
+ // according to the given flags.
+ $name = 'name';
+ if ($plural) {
+ $name = 'plural_' . $name;
+ }
+
+ if ($reversed) {
+ $name = 'reverse_' . $name;
+ }
+
+ if ($capitalized) {
+ $name .= '_capitalized';
}
+
+ if (is_string($type)) {
+ $type = user_relationships_type_load($type);
+ }
+
+ $name_value = !empty($type->$name) ? $type->$name : $type->name;
+ // Attemt to translate the name.
+ if (module_exists('i18n_string')) {
+ $string_object = i18n_string_object_translate('user_relationships_type', $type);
+ $name_value = $string_object[$name];
+ }
+ return $name_value;
+}
+
+function user_relationships_type_translations($relationship_type) {
+ return array(
+ '@rel_name' => user_relationships_type_get_name($relationship_type),
+ '@rel_name_plural' => user_relationships_type_get_name($relationship_type, TRUE),
+ '@Rel_name' => user_relationships_type_get_name($relationship_type, FALSE, FALSE, TRUE),
+ '@Rel_name_plural' => user_relationships_type_get_name($relationship_type, TRUE, FALSE, TRUE),
+ );
}
/**
@@ -1054,7 +1087,7 @@ function user_relationships_autocomplete_types($string = '') {
if ($string) {
$result = db_query_range("SELECT rtid, name FROM {user_relationship_types} WHERE LOWER(name) LIKE LOWER(:string)", 0, 10, array(':string' => '%' . strtolower($string) . '%'));
foreach ($result as $relationship) {
- $matches[$relationship->name] = check_plain(ur_tt("user_relationships:rtid:$relationship->rtid:name", $relationship->name));
+ $matches[$relationship->name] = check_plain(user_relationships_type_get_name($relationship));
}
}
print drupal_json_output($matches);
@@ -1107,7 +1140,7 @@ function user_relationships_get_requestable_rtypes($requester, $requestee, $retu
}
}
if ($return == 'name') {
- $relationships[$rtype->rtid] = ur_tt("user_relationships:rtid:$rtype->rtid:name", $rtype->name);
+ $relationships[$rtype->rtid] = user_relationships_type_get_name($rtype);
}
else {
$relationships[$rtype->rtid] = $rtype;
diff --git a/user_relationships.test b/user_relationships.test
index b05da71..065beb6 100644
--- a/user_relationships.test
+++ b/user_relationships.test
@@ -483,3 +483,55 @@ class UserRelationshipsTestCase extends UserRelationshipsBaseTestCase {
$this-> assertFalse($rtype->is_reciprocal);
}
}
+
+/**
+ * User Relationship type tests.
+ */
+class UserRelationshipsTypesTestCase extends DrupalWebTestCase {
+
+ /**
+ * Implements getInfo().
+ */
+ function getInfo() {
+ return array(
+ 'name' => t('User Relationships Types'),
+ 'description' => t('Checks various user relationship types functions.'),
+ 'group' => t('User Relationships'),
+ );
+ }
+
+ /**
+ * Enable modules.
+ */
+ function setUp() {
+ parent::setUp('user_relationships');
+ }
+
+ function testNames() {
+ // Create relationship type.
+ $relationship_type = (object)array(
+ 'name' => $this->randomName(),
+ 'plural_name' => $this->randomName(),
+ 'reverse_name' => $this->randomName(),
+ 'reverse_plural_name' => $this->randomName(),
+ 'name_capitalized' => $this->randomName(),
+ 'plural_name_capitalized' => $this->randomName(),
+ 'reverse_name_capitalized' => $this->randomName(),
+ 'reverse_plural_name_capitalized' => $this->randomName(),
+ 'requires_approval' => FALSE,
+ 'expires_val' => 0,
+ );
+
+ // First, check all names.
+ $this->assertEqual($relationship_type->name, user_relationships_type_get_name($relationship_type));
+ $this->assertEqual($relationship_type->plural_name, user_relationships_type_get_name($relationship_type, TRUE));
+ $this->assertEqual($relationship_type->reverse_name, user_relationships_type_get_name($relationship_type, FALSE, TRUE));
+ $this->assertEqual($relationship_type->reverse_plural_name, user_relationships_type_get_name($relationship_type, TRUE, TRUE));
+ $this->assertEqual($relationship_type->name_capitalized, user_relationships_type_get_name($relationship_type, FALSE, FALSE, TRUE));
+ $this->assertEqual($relationship_type->plural_name_capitalized, user_relationships_type_get_name($relationship_type, TRUE, FALSE, TRUE));
+ $this->assertEqual($relationship_type->reverse_name_capitalized, user_relationships_type_get_name($relationship_type, FALSE, TRUE, TRUE));
+ $this->assertEqual($relationship_type->reverse_plural_name_capitalized, user_relationships_type_get_name($relationship_type, TRUE, TRUE, TRUE));
+
+ // @todo: Test fallback strategy.
+ }
+}
diff --git a/user_relationships_ui/user_relationships_ui.forms.inc b/user_relationships_ui/user_relationships_ui.forms.inc
index 2c6f746..f253653 100644
--- a/user_relationships_ui/user_relationships_ui.forms.inc
+++ b/user_relationships_ui/user_relationships_ui.forms.inc
@@ -135,8 +135,8 @@ function user_relationships_ui_request($form, &$form_state, $requestee) {
$dest,
isset($relationship) ?
($relationship->requires_approval
- ? t('Are you sure you want to send a new %rel_name request to !name?', array('%rel_name' => ur_tt("user_relationships:rtid:$relationship->rtid:name", $relationship->name), '%rel_plural_name' => ur_tt("user_relationships:rtid:$relationship->rtid:plural_name", $relationship->plural_name), '!name' => theme('username', array('account' => $requestee))))
- : t("Are you sure you want to become !name's %rel_name?", array('!name' => theme('username', array('account' => $requestee)), '%rel_name' => ur_tt("user_relationships:rtid:$relationship->rtid:name", $relationship->name)))) :
+ ? t('Are you sure you want to send a new @rel_name request to !name?', array('!name' => theme('username', array('account' => $requestee))) + user_relationships_type_translations($relationship))
+ : t("Are you sure you want to become !name's @rel_name?", array('!name' => theme('username', array('account' => $requestee))) + user_relationships_type_translations($relationship))) :
'',
t('Send'), t('Cancel'),
'user_relationships_request_confirm'
@@ -182,29 +182,26 @@ function user_relationships_ui_pending_requested($form, &$form_state, $action, $
//pick the correct question message: approve and disapprove are requests to current user, cancel is a request from current user
switch ($action) {
case 'approve':
- $confirmation_message = t('Are you sure you want to approve the %relationship_name relationship request from !name?', array(
+ $confirmation_message = t('Are you sure you want to approve the @rel_name relationship request from !name?', array(
'@action' => $action,
- '%relationship_name' => ur_tt("user_relationships:rtid:$relationship->rtid:name", $relationship->name),
'!name' => theme('username', array('account' => user_load(($viewed_id == $relationship->requester_id ? $relationship->requestee_id : $relationship->requester_id))))
- ));
+ ) + user_relationships_type_translations($relationship));
$action_message = t('Approve relationship');
$request_url = 'relationships/received';
break;
case 'disapprove':
- $confirmation_message = t('Are you sure you want to decline the %relationship_name relationship request from !name?', array(
+ $confirmation_message = t('Are you sure you want to decline the @rel_name relationship request from !name?', array(
'@action' => $action,
- '%relationship_name' => ur_tt("user_relationships:rtid:$relationship->rtid:name", $relationship->name),
'!name' => theme('username', array('account' => user_load(($viewed_id == $relationship->requester_id ? $relationship->requestee_id : $relationship->requester_id))))
- ));
+ ) + user_relationships_type_translations($relationship));
$action_message = t('Decline relationship');
$request_url = 'relationships/received';
break;
default:
- $confirmation_message = t('Are you sure you want to cancel your %relationship_name relationship request to !name?', array(
+ $confirmation_message = t('Are you sure you want to cancel your @rel_name relationship request to !name?', array(
'@action' => $action,
- '%relationship_name' => ur_tt("user_relationships:rtid:$relationship->rtid:name", $relationship->name),
'!name' => theme('username', array('account' => user_load(($viewed_id == $relationship->requester_id ? $relationship->requestee_id : $relationship->requester_id))))
- ));
+ ) + user_relationships_type_translations($relationship));
$action_message = t('Cancel relationship');
$request_url = 'relationships/sent';
}
@@ -280,10 +277,9 @@ function user_relationships_ui_remove($form, &$form_state, $account, $relationsh
$form,
t('Remove relationship'),
$dest,
- t("Are you sure you want to delete the %relationship_name relationship with !name?", array(
- '%relationship_name' => ur_tt("user_relationships:rtid:$relationship->rtid:name", $relationship->name),
- '!name' => theme('username', array('account' => user_load(($viewed_id == $relationship->requester_id ? $relationship->requestee_id : $relationship->requester_id))))
- )),
+ t("Are you sure you want to delete the @rel_name relationship with !name?", array(
+ '!name' => theme('username', array('account' => user_load(($viewed_id == $relationship->requester_id ? $relationship->requestee_id : $relationship->requester_id))))
+ ) + user_relationships_type_translations($relationship)),
t('Yes'), t('No'),
'user_relationships_remove_confirm'
);
diff --git a/user_relationships_ui/user_relationships_ui.module b/user_relationships_ui/user_relationships_ui.module
index 915326f..1379954 100644
--- a/user_relationships_ui/user_relationships_ui.module
+++ b/user_relationships_ui/user_relationships_ui.module
@@ -60,10 +60,9 @@ function user_relationships_ui_actions_between($viewer, $viewed, $action_types =
if (isset($action_types['requested'])) {
$relationships = user_relationships_load(array('requester_id' => $viewer->uid, 'requestee_id' => $viewed->uid, 'approved' => FALSE));
foreach ($relationships as $relationship) {
- $list[] = t('You have sent a new %relationship_name request to this user. (!pending_requests)', array(
- '%relationship_name' => ur_tt("user_relationships:rtid:$relationship->rtid:name", $relationship->name),
+ $list[] = t('You have sent a new @rel_name request to this user. (!pending_requests)', array(
'!pending_requests' => l(t('pending requests'), "relationships/sent"),
- ));
+ ) + user_relationships_type_translations($relationship));
}
}
@@ -71,10 +70,9 @@ function user_relationships_ui_actions_between($viewer, $viewed, $action_types =
$relationships = user_relationships_load(array('requester_id' => $viewed->uid, 'requestee_id' => $viewer->uid, 'approved' => FALSE));
foreach ($relationships as $relationship) {
if (user_relationships_user_access('maintain @relationship relationships', $relationship)) {
- $list[] = t('This user has requested to be your %relationship_name. (!pending_requests)', array(
- '%relationship_name' => ur_tt("user_relationships:rtid:$relationship->rtid:name", $relationship->name),
- '!pending_requests' => l(t('pending requests'), "user/{$viewer->uid}/relationships/received"),
- ));
+ $list[] = t('This user has requested to be your @rel_name. (!pending_requests)', array(
+ '!pending_requests' => l(t('pending requests'), "user/{$viewer->uid}/relationships/received"),
+ ) + user_relationships_type_translations($relationship));
}
}
}
@@ -101,13 +99,13 @@ function user_relationships_ui_actions_between($viewer, $viewed, $action_types =
foreach ($relationships as $relationship) {
if ($relationship->approved && !isset($list[$relationship->rid]) && user_relationships_ui_check_access('view', NULL, $relationship)) {
if (user_relationships_ui_check_access('delete', NULL, $relationship)) {
- $list[$relationship->rid] = t('%relationship_name (!remove_link)', array(
- '%relationship_name' => ur_tt("user_relationships:rtid:$relationship->rtid:name", $relationship->name) . ($relationship->is_oneway ? ($relationship->requester_id == $viewer->uid ? t(' (You to Them)') : t(' (Them to You)')) : NULL),
+ $list[$relationship->rid] = t('@rel_name (!remove_link)', array(
+ '@rel_name' => user_relationships_type_get_name($relationship) . ($relationship->is_oneway ? ($relationship->requester_id == $viewer->uid ? t(' (You to Them)') : t(' (Them to You)')) : NULL),
'!remove_link' => theme('user_relationships_remove_link', array('uid' => $viewer->uid, 'rid' => $relationship->rid)),
));
}
else {
- $list[$relationship->rid] = ur_tt("user_relationships:rtid:$relationship->rtid:name", $relationship->name) . ($relationship->is_oneway ? ($relationship->requester_id == $viewer->uid ? t(' (You to Them)') : t(' (Them to You)')) : NULL);
+ $list[$relationship->rid] = user_relationships_type_get_name($relationship) . ($relationship->is_oneway ? ($relationship->requester_id == $viewer->uid ? t(' (You to Them)') : t(' (Them to You)')) : NULL);
}
}
}
@@ -116,7 +114,6 @@ function user_relationships_ui_actions_between($viewer, $viewed, $action_types =
return $list;
}
-
/**********************************
* CALLBACKS
**********************************/
@@ -300,7 +297,8 @@ function user_relationships_ui_menu() {
foreach (user_relationships_types_load() as $rtid => $relationship) {
if (isset($show_tabs[$rtid])) {
$items["relationships/{$rtid}"] = array(
- 'title' => $relationship->plural_name ? $relationship->plural_name : $relationship->name,
+ 'title' => $relationship->rtid,
+ 'title callback' => 'user_relationships_ui_title_callback',
'type' => MENU_LOCAL_TASK,
'access callback' => 'user_relationships_ui_check_access',
'access arguments' => array('view', NULL, 1),
@@ -376,7 +374,8 @@ function user_relationships_ui_menu() {
);
foreach (user_relationships_types_load() as $rtid => $relationship) {
$items["user/%user/relationships/{$rtid}"] = array(
- 'title' => $relationship->plural_name ? $relationship->plural_name : $relationship->name,
+ 'title' => $relationship->rtid,
+ 'title callback' => 'user_relationships_ui_title_callback',
'type' => MENU_LOCAL_TASK,
'access callback' => 'user_relationships_ui_check_access',
'access arguments' => array('view', 1, 3),
@@ -409,6 +408,10 @@ function user_relationships_ui_menu() {
return $items;
}
+function user_relationships_ui_title_callback($rtid) {
+ return user_relationships_type_get_name(user_relationships_type_load($rtid), TRUE, FALSE, TRUE);
+}
+
/**
* Title callback to display the amount of pending requests.
* @param $column
@@ -517,7 +520,7 @@ function user_relationships_ui_form_alter(&$form, &$form_state, $form_id) {
$options = array();
foreach ($relationships as $relationship) {
if ($relationship->requires_approval && user_relationships_ui_check_access('approve', NULL, $relationship)) {
- $options[$relationship->rtid] = ur_tt("user_relationships:rtid:$relationship->rtid:name", $relationship->name);
+ $options[$relationship->rtid] = user_relationships_type_get_name($relationship);
}
}
diff --git a/user_relationships_ui/user_relationships_ui.pages.inc b/user_relationships_ui/user_relationships_ui.pages.inc
index b685fa0..e2209fd 100644
--- a/user_relationships_ui/user_relationships_ui.pages.inc
+++ b/user_relationships_ui/user_relationships_ui.pages.inc
@@ -41,12 +41,12 @@ function user_relationships_page($account = NULL, $rtid = NULL) {
if ($account->uid == $user->uid) {
$msg = isset($relationship_type)
- ? t("My %relationships", array('%relationships' => $relationship_type->plural_name ? ur_tt("user_relationships:rtid:" . $relationship_type->rtid . ":plural_name", $relationship_type->plural_name) : ur_tt("user_relationships:rtid:" . $relationship_type->rtid . ":name", $relationship_type->name)))
+ ? t("My @rel_name_plural", user_relationships_type_translations($relationship_type))
: t("My relationships");
}
else {
$msg = isset($relationship_type)
- ? t("%username's %relationships", array('%username' => format_username($account), '%relationships' => $relationship_type->plural_name ? ur_tt("user_relationships:rtid:" . $relationship_type->rtid . ":plural_name", $relationship_type->plural_name) : ur_tt("user_relationships:rtid:" . $relationship_type->rtid . ":name", $relationship_type->name)))
+ ? t("%username's @rel_name", array('%username' => format_username($account)) + user_relationships_type_translations($relationship_type))
: t("%username's relationships", array('%username' => format_username($account)));
}
drupal_set_title($msg, PASS_THROUGH);
@@ -63,7 +63,7 @@ function user_relationships_page($account = NULL, $rtid = NULL) {
}
if (!empty($rtid)) {
- $empty = t('You do not have any %plural_name.', array('%plural_name' => ur_tt("user_relationships:rtid:$relationship_type->rtid:plural_name", $relationship_type->plural_name)));
+ $empty = t('You do not have any %rel_plural_name.', user_relationships_type_translations($relationship_type));
}
else {
$empty = t('You do not have any relationships with other users.');
@@ -174,7 +174,7 @@ function user_relationships_ui_get_table_row($relationship, $account) {
$row = array(
theme('username', array('account' => $this_user)),
- ur_tt("user_relationships:rtid:$relationship->rtid:name", $relationship->name) . ($relationship->is_oneway ? ($this_user_str == 'requestee' ? t(' (You to Them)') : t(' (Them to You)')) : NULL),
+ user_relationships_type_get_name($relationship, FALSE, $relationship->is_oneway && $this_user_str == 'requester'),
);
$permission = $account->uid == $relationship->requestee_id ? 'request' : 'approve';
diff --git a/user_relationships_ui/user_relationships_ui.theme.inc b/user_relationships_ui/user_relationships_ui.theme.inc
index 648e4b2..858b58e 100644
--- a/user_relationships_ui/user_relationships_ui.theme.inc
+++ b/user_relationships_ui/user_relationships_ui.theme.inc
@@ -39,7 +39,7 @@ function theme_user_relationships_request_relationship_direct_link($variables) {
return theme('user_relationships_request_relationship_link', array('relate_to' => $relate_to));
}
return l(
- t("Become %name's %rel_name", array('%name' => format_username($relate_to), '%rel_name' => ur_tt("user_relationships:rtid:$relationship_type->rtid:name", $relationship_type->name), '%rel_plural_name' => ur_tt("user_relationships:rtid:$relationship_type->rtid:plural_name", $relationship_type->plural_name))),
+ t("Become %name's @rel_name", array('%name' => format_username($relate_to)) + user_relationships_type_translations($relationship_type)),
"relationship/{$relate_to->uid}/request/{$relationship_type->rtid}",
array(
'query' => drupal_get_destination(),