Hello!

I am trying to get how many people request translations. To do that, I am joinning tmgmt_job, tmgmt_job_item, users and node directly from database and I get this data example with this query:

Query

SELECT 
	u.`name`
	-- tj.tjid
	-- , 
  -- , tj.source_language, tj.target_language
	-- , tj. created, tj.label, tj.uid
	, tji.`plugin`, tji.item_type, tji.item_id
	, n.type
	-- , n.title
	, COUNT(tj.uid) as peticiones
FROM tmgmt_job tj
INNER JOIN users u ON u.uid = tj.uid
INNER JOIN tmgmt_job_item tji ON tji.tjid = tj.tjid AND tji.`plugin` = 'entity' AND tji.item_type = 'node'
INNER JOIN node n ON n.nid = tji.item_id
WHERE n.type IN ('oferta_b2c', 'evento_b2c', 'oferta_b2b', 'evento_b2b')
GROUP BY u.uid, n.type
ORDER BY peticiones DESC
;

Result

43asa099		entity	node		228		oferta_b2c	4
43e09900		entity	node		239		oferta_b2b	3
plaadsno		entity	node		752		oferta_b2c	1
ddfo_oro		entity	node		2888		oferta_b2b	1

When I tried to build a view to view this kind of info, a part of query was:

SELECT tmgmt_job_item.tjiid AS tjiid, users_node.name AS users_node_name, users_node.uid AS users_node_uid, node_tmgmt_job_item.type AS node_tmgmt_job_item_type
FROM
{tmgmt_job_item} tmgmt_job_item
INNER JOIN {node} node_tmgmt_job_item ON tmgmt_job_item.item_id = node_tmgmt_job_item.vid AND (tmgmt_job_item.item_type = 'node' AND tmgmt_job_item.plugin = 'node')
LEFT JOIN {tmgmt_job} tmgmt_job_tmgmt_job_item ON tmgmt_job_item.tjid = tmgmt_job_tmgmt_job_item.tjid
LEFT JOIN {users} users_node ON node_tmgmt_job_item.uid = users_node.uid
LIMIT 10 OFFSET 0

As you can see in bold, one condition get by Relation is " tmgmt_job_item.plugin = 'node'" and I think that is wrong, because I get "entity" in the column "plugin" when I retrieve data from the database.

This error came from here, line 35 inside: sources/node/views/tmgmt_node.views.inc as I show here:

'relationship' => array(
          ...
          array(
            'table' => 'tmgmt_job_item',
            'field' => 'plugin',
            'operator' => '=',
            'value' => 'node',
          ),
        ),
      ),

If I change this line from node to entity, the result is correctly, but I am not sure If it is the correct approach.

Support from Acquia helps fund testing for Drupal Acquia logo

Comments

Daniel Royo created an issue. See original summary.

daniroyo’s picture

I tried to created my first patch, but I am not sure the correct way.

daniroyo’s picture

I am investigating a bit more about that.

There are a lot of piece of code that use entity as plugin, for example:

C:\devdesktop\esMadridPro\profiles\clusters\modules\contrib\tmgmt\sources\entity\ui\tmgmt_entity_ui.pages.inc

function tmgmt_entity_ui_translate_form_submit($form, &$form_state) {
  $entity = $form_state['entity'];
  $entity_type = $form_state['entity_type'];
  list($id, $vid, $bundle) = entity_extract_ids($entity_type, $entity);
  $values = $form_state['values'];
  $jobs = array();
  foreach (array_keys(array_filter($values['languages'])) as $langcode) {
    // Create the job object.
    $job = tmgmt_job_create(entity_language($entity_type, $entity), $langcode, $GLOBALS['user']->uid);
    try {
      // Add the job item.
      $job->addItem('entity', $entity_type, $id);
      // Append this job to the array of created jobs so we can redirect the user
      // to a multistep checkout form if necessary.
      $jobs[$job->tjid] = $job;
    }
    catch (TMGMTException $e) {
      watchdog_exception('tmgmt', $e);
      $languages = language_list();
      $target_lang_name = $languages[$langcode]->language;
      drupal_set_message(t('Unable to add job item for target language %name. Make sure the source content is not empty.', array('%name' => $target_lang_name)), 'error');
    }
  }
  tmgmt_ui_job_checkout_and_redirect($form_state, $jobs);
}

or...

C:\devdesktop\esMadridPro\profiles\clusters\modules\contrib\tmgmt\sources\entity\ui\tmgmt_entity_ui.ui.inc:145

$job->addItem('entity', $type, $entity_id);

Til the bug was resolve, I will use this piece of code to work properly.

function MYHOOK_views_data_alter(&$data) {
  if (!empty($data['tmgmt_job_item']) && !empty($data['tmgmt_job_item']['job_item_to_node'])) {
    print_r($data['tmgmt_job_item']['job_item_to_node']);
    foreach ($data['tmgmt_job_item']['job_item_to_node']['relationship']['extra'] as $key => &$value) {
      if ($value['table'] == 'tmgmt_job_item' && $value['field'] == 'plugin' && $value['value'] == 'node') {
        $value['value'] = 'entity';
      }
    }
  } 
}
Berdir’s picture

Status: Active » Closed (works as designed)

There are two different plugins. node and entity. node is the core translation.module, entity is entity_translation.

We only have views integration for the node source, while you seem to be using entity translation.

This is by design, we can't change this.

daniroyo’s picture

Thanks @Berdir for your response, You are right, we are using entity_translation, so, I assume It is ok by your point of view.

vtkachenko’s picture

We have to use nid instead of vid in TMGMTNodeSourceViewsController::views_data().

Because $job_item->item_id stores nid, but not vid. That is why there difference in result.

vtkachenko’s picture

Status: Closed (works as designed) » Needs work
vtkachenko’s picture