Skip to main content
Drupal is a registered trademark of Dries Buytaert
Release: MCP Sentinel 2.29.0 — Minor update available for module mcp_sentinel (2.29.0). Release: Audit Chain 1.10.9 — Minor update available for module audit_chain (1.10.9). Release: Menu Autopilot 1.4.7 — Minor update available for module menu_autopilot (1.4.7). Release: FileGate 1.11.3 — Minor update available for module file_gate (1.11.3). Release: Download Tracker 1.0.7 — Minor update available for module download_tracker (1.0.7). Release: Directory2Block Slideshow 1.0.8 — Minor update available for module directory2block_slideshow (1.0.8). Release: Mautic Audiences 1.1.5 — Minor update available for module mautic_audiences (1.1.5). Release: Rightup theme 1.0.3 — Minor update available for theme vartheme_bs5_rightup (1.0.3). Module Revived: Swagger-PHP OpenAPI 3 documentation generator 1.0.0 — Module swagger_php updated after 10 months of inactivity (1.0.0). Security Coverage: Microsoft Azure AI — Module ai_provider_azure now has official Drupal security advisory coverage.

A simple module to expose Drupal's autocomplete handlers via JSONRPC. Auto create functionality provided by core has not been tested.

Why use this module?

The main benefit to this module's autocomplete is the use of Drupal's selection handlers allowing for a decoupled entity autocomplete experience that is nearly identical to Drupal's core entity reference field. The module differs slightly from core in the data it returns, core only returns preformatted data to render a select field whereas this module returns additional information to use as needed.

The other benefit to using selection handlers vs direct querying of JSON:API or JSON:API Search API is that a selection can easily be validated on the backend using the exact same selection logic that was used for the front end.

Request

To run a search you can use a POST request

{
  "jsonrpc": "2.0",
  "method": "autocomplete",
  "id": "autocomplete",
  "params": {
    "target_type": "node",
    "selection_handler": "default",
    "selection_settings": {
      "target_bundles": null,
      "sort": {
        "field": "_none",
        "direction": "ASC"
      }
    },
    "query": "search string goes here"
  }
}

or a GET request that uses the url encoded POST data

https://example.org/jsonrpc?query=%7B%22jsonrpc%22%3A%222.0%22%2C%22method%22%3A%22autocomplete%22%2C%22id%22%3A%22autocomplete%22%2C%22params%22%3A%7B%22target_type%22%3A%22node%22%2C%22selection_handler%22%3A%22default%22%2C%22selection_settings%22%3A%7B%22target_bundles%22%3Anull%2C%22sort%22%3A%7B%22field%22%3A%22_none%22%2C%22direction%22%3A%22ASC%22%7D%7D%2C%22query%22%3A%22h%22%7D%7D

Selection settings structure

The selection_settings value supports all options defined for the chosen handler. The settings should be formatted as a JSON object structured identically to the PHP or YAML versions of the settings.

Response

{
  "jsonrpc": "2.0",
  "id": "autocomplete",
  "result": [
    {
      "id": "5",
      "uuid": "df078d9e-b34e-4719-a9fc-b8946b63acaf",
      "type": "node",
      "bundle": "page",
      "label": "Example"
    },
    {
      "id": "1",
      "uuid": "d93d7f5b-f36d-4a76-ae9d-24bc56e06d0b",
      "type": "node",
      "bundle": "page",
      "label": "Homepage"
    }
  ]
}

Depends on

Dependencies of the latest stable release

No dependencies recorded for this project.

Required by

Tracked projects that depend on this one

No tracked projects depend on this one yet.

Activity

Tracked releases
1
Tracked since
Feb 2023
Latest release
3 years ago
Releases (12 mo)
0
Maintenance
Dormant

Releases

Version Type Core Release date
1.0.0-beta1 Pre-release Feb 4, 2023