traitPrepare example


class Query extends BaseQuery {

  use QueryTrait {
    prepare as traitPrepare;
  }

  /** * {@inheritdoc} */
  public function prepare() {
    $this->traitPrepare();

    // If the prepare() method from the trait decided that we need to alter this     // query, we need to re-define the key fields for fetchAllKeyed() as SQL     // expressions.     if ($this->sqlQuery->getMetaData('active_workspace_id')) {
      $id_field = $this->entityType->getKey('id');
      $revision_field = $this->entityType->getKey('revision');

      // Since the query is against the base table, we have to take into account       // that the revision ID might come from the workspace_association       // relationship, and, as a consequence, the revision ID field is no longer
prepare as traitPrepare;
  }

  /** * {@inheritdoc} */
  public function prepare() {
    // Aggregate entity queries do not return an array of entity IDs keyed by     // revision IDs, they only return the values of the aggregated fields, so we     // don't need to add any expressions like we do in     // \Drupal\workspaces\EntityQuery\Query::prepare().     $this->traitPrepare();

    // Throw away the ID fields.     $this->sqlFields = [];
    return $this;
  }

}
Home | Imprint | This part of the site doesn't use cookies.