You are here

public function MetatagFieldInstance::query in Metatag 8

Return value

\Drupal\Core\Database\Query\SelectInterface

Overrides SqlBase::query

File

src/Plugin/migrate/source/d7/MetatagFieldInstance.php, line 50

Class

MetatagFieldInstance
Drupal 7 Metatag field instances.

Namespace

Drupal\metatag\Plugin\migrate\source\d7

Code

public function query() {
  $base_query = $this
    ->select('metatag', 'm')
    ->fields('m', [
    'entity_type',
  ])
    ->groupBy('entity_type');
  if (isset($this->configuration['entity_type_id'])) {
    $entity_type_id = $this->configuration['entity_type_id'];
    $base_query
      ->condition('m.entity_type', $entity_type_id);
    if (isset($this->configuration['bundle'])) {
      $bundle = $this->configuration['bundle'];
      switch ($entity_type_id) {
        case 'node':

          // We want to get a per-node-type metatag migration. So we inner join
          // the base query on node table based on the parsed node ID.
          $base_query
            ->join('node', 'n', "n.nid = m.entity_id");
          $base_query
            ->condition('n.type', $bundle);
          $base_query
            ->addField('n', 'type', 'bundle');
          $base_query
            ->groupBy('bundle');
          break;
        case 'taxonomy_term':

          // Join the taxonomy term data table to the base query; based on
          // the parsed taxonomy term ID.
          $base_query
            ->join('taxonomy_term_data', 'ttd', "ttd.tid = m.entity_id");
          $base_query
            ->fields('ttd', [
            'vid',
          ]);

          // Since the "taxonomy_term_data" table contains only the taxonomy
          // vocabulary ID, but not the vocabulary name, we have to inner
          // join the "taxonomy_vocabulary" table as well.
          $base_query
            ->join('taxonomy_vocabulary', 'tv', 'ttd.vid = tv.vid');
          $base_query
            ->condition('tv.machine_name', $bundle);
          $base_query
            ->addField('tv', 'machine_name', 'bundle');
          $base_query
            ->groupBy('ttd.vid');
          $base_query
            ->groupBy('bundle');
          break;
      }
    }
  }
  return $base_query;
}