123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210 |
- <?php
- function entity_i18n_controller($type = NULL) {
- $static = &drupal_static(__FUNCTION__);
- if (!isset($type)) {
-
-
- foreach (entity_get_info() as $entity_type => $info) {
- entity_i18n_controller($entity_type);
- }
- return array_filter($static);
- }
- if (!isset($static[$type])) {
- $info = entity_get_info($type);
-
-
- $class = isset($info['i18n controller class']) ? $info['i18n controller class'] : FALSE;
- $static[$type] = $class ? new $class($type, $info) : FALSE;
- }
- return $static[$type];
- }
- function entity_i18n_string_info() {
- $groups = array();
- foreach (entity_i18n_controller() as $entity_type => $controller) {
- $groups += $controller->hook_string_info();
- }
- return $groups;
- }
- function entity_i18n_object_info() {
- $info = array();
- foreach (entity_i18n_controller() as $entity_type => $controller) {
- $info += $controller->hook_object_info();
- }
- return $info;
- }
- function entity_i18n_string_objects($type) {
- if ($controller = entity_i18n_controller($type)) {
- return $controller->hook_string_objects();
- }
- }
- class EntityDefaultI18nStringController {
- protected $entityType, $entityInfo;
-
- protected $textgroup;
- public function __construct($type) {
- $this->entityType = $type;
- $this->entityInfo = entity_get_info($type);
-
- $this->textgroup = $this->entityInfo['module'];
- }
-
- public function hook_string_info() {
- $list = system_list('module_enabled');
- $info = $list[$this->textgroup]->info;
- $groups[$this->textgroup] = array(
- 'title' => $info['name'],
- 'description' => !empty($info['description']) ? $info['description'] : NULL,
- 'format' => FALSE,
- 'list' => TRUE,
- );
- return $groups;
- }
-
- public function hook_object_info() {
- $wildcard = $this->menuWildcard();
- $id_key = !empty($this->entityInfo['entity keys']['name']) ? $this->entityInfo['entity keys']['name'] : $this->entityInfo['entity keys']['id'];
- $info[$this->entityType] = array(
-
- 'title' => $this->entityInfo['label'],
-
- 'key' => $id_key,
-
- 'placeholders' => array(
- $wildcard => $id_key,
- ),
-
- 'string translation' => array(
-
- 'textgroup' => $this->textgroup,
-
- 'type' => $this->entityType,
-
- 'properties' => $this->translatableProperties(),
- ),
- );
-
- if ($base_path = $this->menuBasePath()) {
- $info[$this->entityType] += array(
-
- 'edit path' => $base_path . '/manage/' . $wildcard,
-
- 'translate tab' => $base_path . '/manage/' . $wildcard . '/translate',
- );
- $info[$this->entityType]['string translation'] += array(
-
- 'translate path' => $base_path . '/manage/' . $wildcard . '/translate/%i18n_language',
- );
- }
- return $info;
- }
-
- protected function menuBasePath() {
- return !empty($this->entityInfo['admin ui']['path']) ? $this->entityInfo['admin ui']['path'] : FALSE;
- }
-
- protected function menuWildcard() {
- return isset($this->entityInfo['admin ui']['menu wildcard']) ? $this->entityInfo['admin ui']['menu wildcard'] : '%entity_object';
- }
-
- protected function translatableProperties() {
- $list = array();
- foreach (entity_get_all_property_info($this->entityType) as $name => $info) {
- if (!empty($info['translatable']) && !empty($info['i18n string'])) {
- $list[$name] = array(
- 'title' => $info['label'],
- );
- }
- }
- return $list;
- }
-
- public function hook_string_objects() {
- return entity_load_multiple_by_name($this->entityType, FALSE);
- }
- }
|