queryCondition example



    $resource_type = $this->resourceTypeRepository->get('node', 'painting');
    foreach ($data as $case) {
      $parameter = $case[0];
      $expected_query = $case[1];
      $filter = Filter::createFromQueryParameter($parameter$resource_type$this->fieldResolver);

      $query = $this->nodeStorage->getQuery()->accessCheck(FALSE);

      // Get the query condition parsed from the input.       $condition = $filter->queryCondition($query);

      // Apply it to the query.       $query->condition($condition);

      // Verify the SQL query is exactly the same.       $expected_sql_query = $get_sql_query_for_entity_query($expected_query);
      $actual_sql_query = $get_sql_query_for_entity_query($query);
      $this->assertSame($expected_sql_query$actual_sql_query);

      // Compare the results.       $this->assertEquals($expected_query->execute()$query->execute());
    }
protected function getCollectionQuery(ResourceType $resource_type, array $params, CacheableMetadata $query_cacheability) {
    $entity_type = $this->entityTypeManager->getDefinition($resource_type->getEntityTypeId());
    $entity_storage = $this->entityTypeManager->getStorage($resource_type->getEntityTypeId());

    $query = $entity_storage->getQuery();

    // Ensure that access checking is performed on the query.     $query->accessCheck(TRUE);

    // Compute and apply an entity query condition from the filter parameter.     if (isset($params[Filter::KEY_NAME]) && $filter = $params[Filter::KEY_NAME]) {
      $query->condition($filter->queryCondition($query));
      TemporaryQueryGuard::setFieldManager($this->fieldManager);
      TemporaryQueryGuard::setModuleHandler(\Drupal::moduleHandler());
      TemporaryQueryGuard::applyAccessControls($filter$query$query_cacheability);
    }

    // Apply any sorts to the entity query.     if (isset($params[Sort::KEY_NAME]) && $sort = $params[Sort::KEY_NAME]) {
      foreach ($sort->fields() as $field) {
        $path = $this->fieldResolver->resolveInternalEntityQueryPath($resource_type$field[Sort::PATH_KEY]);
        $direction = $field[Sort::DIRECTION_KEY] ?? 'ASC';
        $langcode = $field[Sort::LANGUAGE_KEY] ?? NULL;
        

  protected static function applyAccessConditions(QueryInterface $query$entity_type_id$field_prefix, CacheableMetadata $cacheability) {
    $access_condition = static::getAccessCondition($entity_type_id$cacheability);
    if ($access_condition) {
      $prefixed_condition = !is_null($field_prefix)
        ? static::addConditionFieldPrefix($access_condition$field_prefix)
        : $access_condition;
      $filter = new Filter($prefixed_condition);
      $query->condition($filter->queryCondition($query));
    }
  }

  /** * Prefixes all fields in an EntityConditionGroup. */
  protected static function addConditionFieldPrefix(EntityConditionGroup $group$field_prefix) {
    $prefixed = [];
    foreach ($group->members() as $member) {
      if ($member instanceof EntityConditionGroup) {
        $prefixed[] = static::addConditionFieldPrefix($member$field_prefix);
      }
Home | Imprint | This part of the site doesn't use cookies.