class CastedFieldJoin in Entityqueue 8
Implementation for the "casted_field_join" join.
This is needed because subqueues are using a single table for tracking the relationship to their items, but the referenced item IDs can be either integers or strings and most DB engines (with MySQL as a notable exception) are strict when comparing numbers and strings.
Plugin annotation
@ViewsJoin("casted_field_join");
Hierarchy
- class \Drupal\Component\Plugin\PluginBase implements DerivativeInspectionInterface, PluginInspectionInterface
- class \Drupal\Core\Plugin\PluginBase uses DependencySerializationTrait, MessengerTrait, StringTranslationTrait
- class \Drupal\views\Plugin\views\join\JoinPluginBase implements JoinPluginInterface
- class \Drupal\entityqueue\Plugin\views\join\CastedFieldJoin
- class \Drupal\views\Plugin\views\join\JoinPluginBase implements JoinPluginInterface
- class \Drupal\Core\Plugin\PluginBase uses DependencySerializationTrait, MessengerTrait, StringTranslationTrait
Expanded class hierarchy of CastedFieldJoin
File
- src/
Plugin/ views/ join/ CastedFieldJoin.php, line 20
Namespace
Drupal\entityqueue\Plugin\views\joinView source
class CastedFieldJoin extends JoinPluginBase {
/**
* {@inheritdoc}
*/
public function buildJoin($select_query, $table, $view_query) {
if (empty($this->configuration['table formula'])) {
$right_table = $this->table;
}
else {
$right_table = $this->configuration['table formula'];
}
if ($this->leftTable) {
$left_table = $view_query
->getTableInfo($this->leftTable);
$left_field = "{$left_table['alias']}.{$this->leftField}";
}
else {
// This can be used if left_field is a formula or something. It should be
// used only *very* rarely.
$left_field = $this->leftField;
$left_table = NULL;
}
$right_field = "{$table['alias']}.{$this->field}";
// Determine whether the left field of the relationship is an integer so we
// know whether a CAST() is needed for the right field.
if (isset($this->configuration['entity_type'])) {
$field_storage_definition = \Drupal::service('entity_field.manager')
->getFieldStorageDefinitions($this->configuration['entity_type'])[$this->leftField];
if (is_a($field_storage_definition
->getItemDefinition()
->getClass(), IntegerItem::class, TRUE)) {
switch (\Drupal::database()
->databaseType()) {
case 'mysql':
$cast_data_type = 'UNSIGNED';
break;
default:
$cast_data_type = 'INTEGER';
break;
}
$right_field = "CAST({$right_field} AS {$cast_data_type})";
}
}
$condition = "{$left_field} = {$right_field}";
$arguments = [];
// Tack on the extra.
if (isset($this->extra)) {
$this
->joinAddExtra($arguments, $condition, $table, $select_query, $left_table);
}
$select_query
->addJoin($this->type, $right_table, $table['alias'], $condition, $arguments);
}
}
Members
Name | Modifiers | Type | Description | Overrides |
---|---|---|---|---|
CastedFieldJoin:: |
public | function |
Builds the SQL for the join this object represents. Overrides JoinPluginBase:: |
|
DependencySerializationTrait:: |
protected | property | An array of entity type IDs keyed by the property name of their storages. | |
DependencySerializationTrait:: |
protected | property | An array of service IDs keyed by property name used for serialization. | |
DependencySerializationTrait:: |
public | function | 1 | |
DependencySerializationTrait:: |
public | function | 2 | |
JoinPluginBase:: |
public | property | Defines whether a join has been adjusted. | |
JoinPluginBase:: |
public | property |
The configuration array passed by initJoin. Overrides PluginBase:: |
|
JoinPluginBase:: |
public | property | An array of extra conditions on the join. | |
JoinPluginBase:: |
public | property | How all the extras will be combined. Either AND or OR. | |
JoinPluginBase:: |
public | property | The field to join on (right field). | |
JoinPluginBase:: |
public | property | The field we join to. | |
JoinPluginBase:: |
public | property | A formula to be used instead of the left field. | |
JoinPluginBase:: |
public | property | The table we join to. | |
JoinPluginBase:: |
public | property | The table to join (right table). | |
JoinPluginBase:: |
public | property | The join type, so for example LEFT (default) or INNER. | |
JoinPluginBase:: |
protected | function | Builds a single extra condition. | |
JoinPluginBase:: |
protected | function | Adds the extras to the join condition. | 1 |
JoinPluginBase:: |
public | function |
Constructs a Drupal\views\Plugin\views\join\JoinPluginBase object. Overrides PluginBase:: |
1 |
MessengerTrait:: |
protected | property | The messenger. | 29 |
MessengerTrait:: |
public | function | Gets the messenger. | 29 |
MessengerTrait:: |
public | function | Sets the messenger. | |
PluginBase:: |
protected | property | The plugin implementation definition. | 1 |
PluginBase:: |
protected | property | The plugin_id. | |
PluginBase:: |
constant | A string which is used to separate base plugin IDs from the derivative ID. | ||
PluginBase:: |
public | function |
Gets the base_plugin_id of the plugin instance. Overrides DerivativeInspectionInterface:: |
|
PluginBase:: |
public | function |
Gets the derivative_id of the plugin instance. Overrides DerivativeInspectionInterface:: |
|
PluginBase:: |
public | function |
Gets the definition of the plugin implementation. Overrides PluginInspectionInterface:: |
3 |
PluginBase:: |
public | function |
Gets the plugin_id of the plugin instance. Overrides PluginInspectionInterface:: |
|
PluginBase:: |
public | function | Determines if the plugin is configurable. | |
StringTranslationTrait:: |
protected | property | The string translation service. | 1 |
StringTranslationTrait:: |
protected | function | Formats a string containing a count of items. | |
StringTranslationTrait:: |
protected | function | Returns the number of plurals supported by a given language. | |
StringTranslationTrait:: |
protected | function | Gets the string translation service. | |
StringTranslationTrait:: |
public | function | Sets the string translation service to use. | 2 |
StringTranslationTrait:: |
protected | function | Translates a string to the current language or to a given language. |