Issue with UUID Field Keys in php Blueprints

I’m creating a php blueprint that dynamically creates tag fields based on taxonomy categories (pages). When using category UUIDs as field keys, the data won’t save, but it works fine when using simple string keys.

When using $category->uuid()->toString() as the field key, the form displays correctly but doesn’t save the data. However, if I change the key to something like 'category_' . $index, everything works as expected.

Is there a restriction on what characters can be used in field keys? What’s the recommended approach for maintaining a relationship between dynamic fields and their corresponding pages while ensuring the data saves properly?

Thanks in advance for any help!

Here’s my current code:

<?php
/**
 * Category Tags Blueprint Field Generator
 * 
 * Dynamically generates a group of tag fields for job categories. Each category from the job overview page
 * is converted into a tags field where users can select from predefined taxonomy terms.
 *
 * The field generator:
 * 1. Finds the job overview page in the site structure
 * 2. Gets all taxonomy pages under it (categories)
 * 3. For each category, creates a tags field using its published taxonomy terms as options
 * 4. Groups all generated tag fields into a single blueprint field
 *
 *
 * @param Kirby\Cms\App $kirby The Kirby instance to access site structure
 * @return array The complete blueprint field definition as a YAML-compatible array
 */

// Find all taxonomy pages under the job overview page
$categories = $kirby->site()
    ->children()
    ->findBy('intendedTemplate', 'job-overview')
    ->children()
    ->filterBy('intendedTemplate', 'taxonomy');

// Initialize array to store generated fields
$fields = [];
// Generate a tags field for each category
foreach ($categories as $category) {
    $key = $category->uuid()->toString();
    $fields[$key] = [
        'label' => $category->title(), // Use category name as field label
        'type' => 'tags',
        'options' => [
            'type' => 'query',
            'query' => 'page("' . $category->uuid() . '").children().published()',
            'value' => '{{ page.uuid }}',
        ],
        'help' => 'Select applicable tags for this category' // Add helpful instruction
    ];
}

// Create the final blueprint structure
$yaml = [
    'type' => 'group',    // Group all category tag fields together
    'fields' => $fields,  // Include all generated tag fields
];


return $yaml;

I think it’s the :// from UUIDs that is not suitable for field keys. But since you’re not mixing user, files and pages UUIDs, but with these only refer pages UUIDs, you could try ->uuid()->id() instead to get only the part after the ://.

1 Like

That did the trick! The strange thing was that I also ran into this problem when using ->slug() or ->id().