Example query does not work for Drupal 8+

Created on 17 December 2021, about 3 years ago

Problem/Motivation

The example query shown on the module page does not seem to work for Drupal 8+

Steps to reproduce

I have created a new content type "institution" and added an IP address field "field_institution_ip_range".

I have tried rewriting the example query for Drupal 9 as shown below. It executes without error, but it fails to find any matches

$visitor_addr = ip2long(Drupal::request()->getClientIp());
$query = Drupal::entityQuery('node')
    ->condition('type', 'institution')
    ->condition('status', 1)
    ->condition('field_institution_ip_range.ip_start', $visitor_addr, '<=')
    ->condition('field_institution_ip_range.ip_end', $visitor_addr, '>=')
    ->execute();

I can execute an SQL query against the Drupal database using my current IP address and do indeed find a match.

SELECT DISTINCT entity_id 
FROM node__field_institution_ip_range 
WHERE
    field_institution_ip_range_ip_start <= INET6_ATON(MY_IP_ADDRESS) AND
    field_institution_ip_range_ip_end >= INET6_ATON(MY_IP_ADDRESS)

Proposed resolution

Could the documentation be updated with an example for Drupal 8+ please?

💬 Support request
Status

Active

Version

2.0

Component

Documentation

Created by

🇨🇦Canada g011um Saskatoon

Live updates comments and jobs are added and updated live.
Sign in to follow issues

Comments & Activities

Not all content is available!

It's likely this issue predates Contrib.social: some issue and comment data are missing.

Production build 0.71.5 2024