public function ItemCount::query

File

translators/tmgmt_local/src/Plugin/views/field/ItemCount.php, line 59

Class

ItemCount
Field handler to show the amount of job items per task.

Namespace

Drupal\tmgmt_local\Plugin\views\field

Code

public function query() {
  $this
    ->ensureMyTable();

  // Therefore construct the join.
  // Add the join for the tmgmt_job_item table.
  $configuration = array(
    'table' => 'tmgmt_job_item',
    'field' => 'tjid',
    'left_table' => $this->tableAlias,
    'left_field' => 'tjid',
    'operator' => '=',
  );
  if (!empty($this->options['state'])) {
    $configuration['extra'] = [
      [
        'field' => 'state',
        'value' => $this->options['state'],
      ],
    ];
  }

  /** @var \Drupal\views\Plugin\views\join\Standard $join */
  $join = Views::pluginManager('join')
    ->createInstance('standard', $configuration);

  // Add the join to the tmgmt_job_item table.
  $this->tableAlias = $this->query
    ->addTable('tmgmt_job_item', $this->relationship, $join);

  // And finally add the count of the job items field.
  $params = array(
    'function' => 'count',
  );
  $this->field_alias = $this->query
    ->addField($this->tableAlias, 'tjiid', NULL, $params);
  $this
    ->addAdditionalFields();
}