CSV File Form use token will make an error

Created on 19 February 2025, 18 days ago

Hello,

CSV File Form use token will make an error (Local file not found.)

This form supports the use of tokens, but local files cannot be found using tokens.

πŸ› Bug report
Status

Active

Version

1.0

Component

Miscellaneous

Created by

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

Merge Requests

Comments & Activities

  • Issue created by @msn5158
  • Using a real file path without using a token, the Column Selector displays as shown in the following picture:

    If a token is used, as shown in the picture below, there will be no selection options and only text-box can be entered as the column for the CSV file.

    Click Apply will display error message:

  • The same method works normal using tokens in Views JSON Source, but it doesn't work properly in Views CSV Source. Has it been damaged?

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

    Thank you for this issue and for looking into this thoroughly. We made some changes to that section to make it easier to get files that had been uploaded to the site. It's definitely possible something was damaged. We'll look into it as soon as possible.

  • When it finds the local file, the Column selector displays a list of options, which is done very well. However, When CSV File Path use Token, The token should be executed first, and after obtaining a value, let it forms a complete file path. At this point, the Column Selector checks whether the file path can find the local file, If it can be found, the Column Selector displays a list of options. If the path does not exist, the Column Selector displays a text box for manually entering the column name. However, error messages caused by the absence of a path should not be displayed and prevent view saving from causing view corruption, as tokens have different values on different pages and will inevitably obtain values on some pages that cause the path to not exist.

    Firstly, it is necessary to ensure that the token works, and then if the detected path does not exist, return an empty result set instead of causing error messages.

    Thank you, Both views_csv-source and views_json-source modules are well done.

  • Merge request !27Edit ViewsCsvQuery.php β†’ (Merged) created by andileco
  • πŸ‡ΊπŸ‡ΈUnited States andileco

    @msn5158 - please try the MR/patch - I think this will fix it.

    We may also create a new feature request to get View (Twig) tokens from the first row, like you can see in Header/Footer/No Result Behavior plugins.

  • I don't know how to use the patch, However, I used the file you modified (src/Plugin/views/query/ViewsCsvQuery.php) to override the local file for testing and it doesn't work. Is there something wrong with me?

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

    Please make sure you've cleared caches. To help me debug, can you add:
    \Drupal::messenger()->addMessage(json_encode($query_options['csv_file']).' QO-A');
    before
    if (!empty($query_options['csv_file'])) { (between line 812 and 813)
    and
    \Drupal::messenger()->addMessage(json_encode($query_options['csv_file']).' QO-B');
    just before
    if (!$query_options['headers']) { (between line 815 and 816)?

    Can you also add
    \Drupal::messenger()->addMessage(json_encode($uri).' A');
    before
    $uri = $this->token->replace($uri); (line 794)
    and
    \Drupal::messenger()->addMessage(json_encode($uri).' B');
    immediately after
    $uri = $this->token->replace($uri); (line 796)?

  • It worked, but there are still error messages prompting.

  • This error message indicates that there is no problem. If the token finds the path, it will not prompt an error and has a selection option in the Column Selector of CSV Field. Now, it's perfect.

  • Pipeline finished with Skipped
    6 days ago
    #438917
    • andileco β†’ committed f699a9e9 on 1.0.x
      Issue #3507762 by andileco, msn5158, nikathone: CSV File Form use token...
  • πŸ‡ΊπŸ‡ΈUnited States andileco

    Thank you for confirming! Marking fixed.

Production build 0.71.5 2024