Skip to content

Field Type Registry: Share custom types across instances#34

Open
nicolas-jaussaud wants to merge 1 commit into
mainfrom
fix/field-registry-shared-types
Open

Field Type Registry: Share custom types across instances#34
nicolas-jaussaud wants to merge 1 commit into
mainfrom
fix/field-registry-shared-types

Conversation

@nicolas-jaussaud
Copy link
Copy Markdown

Hi @zinigor!

I believe there is a small issue with the custom field types registration currently

According to this example from the documentation, FieldTypeRegistry instances should share custom types:

// Create and configure a shared registry
$registry = new \Tangible\DataView\FieldTypeRegistry();
$registry->register_type('phone', [...]);

// Use it for multiple views
$view1 = new DataView(['fields' => ['phone' => 'phone'], ...]);
$view2 = new DataView(['fields' => ['mobile' => 'phone'], ...]);

However, it does not seem to be the case currently as each instance hold its own types (here)

This behavior prevents the use of custom fields, as DataView instantiate its own FieldTypeRegistry instance (here, inside the constructor) which will trigger a fatal error when reaching this part if a field type is not registered

I switched types to a static attribute, as it seems to be the expected behavior and was the easiest way to fix the issue without introducing syntax changes

If you don't want to change FieldTypeRegistry, I can also change this PR to pass a FieldTypeRegistry instance as a second (and optional) parameter of DataView:

$registry = new \Tangible\DataView\FieldTypeRegistry();
$registry->register_type('phone', [...]);

// Shared custom types
$view1 = new DataView(['fields' => ['phone' => 'phone'], ...], $registry);
$view2 = new DataView(['fields' => ['mobile' => 'phone'], ...], $registry);

// Only default types
$view2 = new DataView(['fields' => ['mobile' => 'phone'], ...]);

@nicolas-jaussaud nicolas-jaussaud requested a review from zinigor May 19, 2026 18:00
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant