select('term_node', 'tn') ->distinct() ->fields('tn', ['nid', 'vid']) ->fields('n', ['type']); // Because this is an inner join it enforces the current revision. $query->innerJoin('term_data', 'td', 'td.tid = tn.tid AND td.vid = :vid', [':vid' => $this->configuration['vid']]); $query->innerJoin('node', 'n', static::JOIN); return $query; } /** * {@inheritdoc} */ public function fields() { return [ 'nid' => $this->t('The node revision ID.'), 'vid' => $this->t('The node revision ID.'), 'tid' => $this->t('The term ID.'), ]; } /** * {@inheritdoc} */ public function prepareRow(Row $row) { // Select the terms belonging to the revision selected. $query = $this->select('term_node', 'tn') ->fields('tn', ['tid']) ->condition('n.nid', $row->getSourceProperty('nid')); $query->join('node', 'n', static::JOIN); $query->innerJoin('term_data', 'td', 'td.tid = tn.tid AND td.vid = :vid', [':vid' => $this->configuration['vid']]); $row->setSourceProperty('tid', $query->execute()->fetchCol()); return parent::prepareRow($row); } /** * {@inheritdoc} */ public function getIds() { $ids['vid']['type'] = 'integer'; $ids['vid']['alias'] = 'tn'; return $ids; } }