class CastedIntFieldJoin

Same name and namespace in other branches
  1. 10 core/modules/views/src/Plugin/views/join/CastedIntFieldJoin.php \Drupal\views\Plugin\views\join\CastedIntFieldJoin

Implementation for the "casted_int_field_join" join.

This is needed for columns that 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.

Attributes

#[ViewsJoin("casted_int_field_join")]

Hierarchy

Expanded class hierarchy of CastedIntFieldJoin

Related topics

1 file declares its use of CastedIntFieldJoin
CastedIntFieldJoinTestBase.php in core/modules/views/tests/src/Kernel/Plugin/CastedIntFieldJoinTestBase.php

File

core/modules/views/src/Plugin/views/join/CastedIntFieldJoin.php, line 17

Namespace

Drupal\views\Plugin\views\join
View source
class CastedIntFieldJoin 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 = $this->leftFormula ?: "{$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}";
    assert(!isset($this->configuration['cast']) || in_array($this->configuration['cast'], [
      'right',
      'left',
    ]));
    if (isset($this->configuration['cast']) && $this->configuration['cast'] === 'left') {
      $left_field = \Drupal::service('views.cast_sql')->getFieldAsInt($left_field);
    }
    else {
      $right_field = \Drupal::service('views.cast_sql')->getFieldAsInt($right_field);
    }
    $condition = "{$left_field} {$this->configuration['operator']} {$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

Title Sort descending Deprecated Modifiers Object type Summary Overriden Title Overrides
CastedIntFieldJoin::buildJoin public function Builds the SQL for the join this object represents. Overrides JoinPluginBase::buildJoin
DependencySerializationTrait::$_entityStorages protected property An array of entity type IDs keyed by the property name of their storages.
DependencySerializationTrait::$_serviceIds protected property An array of service IDs keyed by property name used for serialization.
DependencySerializationTrait::__sleep public function 3
DependencySerializationTrait::__wakeup public function 3
JoinPluginBase::$adjusted public property Defines whether a join has been adjusted.
JoinPluginBase::$configuration public property The configuration array passed by initJoin. Overrides PluginBase::$configuration
JoinPluginBase::$extra public property An array of extra conditions on the join.
JoinPluginBase::$extraOperator public property How all the extras will be combined. Either AND or OR.
JoinPluginBase::$field public property The field to join on (right field).
JoinPluginBase::$leftField public property The field we join to.
JoinPluginBase::$leftFormula public property A formula to be used instead of the left field.
JoinPluginBase::$leftTable public property The table we join to.
JoinPluginBase::$table public property The table to join (right table).
JoinPluginBase::$type public property The join type, so for example LEFT (default) or INNER.
JoinPluginBase::buildExtra protected function Builds a single extra condition.
JoinPluginBase::joinAddExtra protected function Adds the extras to the join condition. 1
JoinPluginBase::__construct public function Constructs a Drupal\views\Plugin\views\join\JoinPluginBase object. Overrides PluginBase::__construct 1
MessengerTrait::$messenger protected property The messenger. 25
MessengerTrait::messenger public function Gets the messenger. 25
MessengerTrait::setMessenger public function Sets the messenger.
PluginBase::$pluginDefinition protected property The plugin implementation definition. 1
PluginBase::$pluginId protected property The plugin ID.
PluginBase::DERIVATIVE_SEPARATOR constant A string which is used to separate base plugin IDs from the derivative ID.
PluginBase::getBaseId public function Gets the base_plugin_id of the plugin instance. Overrides DerivativeInspectionInterface::getBaseId
PluginBase::getDerivativeId public function Gets the derivative_id of the plugin instance. Overrides DerivativeInspectionInterface::getDerivativeId
PluginBase::getPluginDefinition public function Gets the definition of the plugin implementation. Overrides PluginInspectionInterface::getPluginDefinition 2
PluginBase::getPluginId public function Gets the plugin ID of the plugin instance. Overrides PluginInspectionInterface::getPluginId
PluginBase::isConfigurable Deprecated public function Determines if the plugin is configurable.
StringTranslationTrait::$stringTranslation protected property The string translation service. 3
StringTranslationTrait::formatPlural protected function Formats a string containing a count of items.
StringTranslationTrait::getNumberOfPlurals protected function Returns the number of plurals supported by a given language.
StringTranslationTrait::getStringTranslation protected function Gets the string translation service.
StringTranslationTrait::setStringTranslation public function Sets the string translation service to use. 2
StringTranslationTrait::t protected function Translates a string to the current language or to a given language. 1

Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.