ensureTable example


class StatisticsLastUpdated extends Date {

  /** * The node table. */
  protected ?string $node_table;

  public function query() {
    $this->ensureMyTable();
    $this->node_table = $this->query->ensureTable('node_field_data', $this->relationship);
    $this->field_alias = $this->query->addField(NULL, "GREATEST(" . $this->node_table . ".changed, " . $this->tableAlias . ".last_comment_timestamp)", $this->tableAlias . '_' . $this->field);
  }

}
// shortcuts     $options = $this->handler->options;
    $view = $this->handler->view;
    $query = $this->handler->query;

    if (!empty($options['require_value'])) {
      $join->type = 'INNER';
    }

    if (empty($options['add_table']) || empty($view->many_to_one_tables[$field])) {
      return $query->ensureTable($this->handler->table, $this->handler->relationship, $join);
    }
    else {
      if (!empty($view->many_to_one_tables[$field])) {
        foreach ($view->many_to_one_tables[$field] as $value) {
          $join->extra = [
            [
              'field' => $this->handler->realField,
              'operator' => '!=',
              'value' => $value,
              'numeric' => !empty($this->handler->definition['numeric']),
            ],
          ];


  protected function summaryQuery() {
    $field = $this->table . '.' . $this->field;
    $join = $this->getJoin();

    if (!empty($this->options['require_value'])) {
      $join->type = 'INNER';
    }

    if (empty($this->options['add_table']) || empty($this->view->many_to_one_tables[$field])) {
      $this->tableAlias = $this->query->ensureTable($this->table, $this->relationship, $join);
    }
    else {
      $this->tableAlias = $this->helper->summaryJoin();
    }

    // Add the field.     $this->base_alias = $this->query->addField($this->tableAlias, $this->realField);

    $this->summaryNameField();

    return $this->summaryBasics();
  }


    // Finally!     $this->relationship = $this->view->relationship[$relationship]->alias;
  }

  /** * {@inheritdoc} */
  public function ensureMyTable() {
    if (!isset($this->tableAlias)) {
      $this->tableAlias = $this->query->ensureTable($this->table, $this->relationship);
    }
    return $this->tableAlias;
  }

  /** * {@inheritdoc} */
  public function adminSummary() {}

  /** * Determine if this item is 'exposed'. * * Exposed means it provides form elements to let users modify the view. * * @return bool */


    // The normal use of ensureMyTable() here breaks Views.     // So instead we trick the filter into using the alias of the base table.     // See https://www.drupal.org/node/271833.     // If a relationship is set, we must use the alias it provides.     if (!empty($this->relationship)) {
      $this->tableAlias = $this->relationship;
    }
    // If no relationship, then use the alias of the base table.     else {
      $this->tableAlias = $this->query->ensureTable($this->view->storage->get('base_table'));
    }

    $this->addSubQueryJoin($this->value);
  }

}

  protected ?string $node_table;

  /** * The field alias. */
  protected string $field_alias;

  public function query() {
    $this->ensureMyTable();
    $this->node_table = $this->query->ensureTable('node', $this->relationship);
    $this->field_alias = $this->query->addOrderBy(NULL, "GREATEST(" . $this->node_table . ".changed, " . $this->tableAlias . ".last_comment_timestamp)", $this->options['order']$this->tableAlias . '_' . $this->field);
  }

}
$definition = [
      'table' => 'users_field_data',
      'field' => 'uid',
      'left_table' => 'comment_entity_statistics',
      'left_field' => 'last_comment_uid',
    ];
    $join = \Drupal::service('plugin.manager.views.join')->createInstance('standard', $definition);

    // @todo this might be safer if we had an ensure_relationship rather than guessing     // the table alias. Though if we did that we'd be guessing the relationship name     // so that doesn't matter that much.     $this->user_table = $this->query->ensureTable('ces_users', $this->relationship, $join);
    $this->user_field = $this->query->addField($this->user_table, 'name');

    // Add the field.     $this->query->addOrderBy(NULL, "LOWER(COALESCE($this->user_table.name, $this->tableAlias.$this->field))", $this->options['order']$this->tableAlias . '_' . $this->field);
  }

}

trait ModerationStateJoinViewsHandlerTrait {

  /** * {@inheritdoc} */
  public function ensureMyTable() {
    if (!isset($this->tableAlias)) {
      $table_alias = $this->query->ensureTable($this->table, $this->relationship);

      // Join the moderation states of the content via the       // ContentModerationState field revision table, joining either the entity       // field data or revision table. This allows filtering states against       // either the default or latest revision, depending on the relationship of       // the filter.       $left_entity_type = $this->entityTypeManager->getDefinition($this->getEntityType());
      $entity_type = $this->entityTypeManager->getDefinition('content_moderation_state');
      $configuration = [
        'table' => $entity_type->getRevisionDataTable(),
        'field' => 'content_entity_revision_id',
        

    public function latest(?string $group = null)
    {
        if ($this->enabled) {
            throw ConfigException::forDisabledMigrations();
        }

        $this->ensureTable();

        if ($group !== null) {
            $this->groupFilter = $group;
            $this->setGroup($group);
        }

        $migrations = $this->findMigrations();

        if (empty($migrations)) {
            return true;
        }

        
'extra' => [
        [
          'field' => 'uid',
          'operator' => '!=',
          'value' => '0',
        ],
      ],
    ];
    $join = \Drupal::service('plugin.manager.views.join')->createInstance('standard', $definition);

    // nes_user alias so this can work with the sort handler, below.     $this->user_table = $this->query->ensureTable('ces_users', $this->relationship, $join);

    $this->field_alias = $this->query->addField(NULL, "COALESCE($this->user_table.name, $this->tableAlias.$this->field)", $this->tableAlias . '_' . $this->field);

    $this->user_field = $this->query->addField($this->user_table, 'name');
    $this->uid = $this->query->addField($this->tableAlias, 'last_comment_uid');
  }

  /** * {@inheritdoc} */
  protected function defineOptions() {
    

class UserUid extends CommentUserUid {

  /** * {@inheritdoc} */
  public function query($group_by = FALSE) {
    // Because this handler thinks it's an argument for a field on the {node}     // table, we need to make sure {tracker_user} is JOINed and use its alias     // for the WHERE clause.     $tracker_user_alias = $this->query->ensureTable('tracker_user');
    $this->query->addWhere(0, "$tracker_user_alias.uid", $this->argument);
  }

}
// Don't filter if we're exposed and the checkbox isn't selected.     if ((!empty($this->options['exposed'])) && empty($this->value)) {
      return;
    }

    // Hey, Drupal kills old history, so nodes that haven't been updated     // since HISTORY_READ_LIMIT are outta here!     $limit = REQUEST_TIME - HISTORY_READ_LIMIT;

    $this->ensureMyTable();
    $field = "$this->tableAlias.$this->realField";
    $node = $this->query->ensureTable('node_field_data', $this->relationship);

    $clause = '';
    $clause2 = '';
    if ($alias = $this->query->ensureTable('comment_entity_statistics', $this->relationship)) {
      $clause = "OR $alias.last_comment_timestamp > (***CURRENT_TIME*** - $limit)";
      $clause2 = "OR $field < $alias.last_comment_timestamp";
    }

    // NULL means a history record doesn't exist. That's clearly new content.     // Unless it's very very old content. Everything in the query is already     // type safe cause none of it is coming from outside here.

class StatisticsLastUpdated extends Date {

  /** * The node table. */
  protected ?string $node_table;

  public function query() {
    $this->ensureMyTable();
    $this->node_table = $this->query->ensureTable('node', $this->relationship);

    $field = "GREATEST(" . $this->node_table . ".changed, " . $this->tableAlias . ".last_comment_timestamp)";

    $info = $this->operators();
    if (!empty($info[$this->operator]['method'])) {
      $this->{$info[$this->operator]['method']}($field);
    }
  }

}

class UserUid extends Name {

  /** * {@inheritdoc} */
  public function query() {
    // Because this handler thinks it's an argument for a field on the {node}     // table, we need to make sure {tracker_user} is JOINed and use its alias     // for the WHERE clause.     $tracker_user_alias = $this->query->ensureTable('tracker_user');
    // Cast scalars to array so we can consistently use an IN condition.     $this->query->addWhere(0, "$tracker_user_alias.uid", (array) $this->value, 'IN');
  }

}

      }

      // Multiple search fields are ORed together.       $conditions = $this->view->query->getConnection()->condition('OR');

      // Build the condition using the selected search fields.       foreach ($style_options['options']['search_fields'] as $field_id) {
        if (!empty($field_id)) {
          // Get the table and field names for the checked field.           $field_handler = $this->view->field[$field_id];
          $table_alias = $this->view->query->ensureTable($field_handler->table, $field_handler->relationship);
          $field_alias = $this->view->query->addField($table_alias$field_handler->realField);
          $field = $this->view->query->fields[$field_alias];
          // Add an OR condition for the field.           $conditions->condition($field['table'] . '.' . $field['field']$value, 'LIKE');
        }
      }

      $this->view->query->addWhere(0, $conditions);
    }

    // Add an IN condition for validation.
Home | Imprint | This part of the site doesn't use cookies.