You are here

public function TMGMTEntityDefaultSourceUIController::getEntitiesTranslationData in Translation Management Tool 7

Gets entities data of provided type needed to build overview form list.

Parameters

$type: Entity type for which to get list of entities.

array $property_conditions: Array of key => $value pairs passed into tmgmt_entity_get_translatable_entities() as the second parameter.

Return value

array Array of entities.

1 call to TMGMTEntityDefaultSourceUIController::getEntitiesTranslationData()
TMGMTEntitySourceUIController::overviewForm in sources/entity/ui/tmgmt_entity_ui.ui.inc

File

sources/entity/tmgmt_entity.ui.inc, line 31

Class

TMGMTEntityDefaultSourceUIController
Abstract entity ui controller class for source plugin that provides getEntity() method to retrieve list of entities of specific type. It also allows to implement alter hook to alter the entity query for a specific type.

Code

public function getEntitiesTranslationData($type, $property_conditions = array()) {
  $return_value = array();
  $entities = tmgmt_entity_get_translatable_entities($type, $property_conditions, TRUE);
  $entity_info = entity_get_info($type);
  $bundles = tmgmt_entity_get_translatable_bundles($type);

  // For retrieved entities add translation specific data.
  foreach ($entities as $entity) {
    list($entity_id, , $bundle) = entity_extract_ids($type, $entity);
    $entity_uri = entity_uri($type, $entity);

    // This occurs on user entity type.
    if (empty($entity_id)) {
      continue;
    }

    /**
     * @var EntityTranslationDefaultHandler $handler
     */
    $handler = entity_translation_get_handler($type, $entity);

    // Get existing translations and current job items for the entity
    // to determine translation statuses
    $translations = $handler
      ->getTranslations();
    $source_lang = entity_language($type, $entity);
    $current_job_items = tmgmt_job_item_load_latest('entity', $type, $entity_id, $source_lang);

    // Load basic entity data.
    $return_value[$entity_id] = array(
      'entity_type' => $type,
      'entity_id' => $entity_id,
      'entity_label' => entity_label($type, $entity),
      'entity_uri' => $entity_uri['path'],
    );
    if (count($bundles) > 1) {
      $return_value[$entity_id]['bundle'] = isset($bundles[$bundle]) ? $bundles[$bundle] : t('Unknown');
    }

    // Load entity translation specific data.
    foreach (language_list() as $langcode => $language) {
      $translation_status = 'current';
      if ($langcode == $source_lang) {
        $translation_status = 'original';
      }
      elseif (!isset($translations->data[$langcode])) {
        $translation_status = 'missing';
      }
      elseif (!empty($translations->data[$langcode]['translate'])) {
        $translation_status = 'outofdate';
      }
      $return_value[$entity_id]['current_job_items'][$langcode] = isset($current_job_items[$langcode]) ? $current_job_items[$langcode] : NULL;
      $return_value[$entity_id]['translation_statuses'][$langcode] = $translation_status;
    }
  }
  return $return_value;
}