Use of Tokens in Json File Path

Created on 21 November 2022, almost 2 years ago
Updated 8 November 2024, 6 days ago

Problem/Motivation

Hi, thank you for this great module. I've tried to use dynamic tokens from the Token module in the path URL for my JSON Endpoint. Tokens like [current-page:title] etc work fine (when included as block-view in individual content). However, I wasn't able to use node related tokens like [node:nid] or [node:field_XXX]. A feature like this would add great flexibility to integrate individual content into the platform. Any advice would be very appreciated. Thanks!

✨ Feature request
Status

Active

Version

1.4

Component

Module

Created by

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.

  • πŸ‡ΊπŸ‡ΈUnited States karenann

    I ended up here because I see the "Note: Can use Drupal token as well." on the JSON file path setting, but when I put a token in that value, I can't even save the view. I'm getting the error:

    Exception: Local file not found. in Drupal\views_json_source\Plugin\views\query\ViewsJsonQuery->fetchFile() (line 235 of modules/contrib/views_json_source/src/Plugin/views/query/ViewsJsonQuery.php).

    generated from:

      public function fetchFile($uri) {
        $parsed = parse_url($uri);
        // Check for local file.
        if (empty($parsed['host'])) {
          if (!file_exists(DRUPAL_ROOT . $uri)) {
            throw new \Exception('Local file not found.');
    ...
    

    So I headed to public function execute, right above where fetchFile is called, I can see where the replacement was supposed to happen. The comment references [site:url], so that's the token I was testing with. The replacement is not succeeding.

Production build 0.71.5 2024