diff --git a/src/Renderer/TangibleFieldsRenderer.php b/src/Renderer/TangibleFieldsRenderer.php index f34f287..d590f67 100644 --- a/src/Renderer/TangibleFieldsRenderer.php +++ b/src/Renderer/TangibleFieldsRenderer.php @@ -28,11 +28,6 @@ class TangibleFieldsRenderer implements Renderer { */ protected array $field_configs = []; - /** - * Whether assets have been enqueued. - */ - protected bool $enqueued = false; - /** * Type mapping: DataView type => Tangible Fields type. */ @@ -95,9 +90,6 @@ public function render_editor( Layout $layout, array $data ): string { $html .= ''; - // Schedule asset enqueueing. - $this->schedule_enqueue(); - return $html; } @@ -143,12 +135,11 @@ protected function render_section( array $section ): string { $section_id = sanitize_key( $section['label'] ) . '_' . uniqid(); return $fields->render_field( $section_id, [ - 'type' => 'accordion', - 'label' => $section['label'], - 'value' => true, - 'isOpen' => true, // Expanded by default. - 'fields' => $section_fields, - ...$this->get_memory_store_callbacks(), + 'type' => 'accordion', + 'label' => $section['label'], + 'isOpen' => true, // Expanded by default. + 'uncontrolled' => true, + 'fields' => $section_fields, ] ); } @@ -176,11 +167,11 @@ protected function extract_fields_from_item( array $item ): array { // Wrap in an accordion to preserve the section label. $fields[] = [ - 'type' => 'accordion', - 'label' => $item['label'], - 'title' => $item['label'], - 'value' => true, // Expanded by default. - 'fields' => $section_fields, + 'type' => 'accordion', + 'label' => $item['label'], + 'title' => $item['label'], + 'uncontrolled' => true, + 'fields' => $section_fields, ]; } elseif ( $item['type'] === 'tabs' ) { foreach ( $item['tabs'] ?? [] as $tab ) { @@ -234,9 +225,9 @@ protected function render_tabs( array $tabs_structure ): string { $tabs_id = 'tabs_' . uniqid(); return $fields->render_field( $tabs_id, [ - 'type' => 'tab', - 'tabs' => $tabs, - ...$this->get_memory_store_callbacks(), + 'type' => 'tab', + 'tabs' => $tabs, + 'uncontrolled' => true, ] ); } @@ -369,7 +360,6 @@ protected function render_simple_field( array $field, string $type, mixed $value 'value' => $this->format_value_for_field( $value, $type ), 'description' => $field['help'] ?? $config['description'] ?? '', 'placeholder' => $field['placeholder'] ?? $config['placeholder'] ?? '', - ...$this->get_memory_store_callbacks(), ]; // Add type-specific options. @@ -413,7 +403,6 @@ protected function render_repeater_field( array $field, mixed $value, array $con 'value' => $value, 'sub_fields' => $sub_fields, 'layout' => $config['layout'] ?? 'table', - ...$this->get_memory_store_callbacks(), ]; // Optional repeater settings. @@ -645,25 +634,6 @@ protected function get_default_value( string $slug ): mixed { return $config['default'] ?? null; } - /** - * Get memory store callbacks for Tangible Fields. - * - * We use memory store because DataView handles persistence. - * - * @return array Store and permission callbacks. - */ - protected function get_memory_store_callbacks(): array { - $fields = tangible_fields(); - - return [ - ...$fields->_store_callbacks['memory'](), - ...$fields->_permission_callbacks( [ - 'store' => [ 'always_allow' ], - 'fetch' => [ 'always_allow' ], - ] ), - ]; - } - /** * Render a list of entities. * @@ -738,31 +708,13 @@ protected function format_value_for_display( mixed $value, string $type, string } /** - * Enqueue Tangible Fields assets. + * Required by the interface, but enqueue logic will be handled by + * the fields module + * + * @see https://github.com/TangibleInc/fields/blob/main/enqueue.php */ public function enqueue_assets(): void { - if ( $this->enqueued ) { - return; - } - $this->ensure_tangible_fields_loaded(); - - $fields = tangible_fields(); - $fields->enqueue(); - - $this->enqueued = true; - } - - /** - * Schedule asset enqueueing for the footer. - */ - protected function schedule_enqueue(): void { - if ( $this->enqueued ) { - return; - } - - // Enqueue in footer to ensure all fields are registered. - add_action( 'admin_footer', [ $this, 'enqueue_assets' ], 5 ); } /** diff --git a/tests/phpunit/data-view.php b/tests/phpunit/data-view.php index d34fbcc..232b288 100644 --- a/tests/phpunit/data-view.php +++ b/tests/phpunit/data-view.php @@ -1652,7 +1652,7 @@ public function test_renderer_extract_fields_preserves_section_structure(): void $this->assertArrayHasKey( 'title', $result[0] ); // Required by Fields library. $this->assertEquals( 'Contact Info', $result[0]['title'] ); $this->assertEquals( 'Contact Info', $result[0]['label'] ); - $this->assertTrue( $result[0]['value'] ); // Expanded by default. + $this->assertTrue( $result[0]['uncontrolled'] ); $this->assertArrayHasKey( 'fields', $result[0] ); $this->assertCount( 2, $result[0]['fields'] ); }