Newer
Older
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
<?php
/**
* Object wrapper
*/
class i18n_object_wrapper {
protected $type;
protected $object;
/**
* Class constructor
*/
public function __construct($type, $object) {
$this->type = $type;
$this->object = $object;
}
/**
* Get edit path for object
*/
function get_edit_path() {
if ($path = $this->get_info('edit path')) {
return strtr($path, $this->get_placeholders());
}
else {
return NULL;
}
}
/**
* Get field value from object/array
*/
function get_field($field, $default = NULL) {
if (is_array($field)) {
// We can handle a list of fields too. This is useful for multiple keys (like blocks)
foreach ($field as $key => $name) {
$values[$key] = $this->get_field($name);
}
return $values;
}
elseif (is_object($this->object)) {
return isset($this->object->$field) ? $this->object->$field : $default;
}
elseif (is_array($this->object)) {
return isset($this->object[$field]) ? $this->object[$field] : $default;
}
else {
return $default;
}
}
/**
* Get key value from object/array
*/
function get_key($default = NULL) {
if ($field = $this->get_info('key')) {
return $this->get_field($field, $default);
}
else {
return $default;
}
}
/**
* Get language code
*/
public function get_langcode() {
return i18n_object_langcode($this->object);
}
/**
* Get real object or array
*/
public function get_object() {
return $this->object;
}
/**
* Get menu placehoders for object
*/
Jose Antonio Reyero del Prado
committed
protected function get_placeholders() {
$placeholders = $this->get_info('placeholders', array());
foreach ($placeholders as $name => $field) {
$placeholders[$name] = $this->get_field($field);
}
return $placeholders;
}
/**
* Get title from item
*/
public function get_title() {
return entity_label($this->type, $this->object);
}
/**
* Get link for item
*/
public function get_path() {
if ($uri = entity_uri($this->type, $this->object)) {
return $uri['path'];
}
}
/**
* Menu access callback for mixed translation tab
*/
function get_translate_access() {
Jose Antonio Reyero del Prado
committed
switch ($this->get_translate_mode()) {
case I18N_MODE_TRANSLATE:
return $this->translate_access();
case I18N_MODE_LOCALIZE:
return $this->localize_access();
default:
return FALSE;
}
}
Jose Antonio Reyero del Prado
committed
/**
* Get translate or localize mode for object
*/
function get_translate_mode() {
Jose Antonio Reyero del Prado
committed
return I18N_MODE_NONE;
}
Jose Antonio Reyero del Prado
committed
/**
* Localize access
*/
protected function translate_access() {
return FALSE;
}
Jose Antonio Reyero del Prado
committed
/**
Jose Antonio Reyero del Prado
committed
* Translate access (localize strings)
*/
protected function localize_access() {
Jose Antonio Reyero del Prado
committed
return user_access('translate interface');