You are here

protected function SensorDatabaseAggregator::joinFieldTable in Monitoring 7

Joins the field data table for a given field.

Parameters

\SelectQueryInterface $query: The select query which should be joined.

string $entity_type: The entity type this field belongs to.

string $field_name: Name of the field.

Return value

string Alias of the joined table name.

Throws

\InvalidArgumentException Thrown if the given field does not use the SQL storage.

1 call to SensorDatabaseAggregator::joinFieldTable()
SensorDatabaseAggregator::getFieldName in lib/Drupal/monitoring/Sensor/Sensors/SensorDatabaseAggregator.php
Returns the field name to use for a condition and ensures necessary joins.

File

lib/Drupal/monitoring/Sensor/Sensors/SensorDatabaseAggregator.php, line 247
Contains \Drupal\monitoring\Sensor\Sensors\SensorDatabaseAggregator.

Class

SensorDatabaseAggregator
Base for database aggregator sensors.

Namespace

Drupal\monitoring\Sensor\Sensors

Code

protected function joinFieldTable(\SelectQueryInterface $query, $entity_type, $field_name) {

  // Build the entity table and id column name.
  $entity_info = entity_get_info($entity_type);
  $entity_table_id = $this->info
    ->getSetting('table') . '.' . $entity_info['entity keys']['id'];

  // Check the storage type.
  $field = field_info_field($field_name);
  if ($field['storage']['type'] != 'field_sql_storage') {
    throw new \InvalidArgumentException('Only configurable fields that use the sql storage are supported.');
  }

  // Add the join to the field data table.
  $table_name = _field_sql_storage_tablename($field);
  $alias = $query
    ->join($table_name, $field_name, '%alias.entity_type = :entity_type AND %alias.entity_id = ' . $entity_table_id, array(
    ':entity_type' => $entity_type,
  ));
  return $alias;
}