[Tool] Create YAML reader
>>> [!note] Migrated issue <!-- Drupal.org comment --> <!-- Migrated from issue #3554728. --> 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 and extract structured data from YAML files. Since YAML is a widely used configuration and data format, and PHP (and thus Drupal) already supports parsing YAML through Symfony components, this can be natively supported and included as part of the core packages.</p> <p>In terms of naming, the tool could be either "Read YAML Data" or "Load YAML Data". Following the same logic as CSV and JSON, since it is a structured format, "Load YAML Data" would be the most consistent choice.</p> <p>The inputs for this extractor should be:</p> <p>* File Source (binary, required). The YAML file being loaded. How to load this is TBD. An actual serialized YAML string should also be possible.<br> * YAML Path (string, default null). The path within the YAML structure to start extracting from. If null, extract from the root. Uses javascript annotation (e.g. fields.0.value)<br> * Message Format (enum, default yaml). The return format for the message, can also be json, mainly useful for AI or output standardization.</p> <p>The output format in string format will be the YAML file as-is unless a different message format is specified.</p> <p>If YAML Path is used, the root starts from the extracted data, not including the YAML path.</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 it&rsquo;s managed by Drupal, check access to the file entity, otherwise ensure the file is reachable.<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 YAML Data" tool according to the instructions above.<br> * Implement support for a YAML Path extractor that allows loading nested parts of the YAML data, using javascript annotations.<br> * Write unit tests to ensure the output matches the expected input for both full-file and partial extractions.<br> * Add validation to handle malformed YAML and ensure consistent data conversion to PHP arrays.<br> * Use Symfonys YAML serializer/unserializer.</p>
issue