# Changelog Entry - Record Field Type

## Version: TBD
## Date: January 28, 2026

### Added: Record Field Type

**New Feature**: Implemented a complete Record (Repeater) field type for the custom fields system.

#### What's New

- **Record Field Type**: A powerful repeater field that can contain multiple subfields
- **UI Components**: Clean, collapsible interface for managing record entries
- **Subfield Support**: Supports all existing field types (text, textarea, media, gallery, datetime, url, latlng, term, related-posts)
- **Metadata Management**: Automatic tracking and cleanup of subfield metadata
- **WordPress Integration**: Uses standard WordPress post_meta functions
- **REST API Ready**: Full REST API support when enabled

#### Files Added

- `src/extensions/custom-fields/types/MioRecordMetaControl.jsx` - Main component (updated)
- `src/extensions/custom-fields/RECORD_FIELD_README.md` - Complete documentation
- `src/extensions/custom-fields/RECORD_FIELD_EXAMPLES.php` - Code examples
- `src/extensions/custom-fields/RECORD_FIELD_IMPLEMENTATION.md` - Implementation details
- `src/extensions/custom-fields/RECORD_FIELD_QUICK_REFERENCE.md` - Quick reference guide

#### Files Modified

- `src/extensions/custom-fields/types/MioRecordMetaControl.jsx` - Complete rewrite with full functionality
- `src/extensions/custom-fields/MioCustomFields.module.css` - Added Record field styles
- `src/extensions/custom-fields/MioCustomFields.js` - Updated import for Record control

#### Usage Example

```php
// Register a Record field
$dm = MioDataModel::getInstance();
$dm->registerPostMeta('team_members', [
    'type' => 'array',
    'fieldType' => 'record',
    'label' => 'Team Members',
    'panel' => 'team-panel',
    'postTypes' => ['page'],
    'show_in_rest' => true,
    'single' => true,
    'fields' => [
        ['key' => 'name', 'label' => 'Name', 'fieldType' => 'text'],
        ['key' => 'role', 'label' => 'Role', 'fieldType' => 'text'],
        ['key' => 'photo', 'label' => 'Photo', 'fieldType' => 'media']
    ]
]);

// Display on frontend
$team = mio_get_records(get_the_ID(), 'team_members');
foreach ($team as $member) {
    echo '<h3>' . esc_html($member['name']) . '</h3>';
    echo '<p>' . esc_html($member['role']) . '</p>';
}
```

#### Key Benefits

- **No Plugin Dependencies**: Native implementation, no ACF required
- **Flexible**: Supports all existing custom field types as subfields
- **Clean Data Structure**: Uses WordPress standard metadata tables
- **Developer Friendly**: Well-documented with extensive examples
- **User Friendly**: Intuitive UI with add/remove buttons and collapsible panels

#### Technical Details

**Data Structure**: Record fields store an array of umeta_id reference objects (e.g., `[{name: 123, role: 124}]`), while subfields save their data as individual post meta entries with `single=false` using the naming convention `{fieldKey}_{subfieldKey}` (e.g., `team_members_name`).

**umeta_id Tracking**: The Record field uses umeta_id values to maintain relationships between the record structure and subfield data, enabling queryable subfields without index dependencies.

**Queryable Subfields**: All subfield data can be queried directly using meta_key patterns like `team_members_name` without needing to know the record index or position.

**Performance**: Optimized for typical use cases with recommended maximum of ~50 records per field.

#### Documentation

Full documentation available in:
- `RECORD_FIELD_README.md` - Complete guide with architecture, examples, and troubleshooting
- `RECORD_FIELD_EXAMPLES.php` - Practical PHP code examples
- `RECORD_FIELD_QUICK_REFERENCE.md` - Quick reference for common tasks

#### Breaking Changes

None. This is a new feature addition with no breaking changes to existing functionality.

#### Migration Notes

For users currently using other solutions (like ACF Repeater):
- Record field provides similar functionality with native integration
- Data structure is different - migration scripts may be needed
- See documentation for data structure details

#### Future Enhancements

Potential additions for future versions:
- Drag-and-drop reordering of records
- Nested records support
- Conditional logic for subfields
- Import/export functionality
- Pre-defined record templates
- Maximum records limit option

#### Testing

Recommended testing steps:
1. Register a Record field with various subfield types
2. Create multiple record entries in the WordPress editor
3. Save and reload to verify data persistence
4. Remove records and verify metadata cleanup
5. Test frontend display using provided helper functions
6. Verify REST API access if enabled

#### Support

For questions or issues:
- Review documentation in `RECORD_FIELD_README.md`
- Check examples in `RECORD_FIELD_EXAMPLES.php`
- See troubleshooting section in README
