tmgmt.info.inc 5.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174
  1. <?php
  2. /**
  3. * @file
  4. * Contains the metadata controller classes for the Translation Management Tool
  5. * entities.
  6. */
  7. /**
  8. * Metadata controller for the job entity.
  9. */
  10. class TMGMTJobMetadataController extends EntityDefaultMetadataController {
  11. /**
  12. * {@inheritdoc}
  13. */
  14. public function entityPropertyInfo() {
  15. $info = parent::entityPropertyInfo();
  16. $info = _tmgmt_override_property_description($info, $this->type);
  17. $properties = &$info[$this->type]['properties'];
  18. // Make the created and changed property appear as date.
  19. $properties['changed']['type'] = $properties['created']['type'] = 'date';
  20. // Use the defined entity label callback instead of the custom label directly.
  21. $properties['label']['getter callback'] = 'entity_class_label';
  22. // Allow to change the properties.
  23. foreach (array('target_language', 'source_language', 'translator') as $property) {
  24. $properties[$property]['setter callback'] = 'entity_property_verbatim_set';
  25. }
  26. // Add the options list for the available languages.
  27. $properties['target_language']['options list'] = $properties['source_language']['options list'] = 'entity_metadata_language_list';
  28. // Add the options list for the defined state constants.
  29. $properties['state']['options list'] = 'tmgmt_job_states';
  30. // Add the options list for all available translator plugins.
  31. $properties['translator']['type'] = 'tmgmt_translator';
  32. $properties['translator']['options list'] = 'tmgmt_translator_labels';
  33. // Link the author property to the corresponding user entity.
  34. $properties['author'] = array(
  35. 'label' => t('Author'),
  36. 'type' => 'user',
  37. 'description' => t('The author of the translation job.'),
  38. 'setter callback' => 'entity_property_verbatim_set',
  39. 'setter permission' => 'administer tmgmt',
  40. 'required' => TRUE,
  41. 'schema field' => 'uid',
  42. );
  43. return $info;
  44. }
  45. }
  46. /**
  47. * Metadata controller for the job item entity.
  48. */
  49. class TMGMTJobItemMetadataController extends EntityDefaultMetadataController {
  50. public function entityPropertyInfo() {
  51. $info = parent::entityPropertyInfo();
  52. $info = _tmgmt_override_property_description($info, $this->type);
  53. $properties = &$info[$this->type]['properties'];
  54. // Make the created and changed property appear as date.
  55. $properties['changed']['type'] = 'date';
  56. // Add the options list for the defined state constants.
  57. $properties['state']['options list'] = 'tmgmt_job_item_states';
  58. // Link the job id property to the corresponding job entity.
  59. $properties['tjid'] = array(
  60. 'description' => t('Corresponding job entity.'),
  61. 'type' => 'tmgmt_job',
  62. ) + $properties['tjid'];
  63. // Add the options list for all available source plugins.
  64. $properties['plugin']['options list'] = 'tmgmt_source_plugin_labels';
  65. $properties['word_count']['label'] = t('Word count');
  66. return $info;
  67. }
  68. }
  69. /**
  70. * Metadata controller for the job message entity.
  71. */
  72. class TMGMTMessageMetadataController extends EntityDefaultMetadataController {
  73. /**
  74. * {@inheritdoc}
  75. */
  76. public function entityPropertyInfo() {
  77. $info = parent::entityPropertyInfo();
  78. $info = _tmgmt_override_property_description($info, $this->type);
  79. $properties = &$info[$this->type]['properties'];
  80. // Make the created property appear as date.
  81. $properties['created']['type'] = 'date';
  82. // Link the job id property to the corresponding job entity.
  83. $properties['tjid'] = array(
  84. 'description' => t('Corresponding job entity.'),
  85. 'type' => 'tmgmt_job',
  86. ) + $properties['tjid'];
  87. // Link the job item id property to the corresponding job item entity.
  88. $properties['tjiid'] = array(
  89. 'description' => t('Corresponding job item entity.'),
  90. 'type' => 'tmgmt_job_item',
  91. ) + $properties['tjiid'];
  92. // Link user, was added in an update so make sure that it doesn't explode
  93. // if the schema cache was not cleared.
  94. $properties['uid'] = array(
  95. 'type' => 'user',
  96. 'description' => t('User associated with TMGMT Job Message entity.'),
  97. ) + (isset($properties['uid']) ? $properties['uid'] : array());
  98. return $info;
  99. }
  100. }
  101. /**
  102. * Metadata controller for the translator entity.
  103. */
  104. class TMGMTTranslatorMetadataController extends EntityDefaultMetadataController {
  105. /**
  106. * {@inheritdoc}
  107. */
  108. public function entityPropertyInfo() {
  109. $info = parent::entityPropertyInfo();
  110. $info = _tmgmt_override_property_description($info, $this->type);
  111. $properties = &$info[$this->type]['properties'];
  112. // Options list callback for the translator plugin labels.
  113. $properties['plugin']['options list'] = 'tmgmt_translator_plugin_labels';
  114. return $info;
  115. }
  116. }
  117. /**
  118. * Populates all entity property descriptions based on the schema definition.
  119. *
  120. * @param $info
  121. * Entity propety info array.
  122. *
  123. * @return
  124. * The altered entity properties array.
  125. */
  126. function _tmgmt_override_property_description($info, $entity_type) {
  127. // Load tmgmt.install so we can access the schema.
  128. module_load_install('tmgmt');
  129. $entity_info = entity_get_info($entity_type);
  130. $schema = tmgmt_schema();
  131. $fields = $schema[$entity_info['base table']]['fields'];
  132. $properties = &$info[$entity_type]['properties'];
  133. foreach ($properties as $name => $property_info) {
  134. if (isset($fields[$name]['description'])) {
  135. $properties[$name]['description'] = $fields[$name]['description'];
  136. }
  137. }
  138. return $info;
  139. }