[Tools] Create CSV reader
>>> [!note] Migrated issue <!-- Drupal.org comment --> <!-- Migrated from issue #3554441. --> Reported by: [marcus_johansson](https://www.drupal.org/user/385947) >>> <h3 id="summary-problem-motivation">Problem/Motivation</h3> <p>You need to be able to read CSV data. Since CSV files are stringable and readable by PHP, this can be natively supported and can thus be part of the core packages.</p> <p>In terms of naming, the tool could be either "Read CSV Data" or "Load CSV Data". Since its a structured format, I think the "Load CSV Data" is the correct naming, and the same is true for XML, YAML and JSON data as well, while you read a txt file for instance. I'm not sure if that is consistent though. Discuss.</p> <p>To make it flexible enough, the inputs will be:</p> <p>* File Source (binary, required). This is the file being loaded. How to load this is TBD.<br> * Start Row (integer). This is the starting row if wanted. Default to 0 if return keyed is false, otherwise 1.<br> * Row Limit (integer, default null). This is the amount of rows to collect.<br> * Selected Columns (array<string>, defaullt null). The selected columns to return, can be set via numeric keys or header keys.<br> * Delimiter (string, default null). The delimiter to use, null means automatically figure out.<br> * Return Keyed (boolean, default false). Returns the data as an associative array with the header rows keys. Otherwise numeric array.<br> * Message format (enum, default csv). Return format for the message, can also be yaml or json, useful for AI mainly.</string></p> <p>The output format in string format will be the CSV file as it is, unless message format is given.</p> <p>The output format will be map, that will be rows of data that are either filled with associative or numeric arrays of key/value.</p> <p>As for checkAccess, if the file loading happens before this tool, nothing should really need to be checked. If the file loading from uri, url, fid etc. happens here it has to be:</p> <p>1. fid - check access to the file entity<br> 2. uri - if its managed by Drupal, check the access to the file entity, otherwise check that the file can be reached<br> 3. url - check that the file can be reached<br> 4. data - no checks needed</p> <h3 id="summary-proposed-resolution">Proposed resolution</h3> <p>* If the tool_utilities submodule does not exist yet, create the metadata for it.<br> * Create the Load CSV Data according to instructions above.<br> * Write unit tests for it, to see that output matches input.</p>
issue